source: xplra/src/plugin/src/xplra/GetMultiDataRefRequest.cc@ 49:2f52c296803c

Last change on this file since 49:2f52c296803c was 13:42fd631176b7, checked in by István Váradi <ivaradi@…>, 11 years ago

Reorganized code to be able to handle the client library as a normal libtool library

File size: 3.6 KB
Line 
1// Copyright (c) 2013 by István Váradi
2
3// This file is part of XPLRA, a remote-access plugin for X-Plane
4
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7
8// 1. Redistributions of source code must retain the above copyright notice, this
9// list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25// The views and conclusions contained in the software and documentation are those
26// of the authors and should not be interpreted as representing official policies,
27// either expressed or implied, of the FreeBSD Project.
28
29//------------------------------------------------------------------------------
30
31#include "GetMultiDataRefRequest.h"
32
33#include "Protocol.h"
34
35#include <hu/varadiistvan/xplcommon/Util.h>
36
37//------------------------------------------------------------------------------
38
39using xplra::GetMultiDataRefRequest;
40
41using hu::varadiistvan::scpl::io::DataStream;
42using hu::varadiistvan::xplcommon::Util;
43
44//------------------------------------------------------------------------------
45
46GetMultiDataRefRequest::GetMultiDataRefRequest(uint8_t& result,
47 DataStream& stream)
48{
49 result = Protocol::RESULT_OK;
50
51 uint32_t numTasks = stream.readU32();
52 if (!stream) return;
53 if (numTasks==0 || numTasks>Protocol::MAX_MULTI_COUNT) {
54 result = Protocol::RESULT_INVALID_COUNT;
55 return;
56 }
57
58 for(size_t i = 0;
59 i<numTasks && result==Protocol::RESULT_OK && stream; ++i)
60 {
61 GetDataRefTask* task = GetDataRefTask::create(result, stream);
62 if (task!=0) addTask(task);
63 }
64}
65
66//------------------------------------------------------------------------------
67
68void GetMultiDataRefRequest::writeResult(DataStream& stream) const
69{
70 // Util::debug("hu.varadiistvan.xplra.GetMultiDataRefRequest[%p]::writeResult\n", this);
71 size_t numTasks = getNumTasks();
72 for(size_t i = 0; i<numTasks; ++i) {
73 GetDataRefTask* task = getTask(i);
74 // Util::debug("hu.varadiistvan.xplra.GetMultiDataRefRequest[%p]::writeResult: task[%zu]: %d @ %p\n",
75 // this, i, task->isValid(), task);
76 if (!task->isValid()) {
77 stream.writeU8(Protocol::RESULT_UNKNOWN_DATAREF);
78 stream.writeU32(i);
79 return;
80 }
81 }
82
83 stream.writeU8(Protocol::RESULT_OK);
84 for(size_t i = 0; i<numTasks; ++i) {
85 GetDataRefTask* task = getTask(i);
86 task->writeValue(stream);
87 }
88}
89
90//------------------------------------------------------------------------------
91
92// Local Variables:
93// mode: C++
94// c-basic-offset: 4
95// indent-tabs-mode: nil
96// End:
Note: See TracBrowser for help on using the repository browser.