Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

XFuRemoteDebug.cpp

Go to the documentation of this file.
00001 /*
00002  * \file
00003  * X-Forge Engine <br>
00004  * Copyright 2000-2003 Fathammer Ltd
00005  *
00006  * \brief
00007  *
00008  * $Id: XFuRemoteDebug.cpp,v 1.10 2003/05/27 13:25:47 peppe Exp $
00009  * $Date: 2003/05/27 13:25:47 $
00010  * $Revision: 1.10 $
00011  */
00012 
00013 
00014 #include <xfcore/XFcCore.h>
00015 #include <xfutil/XFuStringKey.h>
00016 #include <xfcore/XFcHashtable.h>
00017 #include <xfutil/XFuRemoteDebugService.h>
00018 #include <xfcore/net/XFcRemoteCommunication.h>
00019 #include <xfutil/XFuRemoteDebug.h>
00020 
00021 
00022 static const char * message = "*******************************************\r\n\
00023 * Welcome to X-Forge remote debug server. *\r\n\
00024 *           I'm ready to serve.           *\r\n\
00025 *******************************************\r\n\r\n\r\n";
00026 
00027 XFuRemoteDebug::XFuRemoteDebug() : mPosition(0), mRemoteComm(NULL)
00028 {
00029 }
00030 
00031 XFuRemoteDebug::~XFuRemoteDebug()
00032 {
00033     delete mRemoteComm;
00034 }
00035 
00036 XFuRemoteDebug * XFuRemoteDebug::create(INT32 aPort)
00037 {
00038     XFuRemoteDebug * r = new XFuRemoteDebug;
00039     if (r && r->init(aPort))
00040         return r;
00041     delete r;
00042     return NULL;
00043 }
00044 
00045 INT XFuRemoteDebug::init(INT32 aPort)
00046 {
00047     mRemoteComm = XFcRemoteCommunication::create(0, aPort, this);
00048     return (mRemoteComm) ? 1 : 0; 
00049 }
00050 
00051 INT32 XFuRemoteDebug::send(const CHAR8 *aData)
00052 {
00053     return mRemoteComm->send(aData, XFcStringToolkit::getLengthInBytes(aData));
00054 }
00055 
00056 INT32 XFuRemoteDebug::send(const CHAR8 *aData, INT32 aSize)
00057 {
00058     return mRemoteComm->send(aData, aSize);
00059 }
00060 
00061 INT XFuRemoteDebug::registerService(const CHAR *aName, XFuRemoteDebugService &aService)
00062 {
00063     XFuStringKey key(aName);
00064     XFuRemoteDebugService * s = mService.put(key, &aService);
00065     return (s) ? 1 : 0;
00066 } 
00067 
00068 XFuRemoteDebugService * XFuRemoteDebug::uregisterService(const CHAR *aName)
00069 {
00070     XFuStringKey key(aName);
00071     return mService.get(key);
00072 }
00073 
00074 void XFuRemoteDebug::event(INT32 aError)
00075 {
00076     switch(aError)
00077     {
00078     case 0:
00079         send(message, strlen(message));
00080         break;
00081     case -1:
00082         break;
00083     default:
00084         break;
00085     }
00086 }
00087 
00088 void XFuRemoteDebug::receive(const CHAR8 * aData, INT32 aSize, INT32 aError)
00089 {
00090     if (aError)
00091         return;
00092     
00093     INT32 i = 0;
00094     for (i = 0; i < aSize; ++i)
00095     {
00096         if (mPosition + i >= RECV_BUFFER_MAX)
00097         {
00098             mPosition = 0;
00099             return;
00100         }
00101         mRecvBuffer[mPosition + i] = aData[i];
00102         
00103     }
00104     mPosition += i;
00105 
00106     CHAR8 name[RECEIVER_NAME_MAX];
00107     if (mRecvBuffer[mPosition - 2] == RECEIVE_REPASS_BUFFER_CHAR)
00108     {
00109         INT32 n = 0;
00110 
00111         while (mRecvBuffer[n] != ' ' && n < RECEIVER_NAME_MAX - 1  && n < mPosition - 1) 
00112         {
00113             name[n] = mRecvBuffer[n++];
00114         }
00115         name[n] = '\0';
00116 
00117         XFuStringKey key(name);
00118 
00119         XFuRemoteDebugService * s  = mService.get(key);
00120         if (s)
00121         {
00122             s->remoteDebugReceive(mRecvBuffer, mPosition, 0);
00123             mRecvBuffer[mPosition] = '\0';
00124             s->remoteDebugReceive(mRecvBuffer + n + 1, 0);
00125         }
00126 
00127         mPosition = 0;    
00128     }
00129 }
00130 
00131 

   
X-Forge Documentation
Confidential
Copyright © 2002-2003 Fathammer
   
Documentation generated
with doxygen
by Dimitri van Heesch