callbackmanager.hh

Go to the documentation of this file.
00001 
00009 #ifndef __CALLBACK_MANAGER__ 
00010 #define __CALLBACK_MANAGER__
00011 
00012 #include <global-types.h>
00013 #include <os.h>
00014 
00015 #include <callback.hh>
00016 #include <callbacktimer.hh>
00017 #include <device-corba.hh>
00018 #include <map>
00019 #include <deque>
00020 
00021 #include <platform.h>
00022 
00023 using namespace std;
00024 
00025 namespace DeviceAccess {
00026 
00028   class E_API CallbackManager {
00029     private:
00030       // for singleton
00031       static CallbackManager* _instance;
00032       CallbackManager() : _devices(),
00033                           _conPerDev(),
00034                           _callbacks(),
00035                           _counter(),
00036                           _timerActivated(false), 
00037                           _connectionsMu(), 
00038                           _tbrMu(), 
00039                           _cbt(), 
00040                           _toBeRemoved(){
00041       }
00042       CallbackManager(const CallbackManager&){}
00043       ~CallbackManager(); 
00044       // Time to wait for new life sign for the connection until error() is called
00045       static const SLong _LIFESIGN_TIMEOUT = 10;
00046 
00047       // Copy of obeserved devices with nomenclature string
00048       map<string, Device*> _devices;
00049       // Actual number of connections for nomenclature string
00050       map<string, int> _conPerDev;
00051       // Observed callbacks with asynchID+nomenclature string
00052       map<string, Callback*> _callbacks;
00053       // Individual timer for each connection with asynchID+nomenclature string
00054       map<string, SLong> _counter;
00055       // TimerActivated
00056       bool _timerActivated;
00057       
00058       // Mutex for the connections list
00059       omni_mutex _connectionsMu; 
00060       // Mutex for deleting elements
00061       omni_mutex _tbrMu;
00062       // Pointer to timer instance (is omnithread, so it deletes itself)
00063       CallbackTimer* _cbt;
00064       // List of connections which should be removed
00065       deque<string> _toBeRemoved;
00066       // Removes the connections listed in _toBeRemoved
00067       void removeConnections();
00068       // extracts nomenclature from asynchid and nomenclature
00069       string getNomen(const string& key);
00070       // removes entry from list with nomenclature keys
00071       void removeDeviceRelated(const string& nomen);
00072     public:
00074       static CallbackManager* getInstance();
00076       static void destroy();
00078 
00082       void decrementLifeSignCounter();
00083       
00085 
00089       void resetLifeSignCounter(const AsynchId& id);
00090       
00092 
00097       void addConnection(Callback* callback, const AsynchId& id, Device& device);
00098       
00100 
00104       void connectionToBeRemoved(const AsynchId& id);
00105 
00107 
00110       void removeConnectionsOfCb(Callback* cb);
00111 
00112   };
00113 }
00114 
00115 #endif
00116 

Generated on 7 Feb 2013 for Client Device Access API by  doxygen 1.4.7