Changeset 3:459106f9bf9a in xplra
- Timestamp:
- 01/03/13 15:45:33 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 8 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/xplra/ListenThread.cc
r2 r3 55 55 while(!quitEvent.check() && !quitEvent.failed() && !acceptor.failed()) { 56 56 if (acceptor.accept()) { 57 ServerThread* serverThread = new ServerThread(acceptor); 57 ServerThread* serverThread = new ServerThread(requestQueue, 58 acceptor); 58 59 serverThread->start(); 59 60 } -
src/xplra/Makefile.am
r2 r3 24 24 25 25 libxplra_la_SOURCES= \ 26 plugin.cc \ 27 ListenThread.cc \ 28 RequestQueue.cc \ 29 ServerThread.cc 26 plugin.cc \ 27 ListenThread.cc \ 28 RequestQueue.cc \ 29 ServerThread.cc \ 30 TaskRequest.cc \ 31 DataRefTask.cc \ 32 GetDataRefTask.cc 30 33 31 34 libxplra_la_LIBADD=$(LIBXPLCOMMON_LIBS) … … 35 38 Request.h \ 36 39 RequestQueue.h \ 37 ServerThread.h 40 ServerThread.h \ 41 Task.h \ 42 TaskRequest.h \ 43 DataRefTask.h \ 44 GetDataRefTask.h -
src/xplra/ServerThread.cc
r2 r3 31 31 #include "ServerThread.h" 32 32 33 #include "RequestQueue.h" 34 #include "GetDataRefTask.h" 35 #include "TaskRequest.h" 36 37 #include <xplcommon/Util.h> 38 39 #include <cstdio> 40 33 41 //------------------------------------------------------------------------------ 34 42 … … 37 45 using xplcommon::LocalAcceptor; 38 46 using xplcommon::Mutex; 47 using xplcommon::Util; 48 49 using std::string; 39 50 40 51 //------------------------------------------------------------------------------ … … 57 68 //------------------------------------------------------------------------------ 58 69 59 ServerThread::ServerThread( LocalAcceptor& acceptor) :70 ServerThread::ServerThread(RequestQueue& requestQueue, LocalAcceptor& acceptor) : 60 71 Thread(true), 72 requestQueue(requestQueue), 61 73 bufferedStream(acceptor.getSocket(&waiter)), 62 74 stream(*bufferedStream) … … 89 101 void ServerThread::run() 90 102 { 91 stream.write("Hello, world!", 13); 92 stream.flush(); 103 Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run\n", this); 104 while(stream) { 105 uint8_t command = stream.readU8(); 106 if (!stream) continue; 107 108 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: command=0x%02x\n", 109 // this, command); 110 111 if (command==CMD_GET_SINGLE) { 112 string name = stream.readString(); 113 uint8_t type = stream.readU8(); 114 if (!stream) continue; 115 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: name='%s', type=0x%02x\n", 116 // this, name.c_str(), type); 117 if (type==TYPE_BYTE_ARRAY) { 118 int length = stream.readS32(); 119 if (!stream) continue; 120 121 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: length=%lu\n", 122 // this, static_cast<unsigned long>(length)); 123 124 GetByteArrayDataRefTask* task = 125 new GetByteArrayDataRefTask(name, length); 126 TaskRequest request(task); 127 128 if (requestQueue.execute(&request)) { 129 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: request executed\n"); 130 stream.writeU8(RESULT_OK); 131 int length = task->getLength(); 132 stream.writeS32(length); 133 if (length>0) { 134 stream.write(task->getData(), length); 135 } 136 } else { 137 break; 138 } 139 } else { 140 stream.writeU8(RESULT_OTHER_ERROR); 141 } 142 } else { 143 stream.writeU8(RESULT_INVALID_COMMAND); 144 } 145 stream.flush(); 146 } 147 148 Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: quitting\n", this); 93 149 } 94 150 -
src/xplra/ServerThread.h
r2 r3 37 37 #include <xplcommon/Waiter.h> 38 38 #include <xplcommon/BufferedStream.h> 39 #include <xplcommon/ BlockingStream.h>39 #include <xplcommon/DataStream.h> 40 40 #include <xplcommon/LocalAcceptor.h> 41 41 … … 48 48 //------------------------------------------------------------------------------ 49 49 50 class RequestQueue; 51 52 //------------------------------------------------------------------------------ 53 50 54 /** 51 55 * A thread serving a client. … … 53 57 class ServerThread : public xplcommon::Thread 54 58 { 59 public: 60 /** 61 * Command: get the value of a single dataref. 62 */ 63 static const uint8_t CMD_GET_SINGLE = 0x01; 64 65 /** 66 * Data type: int 67 */ 68 static const uint8_t TYPE_INT = 0x01; 69 70 /** 71 * Data type: float 72 */ 73 static const uint8_t TYPE_FLOAT = 0x02; 74 75 /** 76 * Data type: double 77 */ 78 static const uint8_t TYPE_DOUBLE = 0x03; 79 80 /** 81 * Data type: float array 82 */ 83 static const uint8_t TYPE_FLOAT_ARRAY = 0x11; 84 85 /** 86 * Data type: int array 87 */ 88 static const uint8_t TYPE_INT_ARRAY = 0x12; 89 90 /** 91 * Data type: byte array 92 */ 93 static const uint8_t TYPE_BYTE_ARRAY = 0x13; 94 95 /** 96 * Result code: no error, everything is OK. 97 */ 98 static const uint8_t RESULT_OK = 0x00; 99 100 /** 101 * Result code: invalid command 102 */ 103 static const uint8_t RESULT_INVALID_COMMAND = 0x01; 104 105 /** 106 * Result code: unknown dataref 107 */ 108 static const uint8_t RESULT_UNKNOWN_DATAREF = 0x02; 109 110 /** 111 * Result code: invalid type 112 */ 113 static const uint8_t RESULT_INVALID_TYPE = 0x03; 114 115 /** 116 * Result code: other error 117 */ 118 static const uint8_t RESULT_OTHER_ERROR = 0xff; 119 55 120 private: 56 121 /** … … 77 142 private: 78 143 /** 144 * The request queue to use. 145 */ 146 RequestQueue& requestQueue; 147 148 /** 79 149 * Our waiter. 80 150 */ … … 87 157 88 158 /** 89 * The blockingstream being used for communication.159 * The data stream being used for communication. 90 160 */ 91 xplcommon:: BlockingStream stream;161 xplcommon::DataStream stream; 92 162 93 163 public: … … 96 166 * given acceptor. 97 167 */ 98 ServerThread(xplcommon::LocalAcceptor& acceptor); 168 ServerThread(RequestQueue& requestQueue, 169 xplcommon::LocalAcceptor& acceptor); 99 170 100 171 /**
Note:
See TracChangeset
for help on using the changeset viewer.