Changeset fb8e97


Ignore:
Timestamp:
01/09/12 17:40:44 (18 months ago)
Author:
Micke Prag <micke.prag@…>
Branches:
('master', '668dd99ac278cfd419d67879b141678facea630a')('windows_service_fixes', 'df6bd2788365991d36d5af2a75833b8de2a5860f')
Children:
df6bd2788365991d36d5af2a75833b8de2a5860f
Parents:
542d17a45de15d891024fbb5af13ececef77d3ec
git-author:
Micke Prag <micke.prag@telldus.se>2012-01-09 17:40:44+01:00
git-committer:
Micke Prag <micke.prag@telldus.se>2012-01-09 17:40:44+01:00
Message:

Implement class Timer in Windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • telldus-core/service/Timer.cpp

    r988b44 rfb8e97  
    11#include "Timer.h" 
    22#include "Mutex.h" 
    3 #include "Log.h" 
    43#ifdef _WINDOWS 
    54#else 
     
    1514        bool running; 
    1615#ifdef _WINDOWS 
     16        HANDLE cond; 
     17        TelldusCore::Mutex mutex; 
    1718#else 
    1819        pthread_mutex_t waitMutex; 
     
    2627        d->event = event; 
    2728#ifdef _WINDOWS 
     29        d->cond = CreateEventW(NULL, false, false, NULL); 
    2830#else 
    2931        pthread_cond_init(&d->cond, NULL); 
     
    5052void Timer::stop() { 
    5153#ifdef _WINDOWS 
     54        TelldusCore::MutexLocker(&d->mutex); 
     55        d->running = false; 
     56        SetEvent(d->cond); 
    5257#else 
    5358        //Signal event 
     
    6368void Timer::run() { 
    6469#ifdef _WINDOWS 
    65                 sleep(2); //TODO: Implement me 
     70        int interval = 0; 
     71        { 
     72                TelldusCore::MutexLocker(&d->mutex); 
     73                d->running = true; 
     74                interval = d->interval*1000; 
     75        } 
     76        while(1) { 
     77                DWORD retval = WaitForSingleObject(d->cond, interval); 
     78                if (retval == WAIT_TIMEOUT) { 
     79                        d->event->signal(); 
     80                } 
     81                TelldusCore::MutexLocker(&d->mutex); 
     82                if (!d->running) { 
     83                        break; 
     84                } 
     85        } 
    6686#else 
    6787        struct timespec ts; 
Note: See TracChangeset for help on using the changeset viewer.