Changeset 9:953cd606427c in xplra for src/xplra/ServerThread.cc


Ignore:
Timestamp:
01/04/13 16:12:21 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Registering multi-data update requests works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/xplra/ServerThread.cc

    r8 r9  
    3737#include "TaskRequest.h"
    3838#include "GetMultiDataRefRequest.h"
     39#include "SetMultiDataRefRequest.h"
    3940
    4041#include <xplcommon/Util.h>
     
    7677    bufferedStream(acceptor.getSocket(&waiter)),
    7778    stream(*bufferedStream),
    78     nextGetMultiRequestID(1)
     79    nextGetMultiRequestID(1),
     80    nextSetMultiRequestID(1)
    7981{
    8082    instancesMutex.lock();
     
    9193    for(getMultiRequests_t::iterator i = getMultiRequests.begin();
    9294        i!=getMultiRequests.end(); ++i)
     95    {
     96        delete i->second;
     97    }
     98
     99    for(setMultiRequests_t::iterator i = setMultiRequests.begin();
     100        i!=setMultiRequests.end(); ++i)
    93101    {
    94102        delete i->second;
     
    129137        } else if (command==Protocol::COMMAND_EXECUTE_GET_MULTI) {
    130138            if (!handleExecuteGetMulti()) break;
     139        } else if (command==Protocol::COMMAND_REGISTER_SET_MULTI) {
     140            if (!handleRegisterSetMulti()) break;
     141        } else if (command==Protocol::COMMAND_UNREGISTER_SET_MULTI) {
     142            if (!handleUnregisterSetMulti()) break;
     143        } else if (command==Protocol::COMMAND_EXECUTE_SET_MULTI) {
     144            if (!handleExecuteSetMulti()) break;
    131145        } else {
    132146            stream.writeU8(Protocol::RESULT_INVALID_COMMAND);
     
    177191        stream.writeU8(result);
    178192        return true;
     193    }
     194
     195    task->readValue(stream);
     196    if (!stream) {
     197        delete task;
     198        return false;
    179199    }
    180200
     
    258278//------------------------------------------------------------------------------
    259279
     280bool ServerThread::handleRegisterSetMulti()
     281{
     282    uint8_t result = Protocol::RESULT_OK;
     283    SetMultiDataRefRequest* request =
     284        new SetMultiDataRefRequest(result, stream);
     285    if (result!=Protocol::RESULT_OK || !stream) {
     286        delete request;
     287        stream.writeU8(result);
     288        return stream;
     289    }
     290
     291    size_t id = nextSetMultiRequestID++;
     292    setMultiRequests[id] = request;
     293
     294    stream.writeU8(Protocol::RESULT_OK);
     295    stream.writeU32(id);
     296
     297    return true;
     298}
     299
     300//------------------------------------------------------------------------------
     301
     302bool ServerThread::handleUnregisterSetMulti()
     303{
     304    uint32_t id = stream.readU32();
     305    if (!stream) return false;
     306
     307    setMultiRequests_t::iterator i = setMultiRequests.find(id);
     308    if (i==setMultiRequests.end()) {
     309        stream.writeU8(Protocol::RESULT_INVALID_ID);
     310    } else {
     311        SetMultiDataRefRequest* request = i->second;
     312        setMultiRequests.erase(i);
     313        delete request;
     314        stream.writeU8(Protocol::RESULT_OK);
     315    }
     316
     317    return true;
     318}
     319
     320//------------------------------------------------------------------------------
     321
     322bool ServerThread::handleExecuteSetMulti()
     323{
     324    uint32_t id = stream.readU32();
     325    if (!stream) return false;
     326
     327    setMultiRequests_t::iterator i = setMultiRequests.find(id);
     328    if (i==setMultiRequests.end()) {
     329        stream.writeU8(Protocol::RESULT_INVALID_ID);
     330    } else {
     331        SetMultiDataRefRequest* request = i->second;
     332        request->readValues(stream);
     333        if (!stream || !requestQueue.execute(request)) return false;
     334        request->writeResult(stream);
     335    }
     336
     337    return true;
     338}
     339
     340//------------------------------------------------------------------------------
     341
    260342// Local Variables:
    261343// mode: C++
Note: See TracChangeset for help on using the changeset viewer.