00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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