Changeset 40:ec5dde8a6ff6 in xplra for src/client/c
- Timestamp:
- 02/14/13 18:21:47 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/client/c/hu/varadiistvan/xplra
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/client/c/hu/varadiistvan/xplra/Exception.cc
r14 r40 61 61 //------------------------------------------------------------------------------ 62 62 63 ProtocolException::ProtocolException(errorCode_t errorCode) throw() : 64 errorCode(errorCode) 63 ProtocolException::ProtocolException(errorCode_t errorCode, bool hasParameter, 64 long parameter) throw() : 65 errorCode(errorCode), 66 hasParameter(parameter), 67 parameter(parameter) 65 68 { 66 69 switch (errorCode) { … … 70 73 case UNKNOWN_DATAREF: 71 74 message = "xplra::ProtocolException: unknown dataref"; 75 if (hasParameter) { 76 char buf[32]; 77 snprintf(buf, sizeof(buf), " (# %ld)", parameter); 78 message += buf; 79 } 72 80 break; 73 81 case INVALID_TYPE: … … 85 93 case INVALID_ID: 86 94 message = "xplra::ProtocolException: invalid ID"; 95 break; 96 case INVALID_DURATION: 97 message = "xplra::ProtocolException: invalid duration"; 87 98 break; 88 99 case OTHER: -
src/client/c/hu/varadiistvan/xplra/Exception.h
r19 r40 143 143 INVALID_ID = 7, 144 144 145 /// Invalid duration 146 INVALID_DURATION = 8, 147 145 148 /// Other error 146 149 OTHER = 255 … … 153 156 errorCode_t errorCode; 154 157 158 /** 159 * Indicate if the parameter is valid. 160 */ 161 bool hasParameter; 162 163 /** 164 * Parameter of the error. 165 */ 166 long parameter; 167 155 168 public: 156 169 /** 157 170 * Construct the exception. 158 171 */ 159 ProtocolException(errorCode_t errorCode) throw(); 172 ProtocolException(errorCode_t errorCode, 173 bool hasParameter = false, long parameter = 0) throw(); 160 174 161 175 /** … … 163 177 */ 164 178 errorCode_t getErrorCode() const throw(); 179 180 /** 181 * Get the value of the parameter and whether it is valid or not. 182 */ 183 bool getParameter(long& param) const throw(); 165 184 }; 166 185 … … 246 265 { 247 266 return errorCode; 267 } 268 269 //------------------------------------------------------------------------------ 270 271 inline bool ProtocolException::getParameter(long& param) const throw() 272 { 273 if (hasParameter) param = parameter; 274 return hasParameter; 248 275 } 249 276 -
src/client/c/hu/varadiistvan/xplra/MultiBuffer.cc
r33 r40 610 610 611 611 xplane.stream->flush(); 612 xplane.checkResult( );612 xplane.checkResult(true); 613 613 } 614 614 -
src/client/c/hu/varadiistvan/xplra/MultiGetter.cc
r33 r40 97 97 xplane.stream->writeU32(registeredID); 98 98 xplane.stream->flush(); 99 xplane.checkResult( );99 xplane.checkResult(true); 100 100 101 101 readValues(); -
src/client/c/hu/varadiistvan/xplra/MultiSetter.cc
r33 r40 99 99 } 100 100 xplane.stream->flush(); 101 xplane.checkResult( );101 xplane.checkResult(true); 102 102 } 103 103 … … 121 121 } 122 122 xplane.stream->flush(); 123 xplane.checkResult( );123 xplane.checkResult(true); 124 124 } 125 125 -
src/client/c/hu/varadiistvan/xplra/XPlane.cc
r36 r40 73 73 //------------------------------------------------------------------------------ 74 74 75 void XPlane::checkResult(uint8_t result) throw(ProtocolException) 75 void XPlane::checkResult(uint8_t result, bool hasParameter, long parameter) 76 throw(ProtocolException) 76 77 { 77 78 switch(result) { … … 79 80 return; 80 81 case Protocol::RESULT_INVALID_COMMAND: 81 throw ProtocolException(ProtocolException::INVALID_COMMAND); 82 throw ProtocolException(ProtocolException::INVALID_COMMAND, 83 hasParameter, parameter); 82 84 case Protocol::RESULT_UNKNOWN_DATAREF: 83 throw ProtocolException(ProtocolException::UNKNOWN_DATAREF); 85 throw ProtocolException(ProtocolException::UNKNOWN_DATAREF, 86 hasParameter, parameter); 84 87 case Protocol::RESULT_INVALID_TYPE: 85 throw ProtocolException(ProtocolException::INVALID_TYPE); 88 throw ProtocolException(ProtocolException::INVALID_TYPE, 89 hasParameter, parameter); 86 90 case Protocol::RESULT_INVALID_LENGTH: 87 throw ProtocolException(ProtocolException::INVALID_LENGTH); 91 throw ProtocolException(ProtocolException::INVALID_LENGTH, 92 hasParameter, parameter); 88 93 case Protocol::RESULT_INVALID_OFFSET: 89 throw ProtocolException(ProtocolException::INVALID_OFFSET); 94 throw ProtocolException(ProtocolException::INVALID_OFFSET, 95 hasParameter, parameter); 90 96 case Protocol::RESULT_INVALID_COUNT: 91 throw ProtocolException(ProtocolException::INVALID_COUNT); 97 throw ProtocolException(ProtocolException::INVALID_COUNT, 98 hasParameter, parameter); 92 99 case Protocol::RESULT_INVALID_ID: 93 throw ProtocolException(ProtocolException::INVALID_ID); 100 throw ProtocolException(ProtocolException::INVALID_ID, 101 hasParameter, parameter); 102 case Protocol::RESULT_INVALID_DURATION: 103 throw ProtocolException(ProtocolException::INVALID_DURATION, 104 hasParameter, parameter); 94 105 case Protocol::RESULT_OTHER_ERROR: 95 106 default: 96 throw ProtocolException(ProtocolException::OTHER); 107 throw ProtocolException(ProtocolException::OTHER, 108 hasParameter, parameter); 97 109 } 98 110 } … … 100 112 //------------------------------------------------------------------------------ 101 113 102 void XPlane::checkResult( ) throw(ProtocolException, IOException)114 void XPlane::checkResult(bool multi) throw(ProtocolException, IOException) 103 115 { 104 116 uint8_t result = stream->readU8(); 105 checkStream(); 106 checkResult(result); 117 bool hasParameter = false; 118 long parameter = 0; 119 if (multi) { 120 if (result==Protocol::RESULT_UNKNOWN_DATAREF) { 121 parameter = stream->readU32(); 122 hasParameter = true; 123 } 124 } 125 checkStream(); 126 checkResult(result, hasParameter, parameter); 107 127 } 108 128 … … 205 225 206 226 checkStream(); 227 } 228 229 //------------------------------------------------------------------------------ 230 231 void XPlane::reloadPlugins() throw(Exception) 232 { 233 stream->writeU8(Protocol::COMMAND_RELOAD_PLUGINS); 234 stream->flush(); 235 checkResult(); 207 236 } 208 237 … … 457 486 } 458 487 } 488 489 //------------------------------------------------------------------------------ 490 491 void XPlane::showMessage(const char* message, float duration) throw(Exception) 492 { 493 stream->writeU8(Protocol::COMMAND_SHOW_MESSAGE); 494 stream->writeString(message); 495 stream->writeFloat(duration); 496 stream->flush(); 497 checkResult(); 498 } 499 459 500 //------------------------------------------------------------------------------ 460 501 -
src/client/c/hu/varadiistvan/xplra/XPlane.h
r36 r40 150 150 151 151 /** 152 * Reload the plugins loaded in X-Plane. After this the connection 153 * fails. 154 */ 155 void reloadPlugins() throw(Exception); 156 157 /** 152 158 * Get the integer value of the dataref with the given name. 153 159 */ … … 271 277 size_t offset = 0) throw(Exception); 272 278 279 /** 280 * Show a textual message for a certain duration. 281 */ 282 void showMessage(const char* message, float duration) throw(Exception); 283 273 284 private: 274 285 /** … … 281 292 * throw a ProtocolException with the correct error code. 282 293 */ 283 void checkResult(uint8_t result) throw(ProtocolException); 294 void checkResult(uint8_t result, bool hasParameter = false, 295 long parameter = 0) throw(ProtocolException); 284 296 285 297 /** … … 288 300 * is some problem with the stream, an IOException is thrown. 289 301 */ 290 void checkResult( ) throw(ProtocolException, IOException);302 void checkResult(bool multi = false) throw(ProtocolException, IOException); 291 303 292 304 /** -
src/client/c/hu/varadiistvan/xplra/xplra.cc
r36 r40 515 515 //------------------------------------------------------------------------------ 516 516 517 extern "C" int xplra_reload_plugins(int connectionID) 518 { 519 Connection* connection = ConnectionSlot::getValue(connectionID); 520 if (connection==0) return -1; 521 try { 522 connection->reloadPlugins(); 523 return 0; 524 } catch (...) { 525 connection->handleException(); 526 return -1; 527 } 528 } 529 530 //------------------------------------------------------------------------------ 531 517 532 extern "C" int xplra_get_int(int* value, int connectionID, const char* name) 518 533 { … … 1267 1282 try { 1268 1283 return connection->destroyMultiBuffer(bufferID) ? 0 : -1; 1284 } catch(...) { 1285 connection->handleException(); 1286 return -1; 1287 } 1288 } 1289 1290 //------------------------------------------------------------------------------ 1291 //------------------------------------------------------------------------------ 1292 1293 extern "C" int xplra_show_message(int connectionID, 1294 const char* message, float duration) 1295 { 1296 Connection* connection = ConnectionSlot::getValue(connectionID); 1297 if (connection==0) return -1; 1298 1299 try { 1300 connection->showMessage(message, duration); 1301 return 0; 1269 1302 } catch(...) { 1270 1303 connection->handleException(); -
src/client/c/hu/varadiistvan/xplra/xplra.h
r36 r40 79 79 #define ERROR_PROTOCOL_INVALID_ID = 7 80 80 81 /** An invalid duration was specified */ 82 #define ERROR_PROTOCOL_INVALID_DURATION = 8 83 81 84 /** Other protocol error */ 82 #define ERROR_PROTOCOL_OTHER = 885 #define ERROR_PROTOCOL_OTHER = 255 83 86 84 87 /** A function requiring a connection is called without a connection */ … … 137 140 int* xplaneVersion, int* xplmVersion, 138 141 int* xplraVersion); 142 143 /*----------------------------------------------------------------------------*/ 144 145 /** 146 * Reload the plugins in X-Plane. After this the connection fails. 147 */ 148 int xplra_reload_plugins(int connectionID); 139 149 140 150 /*----------------------------------------------------------------------------*/ … … 720 730 721 731 /** 722 * Destr uy a multi-dataref buffer for the given connection.732 * Destroy a multi-dataref buffer for the given connection. 723 733 * 724 734 * @param connectionID the ID of the connection for which the buffer … … 729 739 int xplra_multi_destroy_buffer(int connectionID, int bufferID); 730 740 741 /*----------------------------------------------------------------------------*/ 742 /*----------------------------------------------------------------------------*/ 743 744 /** 745 * Show a message in the simulator window for the given duration. 746 */ 747 int xplra_show_message(int connectionID, const char* message, float duration); 748 749 /*----------------------------------------------------------------------------*/ 731 750 /*----------------------------------------------------------------------------*/ 732 751
Note:
See TracChangeset
for help on using the changeset viewer.