Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkInteractionDebug.h"
00019 #include "mitkSocketClient.h"
00020 #include <string.h>
00021
00022 namespace mitk {
00023
00024 const int InteractionDebug::OPEN_CONNECTION = 1;
00025 const int InteractionDebug::NEW_STATE_MACHINE = 2;
00026 const int InteractionDebug::EVENT = 3;
00027 const int InteractionDebug::TRANSITION = 4;
00028 const int InteractionDebug::ACTION = 5;
00029 const int InteractionDebug::DELETE_STATE_MACHINE = 6;
00030
00031 InteractionDebug* InteractionDebug::m_Instance = NULL;;
00032 char* InteractionDebug::m_FileName = NULL;
00033
00037 InteractionDebug::InteractionDebug()
00038 {
00039 SocketClient::GetInstance()->open( "127.0.0.1", 34768 );
00040 }
00041
00042
00046 unsigned int InteractionDebug::GetHashValue()
00047 {
00048 return 0;
00049 }
00050
00054 void InteractionDebug::OpenConection()
00055 {
00056 char* wb = m_Buffer;
00057 *((unsigned long*) wb) = (unsigned long) GetHashValue();
00058 wb += sizeof(long);
00059
00060 size_t size = strlen( m_FileName );
00061
00062 *((unsigned long*) wb) = (unsigned long) size;
00063 wb += sizeof(long);
00064
00065 strcpy( wb, m_FileName );
00066 size += 2*sizeof(long);
00067
00068 sendCounter();
00069
00070 SocketClient::GetInstance()->send( OPEN_CONNECTION, (unsigned int) size, m_Buffer );
00071 }
00072
00076 bool InteractionDebug::NewStateMachine( const char* name, const StateMachine* stateMachine )
00077 {
00078 if ( name == NULL )
00079 return false;
00080
00081
00082 char* wb = m_Buffer;
00083 *((unsigned long*) wb) = (unsigned long) stateMachine;
00084 wb += sizeof(long);
00085
00086
00087 size_t size = strlen(name);
00088
00089 *((unsigned long*) wb) = (unsigned long) size;
00090 wb += sizeof(long);
00091
00092
00093 strcpy(wb,name);
00094
00095 size += 2*sizeof(long);
00096
00097 sendCounter();
00098
00099 return SocketClient::GetInstance()->send( NEW_STATE_MACHINE, (unsigned int) size, m_Buffer );
00100 }
00101
00105 bool InteractionDebug::Event( const StateMachine* stateMachine, unsigned int EventId )
00106 {
00107 if ( EventId != 520)
00108 {
00109 if ( stateMachine == NULL || stateMachine->GetType().empty() )
00110 return false;
00111
00112
00113 char* wb = m_Buffer;
00114 *((unsigned long*) wb) = (unsigned long) stateMachine;
00115 wb += sizeof(long);
00116
00117
00118 *((unsigned long*) wb) = EventId;
00119
00120 sendCounter();
00121
00122 return SocketClient::GetInstance()->send( EVENT, 2*sizeof(long), m_Buffer );
00123 }
00124 return true;
00125 }
00126
00130 bool InteractionDebug::Transition( const StateMachine* stateMachine, const char* transitionName )
00131 {
00132 if ( stateMachine == NULL || stateMachine->GetType().empty() )
00133 return false;
00134
00135
00136 char* wb = m_Buffer;
00137 *((unsigned long*) wb) = (unsigned long) stateMachine;
00138 wb += sizeof(long);
00139
00140
00141 unsigned long size = static_cast<unsigned long>(strlen( transitionName ));
00142 *((unsigned long*) wb) = size;
00143
00144 wb += sizeof(long);
00145
00146 for ( unsigned long i=0; i<size; i++, wb++ )
00147 *wb = transitionName[i];
00148
00149 size += 2*sizeof(long);
00150
00151
00152
00153 return SocketClient::GetInstance()->send( TRANSITION, size, m_Buffer );
00154 }
00155
00159 bool InteractionDebug::Action( const StateMachine* stateMachine, const char* transitionName, unsigned int action )
00160 {
00161 if ( stateMachine == NULL || stateMachine->GetType().empty() )
00162 return false;
00163
00164
00165 char* wb = m_Buffer;
00166 *((unsigned long*) wb) = (unsigned long) stateMachine;
00167 wb += sizeof(long);
00168
00169
00170 unsigned long size = static_cast<unsigned long>(strlen( transitionName ));
00171 *((unsigned long*) wb) = size;
00172
00173 wb += sizeof(long);
00174
00175 for ( unsigned long i=0; i<size; i++, wb++ )
00176 *wb = transitionName[i];
00177
00178 wb += sizeof(long);
00179
00180 *((unsigned long*) wb) = action;
00181
00182 size += 3*sizeof(long);
00183
00184 sendCounter();
00185
00186 return SocketClient::GetInstance()->send( ACTION, size, m_Buffer );
00187 }
00188
00192 bool InteractionDebug::DeleteStateMachine( const StateMachine* stateMachine )
00193 {
00194 if ( stateMachine == NULL || stateMachine->GetType().empty() )
00195 return false;
00196
00197
00198 char* wb = m_Buffer;
00199 *((unsigned long*) wb) = (unsigned long) stateMachine;
00200
00201 sendCounter();
00202
00203 return SocketClient::GetInstance()->send( DELETE_STATE_MACHINE, sizeof(long), m_Buffer );
00204 }
00205
00209 InteractionDebug* InteractionDebug::GetInstance()
00210 {
00211 if (m_Instance==NULL)
00212 m_Instance = new InteractionDebug();
00213
00214 return m_Instance;
00215 }
00216
00220 void InteractionDebug::SetXMLFileName( const char* fileName )
00221 {
00222 size_t size = strlen(fileName) + 1;
00223 m_FileName = new char[size];
00224 strcpy(m_FileName,fileName);
00225 }
00226
00227 void InteractionDebug::sendCounter()
00228 {
00229 static unsigned long m_Counter = 0;
00230 static char my_Buffer[sizeof(long)];
00231 m_Counter++;
00232
00233 char* wb = my_Buffer;
00234 *((unsigned long*) wb) = (unsigned long) m_Counter;
00235
00236 bool success = SocketClient::GetInstance()->send( 7, sizeof(long), wb );
00237 if (success)
00238 {
00239 MITK_INFO << "Counter: " << m_Counter << std::endl;
00240 }
00241 }
00242
00243 void InteractionDebug::setMaxConnectionAdvance(int maxConnectionAdvance)
00244 {
00245 SocketClient::GetInstance()->setMaxConnectionAdvance(maxConnectionAdvance);
00246 }
00247
00248 }