Commit 5ace6ea00a4c44a8415d669b5aa2873998a9bff2

Authored by Perry Werneck
1 parent 46b42c15

Implementing IPC commom methods for windows.

src/lib3270++/private.h
... ... @@ -241,8 +241,9 @@
241 241 };
242 242  
243 243 struct {
244   - DWORD length;
245   - DWORD used;
  244 + DWORD length; ///< @brief Length of input buffer.
  245 + DWORD used; ///< @brief Length of used block.
  246 + DWORD current; ///< @brief Offset of the current argument.
246 247 uint8_t * block;
247 248 } in;
248 249  
... ... @@ -256,9 +257,12 @@
256 257 Type type;
257 258 };
258 259  
259   - /// @brief Create DataBlock
  260 + /// @brief Store value on data block.
260 261 DataBlock * pushBlock(const void *ptr, size_t len);
261 262  
  263 + /// @brief Get next argument.
  264 + DataBlock * getNextBlock() const;
  265 +
262 266 #else
263 267 struct {
264 268 DBusMessage * in;
... ... @@ -290,7 +294,6 @@
290 294 Request & call();
291 295  
292 296 // Push values
293   -
294 297 Request & push(const char *arg);
295 298  
296 299 // Pop values
... ...
src/lib3270++/windows/request.cc
... ... @@ -91,7 +91,7 @@
91 91  
92 92 }
93 93  
94   - /// @brief Create DataBlock
  94 + /// @brief Store value on data block.
95 95 IPC::Request::DataBlock * IPC::Request::pushBlock(const void *ptr, size_t length) {
96 96  
97 97 if((out.used + length + sizeof(IPC::Request::DataBlock)) >= out.length) {
... ... @@ -107,17 +107,61 @@
107 107  
108 108 }
109 109  
  110 + /// @brief Get next argument.
  111 + IPC::Request::DataBlock * IPC::Request::getNextBlock() const {
  112 +
  113 + if((in.current + sizeof(IPC::Request::DataBlock)) >= in.used) {
  114 + throw std::runtime_error("Out of range");
  115 + }
  116 +
  117 + return (IPC::Request::DataBlock *) (in.block + in.current);
  118 +
  119 + }
  120 +
110 121 IPC::Request & IPC::Request::push(const char *arg) {
111 122 pushBlock(arg, strlen(arg)+1)->type = IPC::Request::String;
112 123 return *this;
113 124 }
114 125  
115 126 IPC::Request & IPC::Request::pop(std::string &value) {
  127 + DataBlock * block = getNextBlock();
  128 +
  129 + if(block->type != IPC::Request::String)
  130 + throw std::runtime_error("Invalid format");
  131 +
  132 + const char *ptr = (const char *) (block+1);
  133 +
  134 + in.current += (strlen(ptr)+1+sizeof(DataBlock));
  135 +
  136 + value.assign(ptr);
116 137  
117 138 return *this;
118 139 }
119 140  
120 141 IPC::Request & IPC::Request::Request::pop(int &value) {
  142 +
  143 + DataBlock * block = getNextBlock();
  144 +
  145 + switch(block->type) {
  146 + case IPC::Request::Int16:
  147 + value = * ((int16_t *) (block+1));
  148 + in.current += sizeof(int16_t) + sizeof(DataBlock);
  149 + break;
  150 +
  151 + case IPC::Request::Int32:
  152 + value = * ((int32_t *) (block+1));
  153 + in.current += sizeof(int32_t) + sizeof(DataBlock);
  154 + break;
  155 +
  156 + case IPC::Request::Int64:
  157 + value = * ((int64_t *) (block+1));
  158 + in.current += sizeof(int64_t) + sizeof(DataBlock);
  159 + break;
  160 +
  161 + default:
  162 + throw std::runtime_error("Invalid format");
  163 + }
  164 +
121 165 return *this;
122 166 }
123 167  
... ...
src/lib3270++/windows/session.cc
... ... @@ -95,6 +95,8 @@
95 95 lib3270_trace_data(NULL,"Request block",(const char *) this->out.block, this->out.used);
96 96 #endif // DEBUG
97 97  
  98 + in.current = 0;
  99 +
98 100 if(!TransactNamedPipe(
99 101 this->hPipe,
100 102 this->out.block,
... ...