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
00026 #ifndef DCDT_DEFS_H
00027 #define DCDT_DEFS_H
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <stdarg.h>
00032 #include <pthread.h>
00033 #include <iostream>
00034
00035
00036 #define MAX_PAYLOAD_LEN 5000
00037
00038 #define NANOSLEEP_VERSION
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #define NANOBIAS 10000
00049
00050
00051
00052 #define READCYCLE 10
00053 #define WRITECYCLE 10
00054 #define READWRITECYCLE 10
00055
00056 #define NUMMEMBERFORMAIN 3
00057
00058 #define NUMREADER 10
00059 #define NUMWRITER 10
00060 #define NUMREADERWRITER 10
00061
00062
00063 #define READINIT 11
00064 #define READEND 12
00065 #define READDONEEND 15
00066 #define READLOCKINIT 13
00067 #define READLOCKEND 14
00068
00069 #define WRITEINIT 21
00070 #define WRITEEND 22
00071 #define WRITELOCKINIT 23
00072 #define WRITELOCKEND 24
00073
00074 #define DELETEINIT 31
00075 #define DELETEEND 32
00076 #define DELETELOCKINIT 33
00077 #define DELETELOCKEND 34
00078
00079 #define BRIDGEINIT 41
00080 #define BRIDGEEND 42
00081 #define BRIDGELOCKINIT 43
00082 #define BRIDGELOCKEND 44
00083
00084 #define WAITINIT 51
00085 #define WAITEND 52
00086
00087
00088 #define SUCCESS 0
00089 #define FAILURE -1
00090
00091
00092 #define DCDT_ZERO 0
00093 #define DCDT_INIT 1
00094 #define DCDT_LETSWORK 2
00095 #define DCDT_SHUTDOWN 3
00096 #define DCDT_TERMINATING 4
00097 #define DCDT_DOWN 5
00098
00099
00100 #define EMPTYSLOT 0
00101 #define CREATED 1
00102 #define ACTIVE 2
00103 #define INITIALIZING 3
00104 #define READY 4
00105 #define RUNNING 5
00106 #define SUSPENDED 6
00107 #define DEACTIVATED 7
00108 #define TERMINATING 8
00109
00110
00111 #define UCHAR unsigned char
00112 #define UINT unsigned int
00113 #define LLONG long long
00114 #define DCDT_TIME unsigned int
00115
00116
00117 #define INNER_STARTNAME "/tmp/dcdt_startsock"
00118 #define INNER_NAME "/tmp/dcdt_sock"
00119 #ifndef UNIX_PATH_MAX
00120 #define UNIX_PATH_MAX 108
00121 #endif
00122
00123
00124
00125 #define L_WAITING 1
00126 #define L_CONNECTING 2
00127 #define L_RESETTOCONN 3
00128 #define L_WORKING 4
00129 #define L_LOST 5
00130 #define L_RESTARTING 6
00131 #define L_STOPPING 7
00132
00133
00134 #define LINK_RESTART_NUM 3
00135 #define LINK_LOST_NUM 5
00136 #define LINK_LOST_TIMER 2000000
00137
00138
00139 #define FINDER_PERIOD 500000
00140 #define NOTIFY_PERIOD 5000000
00141
00142 #define MAXLINKS 500
00143 #define MAXCHANNELS 10
00144
00145
00146 #define ProfileType unsigned int
00147
00148 #define MPM_SYSTEM 1
00149 #define MPM_USER 2
00150 #define MPM_LINK 4
00151 #define MPM_BRIDGE 8
00152 #define MPM_STATIC 16
00153
00154
00155
00156
00157
00158 #define TIMEOUT_MSG 10
00159
00160
00161 class DCDT_Channel;
00162
00164 class CommData {
00165 public:
00166 virtual DCDT_Channel* CreateChannel(int AgoraID) = 0;
00167 };
00168
00169
00170 #define SIZEOF_INTEGER 32
00171
00172
00173
00174
00175
00176 #define NUMINT_MSGTYPE 4
00177 #define MAX_MSG_TYPE (NUMINT_MSGTYPE*SIZEOF_INTEGER)
00178
00179
00180
00181
00182
00183 #define NUMINT_MEMBERS 6
00184 #define MAX_MEMBERS (NUMINT_MEMBERS*SIZEOF_INTEGER)
00185
00186 class DCDT_Condition{
00187 public:
00188 DCDT_Condition() {
00189 pthread_cond_init( &myCond, NULL);
00190 pthread_mutex_init ( &myMutexCond, NULL );
00191 };
00192 ~DCDT_Condition() {
00193 pthread_cond_destroy( &myCond);
00194 };
00195
00196 inline void wait() {
00197 pthread_cond_wait(&myCond, &myMutexCond);
00198
00199 };
00200 inline void signal(){
00201 pthread_cond_signal( &myCond);
00202 };
00203 inline void lock() {
00204 pthread_mutex_lock( &myMutexCond);
00205
00206 };
00207 inline void unlock(){
00208 pthread_mutex_unlock( &myMutexCond);
00209 };
00210
00211 private:
00212 pthread_cond_t myCond;
00213 pthread_mutex_t myMutexCond;
00214 };
00215
00216 class DCDT_Mutex {
00217 public:
00218 DCDT_Mutex() {
00219 pthread_mutex_init( &myMutex, NULL);
00220 };
00221 ~DCDT_Mutex() {
00222 pthread_mutex_destroy( &myMutex);
00223 };
00224
00225 inline void lock() {
00226 pthread_mutex_lock( &myMutex);
00227
00228 };
00229 inline void unlock(){
00230 pthread_mutex_unlock( &myMutex);
00231 };
00232
00233 private:
00234 pthread_mutex_t myMutex;
00235
00236 };
00237
00238
00239 #define UNIT_MAX 100
00240 #define DCDT_TRC_AGORA 1
00241 #define DCDT_TRC_POSTOFFICE 2
00242 #define DCDT_TRC_INNERLINK 3
00243 #define DCDT_TRC_MEMBER 4
00244 #define DCDT_TRC_COMM 5
00245
00246
00248 class Exception {};
00249
00250 class ChannelError : public Exception {
00251 public:
00252 int errval;
00253 ChannelError() { errval = 0; };
00254 ChannelError(int err) { errval = err; };
00255 };
00256
00257 class ConnError : public ChannelError {
00258 public:
00259 ConnError() : ChannelError() {};
00260 ConnError(int err) : ChannelError(err) {};
00261 };
00262
00263 class TimeOut : public Exception {};
00264
00265 typedef enum { DCDT_LOCAL_MSG=1, DCDT_REMOTE_MSG=2, DCDT_ALL_MSG=3 } DCDT_RequestType;
00266
00267 #endif //define