Changeset 5:94fdd791268f in xplra


Ignore:
Timestamp:
01/03/13 18:27:08 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Extracted the protocol-related constants into their own class

Location:
src/xplra
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/xplra/Makefile.am

    r4 r5  
    3737        Request.h               \
    3838        RequestQueue.h          \
     39        Protocol.h              \
    3940        ServerThread.h          \
    4041        Task.h                  \
  • src/xplra/ServerThread.cc

    r3 r5  
    3232
    3333#include "RequestQueue.h"
     34#include "Protocol.h"
    3435#include "GetDataRefTask.h"
    3536#include "TaskRequest.h"
     
    109110        //             this, command);
    110111
    111         if (command==CMD_GET_SINGLE) {
     112        if (command==Protocol::CMD_GET_SINGLE) {
    112113            string name = stream.readString();
    113114            uint8_t type = stream.readU8();
     
    115116            // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: name='%s', type=0x%02x\n",
    116117            //             this, name.c_str(), type);
    117             if (type==TYPE_BYTE_ARRAY) {
     118            if (type==Protocol::TYPE_BYTE_ARRAY) {
    118119                int length = stream.readS32();
    119120                if (!stream) continue;
     
    128129                if (requestQueue.execute(&request)) {
    129130                    // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: request executed\n");
    130                     stream.writeU8(RESULT_OK);
     131                    stream.writeU8(Protocol::RESULT_OK);
    131132                    int length = task->getLength();
    132133                    stream.writeS32(length);
     
    138139                }
    139140            } else {
    140                 stream.writeU8(RESULT_OTHER_ERROR);
     141                stream.writeU8(Protocol::RESULT_OTHER_ERROR);
    141142            }
    142143        } else {
    143             stream.writeU8(RESULT_INVALID_COMMAND);
     144            stream.writeU8(Protocol::RESULT_INVALID_COMMAND);
    144145        }
    145146        stream.flush();
  • src/xplra/ServerThread.h

    r3 r5  
    5757class ServerThread : public xplcommon::Thread
    5858{
    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 
    12059private:
    12160    /**
Note: See TracChangeset for help on using the changeset viewer.