RemoteDevice.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00033 
00037 
00038 #ifndef __REMOTE_DEVICE_H_
00039 #define __REMOTE_DEVICE_H_
00040 
00041 #include <socketUDP.h>
00042 #include <CommonOptions.h>
00043 
00044 #include <resources.h>
00045 #include <CommModule.h>
00046 
00047 #include <SsUtils.h>
00048 
00049 namespace MipResources{
00051 /* @{ */
00052 
00053 
00055 extern "C" void RDWork(void* p);
00056 
00058 extern "C" void RDClean(void* p);
00059 
00060 
00064 class RemoteDeviceOptions : public Options {
00065  public:
00066   IntOption*  recipientPort;
00067   IntOption*  baseRecipientPort;
00068   StringOption* recipientAddr;
00069   IntOption*  listenerPort;
00070   IntOption*  baseListenerPort;
00071 
00072   RemoteDeviceOptions();
00073 
00074   string getObjectName() const {
00075    return "RemoteDeviceOptions";
00076   }
00077 };
00078 
00083  class RemoteDevice : public Resource{
00084  private:
00085   static const ResourcePlate _plate = REM_DEV_RES;
00086   
00087   RemoteDeviceOptions _remDevOptions;
00088 
00089   int _myId;
00090   
00091   Timer _timer;
00092   
00093    Thread _RDThread;
00094   
00095   SenderUDP*  _sender;
00096   ListenerUDP* _listener;
00097   
00098   int   _recipientPort;
00099   string _recipientAddr;
00100   
00101   int   _listenerPort;
00102   
00103   pthread_mutex_t _receiveMutex;
00104   
00105   string _lastMessage;
00106   bool   _messageToRead;
00107   int   _lostMessages;
00108 
00109  public:
00110   
00112   RemoteDevice(int argc, const char* argv[]);
00113   
00115   ~RemoteDevice();
00116 
00118   ResourcePlate getPlate() const {
00119    return _plate;
00120   }
00121   
00124   void send(string &message);
00125   
00129   bool getLastMessage(string &message);
00130   
00133   int getLostMessages();
00134   
00136   void resetLostMessages();
00137   
00140   void RDReceive(){
00141    while(_listener->lSelect() == 1){
00142     pthread_mutex_lock(&_receiveMutex);
00143     _listener->receive(_lastMessage,_recipientAddr);
00144     if(_messageToRead == true){
00145      _lostMessages++;
00146     }
00147 //     cout << " _lastMessage size (" << _lastMessage.size() <<")" << _timer.print() << endl;
00148     _messageToRead = true;
00149     pthread_mutex_unlock(&_receiveMutex);
00150    }
00151    _timer.reset();
00152   }
00153 };
00154 
00155 /* @} */
00156  
00157 };// end namespace MipResources{
00158 
00159 #endif
00160 
00161 
00162 
00163 
00164 
00165 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6