Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

DCDT_Finder.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 dEVICE cOMMUNITIES dEVELOPMENT tOOLKIT 
00003 
00004 DCDT_Finder.h
00005 
00006 COPYRIGHT (C) 2002   Alessandro Mazzini (mazzini@airlab.elet.polimi.it)
00007 
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2 of the License, or (at your option) any later version.
00013 
00014 This library 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 GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
00022 
00023 ****************************************************************************/
00024 
00025 #ifndef FINDER_H
00026 #define FINDER_H
00027 
00028 #include <DCDT_Member.h>
00029 #include <DCDT_Channel_IP.h>
00030 #include <DCDT_Channel_Serial.h>
00031 #include <DCDT_LinkRx.h>
00032 
00033 #define STARTING_TIMER_VAL 7000000
00034 
00035 typedef struct _DCDT_LinkTableElem {
00036   DCDT_LinkRx *LinkPtr;
00037   int status;
00038   int remoteID;
00039   bool freeSlot;
00040   DCDT_Mutex mtx;
00041 } DCDT_LinkTableElem;
00042 
00043 typedef struct _ChannelTableElem {
00044   bool active;
00045   bool dynamic;
00046   DCDT_Channel *channel;
00047 } ChannelTableElem;
00048 
00053 class DCDT_Finder : public DCDT_Member {
00054  public:
00055   DCDT_Finder(DCDT_Agora* agora, FinderData *fd);
00056   ~DCDT_Finder();
00057   
00058   void Init();
00059 
00060   CommData* CreateLink(int r_id, int status, CommData *l_cd, CommData *r_cd, unsigned int profile);
00061   inline void SetLinkStatus(int LinkID, int LinkStatus);
00062   inline void SetLinkRemoteAgoraID(int LinkID, int id);
00063 
00064   int IsPresent(int id);
00065   inline int GetFirstFreeLinkTableSlot();
00066   inline void DeleteLinkTableSlot(int LinkID);
00067 
00068   int ActivateLink(DCDT_LinkRx *);
00069   void CloseLink(int id);
00070   void DoYourJob(int par = 0);
00071 
00072  protected:
00073 
00074  private:
00075   void StaticLinks();
00076 
00077   FinderData *finder_data;
00078   DCDT_LinkTableElem LinkTable[MAXLINKS];
00079 
00080   DCDT_TIME 
00081     // When the previous finder cycle was ended
00082     old_ts, 
00083     passed;
00084   DCDT_TIME
00086     start_ts,
00088     new_ts,
00090     notify_ts;
00091 
00092   bool starting_timer;
00093   bool linked,
00095     received;
00096   short port;
00097   int remote_AgoraID;
00098   char from[INET_ADDRSTRLEN];
00099 
00101   CommData
00103     *localCD,
00105     *remoteCD;
00106 
00108   HSMsgHeader *hs_header;
00109   int linknum, i;
00110   ChannelTableElem dynamic_channels[MAXCHANNELS];
00111 
00112 };
00113 
00114 inline void DCDT_Finder::SetLinkStatus(int LinkID, int LinkStatus)
00115 {
00116   LinkTable[LinkID].status = LinkStatus;
00117 };
00118 
00119 inline void DCDT_Finder::SetLinkRemoteAgoraID(int LinkID, int id)
00120 {
00121   LinkTable[LinkID].remoteID = id;
00122 };
00123 
00124 inline int DCDT_Finder::GetFirstFreeLinkTableSlot()
00125 {
00126   for( int i = 1; i < MAXLINKS; i++) {
00127     LinkTable[i].mtx.lock();
00128     if ( LinkTable[i].freeSlot) {
00129       LinkTable[i].freeSlot = false;
00130       LinkTable[i].mtx.unlock();
00131       return i;
00132       }
00133     LinkTable[i].mtx.unlock();
00134     }
00135   return 0;
00136 };
00137 
00138 inline void DCDT_Finder::DeleteLinkTableSlot(int LinkID)
00139 {
00140   LinkTable[LinkID].mtx.lock();
00141 
00142   LinkTable[LinkID].freeSlot = true;
00143 
00144   LinkTable[LinkID].mtx.unlock();
00145 
00146 };
00147 
00148 #endif //define

Generated on Sun Jun 19 10:35:50 2005 for dcdt by  doxygen 1.3.9.1