nidas v1.2.3
Looper.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2006, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27
28#ifndef NIDAS_CORE_LOOPER_H
29#define NIDAS_CORE_LOOPER_H
30
31#include "LooperClient.h"
32
33#include <nidas/util/Thread.h>
37
38#include <sys/time.h>
39#include <sys/select.h>
40#include <assert.h>
41
42#include <list>
43
44namespace nidas { namespace core {
45
52public:
53
54 Looper();
55
67 void addClient(LooperClient *clnt, unsigned int msecPeriod,
68 unsigned int msecOffset);
69
73 void removeClient(LooperClient *clnt);
74
80 virtual int run();
81
85 static int gcd(unsigned int a, unsigned int b);
86
87private:
88
89 void setupClientMaps();
90
92
93 std::list<LooperClient*> _clients;
94
95 std::map<LooperClient*, unsigned int> _clientPeriods;
96 std::map<LooperClient*, unsigned int> _clientOffsets;
97
98 std::map<LooperClient*, unsigned int> _clientDivs;
99 std::map<LooperClient*, unsigned int> _clientMods;
100
101 unsigned int _sleepMsec;
102
103};
104
105}} // namespace nidas namespace core
106
107#endif
Interface of a client of Looper.
Definition LooperClient.h:38
Looper is a Thread that periodically loops, calling the LooperClient::looperNotify() method of Looper...
Definition Looper.h:51
void removeClient(LooperClient *clnt)
Remove a client from the Looper.
Definition Looper.cc:64
std::map< LooperClient *, unsigned int > _clientDivs
Definition Looper.h:98
virtual int run()
Thread function.
Definition Looper.cc:155
std::map< LooperClient *, unsigned int > _clientPeriods
Definition Looper.h:95
std::list< LooperClient * > _clients
Definition Looper.h:93
void setupClientMaps()
Definition Looper.cc:96
void addClient(LooperClient *clnt, unsigned int msecPeriod, unsigned int msecOffset)
Add a client to the Looper whose LooperClient::looperNotify() method should be called every msec numb...
Definition Looper.cc:45
nidas::util::Mutex _clientMutex
Definition Looper.h:91
Looper()
Definition Looper.cc:36
static int gcd(unsigned int a, unsigned int b)
Utility function for finding greatest common divisor.
Definition Looper.cc:90
std::map< LooperClient *, unsigned int > _clientOffsets
Definition Looper.h:96
std::map< LooperClient *, unsigned int > _clientMods
Definition Looper.h:99
unsigned int _sleepMsec
Definition Looper.h:101
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
Definition Thread.h:83
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31