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

DCDT_Defs.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 dEVICE cOMMUNITIES dEVELOPMENT tOOLKIT 
00003 
00004 DCDT_Defs.h
00005 
00006 COPYRIGHT (C) 2002  Paolo Meriggi (meriggi@ing.unibs.it)
00007                     Alessandro Mazzini (mazzini@airlab.elet.polimi.it)
00008 
00009 
00010 This library is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU Lesser General Public
00012 License as published by the Free Software Foundation; either
00013 version 2 of the License, or (at your option) any later version.
00014 
00015 This library is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public
00021 License along with this library; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
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 //#define SEQUENCER_VERSION
00040 
00041 // definition required only in nanosleep version
00042 // to correct the timing bias introduced by the
00043 // nanosleep() call
00044 
00045 //in case HZ=1280
00046 //#define NANOBIAS 781
00047 //in case HZ=100
00048 #define NANOBIAS 10000
00049 
00050 //Variables and costants used during the test's part
00051 
00052 #define READCYCLE        10
00053 #define WRITECYCLE       10 
00054 #define READWRITECYCLE   10
00055 
00056 #define NUMMEMBERFORMAIN 3
00057 // Note that  NUMMEMBERFORMAIN = NUMREADER + NUMWRITER + NUMREADERWRITER 
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 // General definitions
00088 #define SUCCESS    0
00089 #define FAILURE   -1
00090 
00091 // RunLevel definitions
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 // Member states
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 // InnerLink first agora socket name
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 // link status types
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 // timer di attesa del link sul canale
00134 #define LINK_RESTART_NUM      3
00135 #define LINK_LOST_NUM         5
00136 #define LINK_LOST_TIMER       2000000
00137 
00138 // usec di intervallo tra un notify e l'altro
00139 #define FINDER_PERIOD   500000
00140 #define NOTIFY_PERIOD   5000000
00141 
00142 #define MAXLINKS 500
00143 #define MAXCHANNELS 10
00144 
00145 // Member Profile Masks
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 // dichiarazioni per i messaggi
00156 
00157 // number of seconds to wait before removing unread msgs from list
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 // Defines for the message types:
00173 // remember that the max number of messages types must be:
00174 // MAX_MSG_TYPE = 32 * NUMINT_MSGTYPE
00175 // We use a bit for every message type ( ex. for subscription mask )
00176 #define NUMINT_MSGTYPE  4
00177 #define MAX_MSG_TYPE    (NUMINT_MSGTYPE*SIZEOF_INTEGER)
00178 
00179 // Defines for the Agorà members:
00180 // remember that the max number of members must be:
00181 // MAX_MEMBERS = 32 * NUMINT_MEMBERS
00182 // We use a bit for every member ( ex. for readers mask )
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 // CTrace definitions
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 // Exceptions
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

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