blob: ced2064452d6ad8f1535a7dc43f2759fe92e37a6 [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "RequestMessage.h"
26#include "RemoteProcessorProtocol.h"
27#include <assert.h>
28#include <algorithm>
29#include <ctype.h>
30
31#define base CMessage
32
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020033const char* const CRequestMessage::gacDelimiters = " \t\n\v\f\r";
34
Patrick Benavoli68a91282011-08-31 11:23:23 +020035CRequestMessage::CRequestMessage(const string& strCommand) : base(ECommandRequest), _strCommand(strCommand)
36{
37}
38
39CRequestMessage::CRequestMessage()
40{
41}
42
43// Command Name
44void CRequestMessage::setCommand(const string& strCommand)
45{
46 _strCommand = trim(strCommand);
47}
48
49const string& CRequestMessage::getCommand() const
50{
51 return _strCommand;
52}
53
54// Arguments
55void CRequestMessage::addArgument(const string& strArgument)
56{
57 _argumentVector.push_back(trim(strArgument));
58}
59
60uint32_t CRequestMessage::getArgumentCount() const
61{
62 return _argumentVector.size();
63}
64
65const string& CRequestMessage::getArgument(uint32_t uiArgument) const
66{
67 assert(uiArgument < _argumentVector.size());
68
69 return _argumentVector[uiArgument];
70}
71
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020072const string CRequestMessage::packArguments(uint32_t uiStartArgument, uint32_t uiNbArguments) const
73{
74 string strPackedArguments;
75
76 assert(uiStartArgument + uiNbArguments <= _argumentVector.size());
77
78 // Pack arguments, separating them with a space
79 uint32_t uiArgument;
80
81 bool bFirst = true;
82
83 for (uiArgument = uiStartArgument; uiArgument < uiStartArgument + uiNbArguments; uiArgument++) {
84
85 if (!bFirst) {
86
87 strPackedArguments += " ";
88 } else {
89
90 bFirst = false;
91 }
92
93 strPackedArguments += _argumentVector[uiArgument];
94 }
95
96 return strPackedArguments;
97}
98
Patrick Benavoli68a91282011-08-31 11:23:23 +020099// Fill data to send
100void CRequestMessage::fillDataToSend()
101{
102 // Send command
103 writeString(getCommand());
104
105 // Arguments
106 uint32_t uiArgument;
107
108 for (uiArgument = 0; uiArgument < getArgumentCount(); uiArgument++) {
109
110 writeString(getArgument(uiArgument));
111 }
112}
113
114// Collect received data
115void CRequestMessage::collectReceivedData()
116{
117 // Receive command
118 string strCommand;
119
120 readString(strCommand);
121
122 setCommand(strCommand);
123
124 // Arguments
125 while (getRemainingDataSize()) {
126
127 string strArgument;
128
129 readString(strArgument);
130
131 addArgument(strArgument);
132 }
133}
134
135// Size
136uint32_t CRequestMessage::getDataSize() const
137{
138 // Command
139 uint32_t uiSize = getStringSize(getCommand());
140
141 // Arguments
142 uint32_t uiArgument;
143
144 for (uiArgument = 0; uiArgument < getArgumentCount(); uiArgument++) {
145
146 uiSize += getStringSize(getArgument(uiArgument));
147 }
148 return uiSize;
149}
150
151// Trim input string
152string CRequestMessage::trim(const string& strToTrim)
153{
154 // Trim string
155 string strTrimmed = strToTrim;
156
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200157 strTrimmed.erase(strTrimmed.find_last_not_of(gacDelimiters) + 1 );
158
159 strTrimmed.erase(0, strTrimmed.find_first_not_of(gacDelimiters));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200160
161 return strTrimmed;
162}