Commit bb6f10045b547019d9849acc3a1c9b6993859abd

Authored by Perry Werneck
1 parent 0dc47c93

Working on IPC module for windows.

src/lib3270++/private.h
... ... @@ -237,24 +237,25 @@
237 237 Uint64 = 't'
238 238 };
239 239  
240   - #pragma pack(1)
  240 + struct {
  241 + size_t length;
  242 + size_t used;
  243 + uint8_t * block;
  244 + } in;
  245 +
  246 + struct {
  247 + size_t length;
  248 + size_t used;
  249 + uint8_t * block;
  250 + } out;
  251 +
241 252 struct DataBlock {
242 253 Type type;
243 254 };
244   - #pragma pack()
245   -
246   - std::vector<DataBlock *> input;
247   -
248   - std::vector<DataBlock *> output;
249 255  
250 256 /// @brief Create DataBlock
251   - static DataBlock * createDataBlock(const void *ptr, size_t len);
252   -
253   - /// @brief Descompacta argumentos recebidos.
254   - static void unpack(std::vector<DataBlock *> &args, const uint8_t * buffer, size_t szBuffer);
  257 + DataBlock * pushBlock(const void *ptr, size_t len);
255 258  
256   - /// @brief Compacta array de argumentos em um bloco de dados.
257   - static DWORD pack(std::vector<DataBlock *> &args, uint8_t * outBuffer, size_t szBuffer);
258 259 #else
259 260 struct {
260 261 DBusMessage * in;
... ...
src/lib3270++/windows/request.cc
... ... @@ -44,35 +44,65 @@
44 44  
45 45 namespace TN3270 {
46 46  
  47 + #define PIPE_BUFFER_LENGTH 8192
  48 +
47 49 IPC::Request::Request(const Session &session) {
  50 +
  51 + in.length = PIPE_BUFFER_LENGTH;
  52 + in.used = 0;
  53 + in.block = new uint8_t[in.length];
  54 +
  55 + out.length = PIPE_BUFFER_LENGTH;
  56 + out.used = 0;
  57 + out.block = new uint8_t[in.length];
  58 +
48 59 }
49 60  
50 61 IPC::Request::Request(const Session &session, const char *method) : Request(session) {
  62 +
  63 + // Add name
  64 + strcpy((char *) out.block, method);
  65 + out.used += strlen((char *) method) + 1;
  66 +
  67 + // Add ID
  68 + *((uint16_t *) (out.block + out.used)) = (uint16_t) 3;
  69 + out.used += sizeof(uint16_t);
  70 +
51 71 }
52 72  
53 73 IPC::Request::Request(const Session &session, bool isSet, const char *property) : Request(session) {
  74 +
  75 + // Add name
  76 + strcpy((char *) out.block, property);
  77 + out.used += strlen((char *) property) + 1;
  78 +
  79 + // Add ID (SetProperty = 2, getProperty = 1)
  80 + *((uint16_t *) (out.block + out.used)) = (uint16_t) (isSet ? 2 : 1);
  81 + out.used += sizeof(uint16_t);
  82 +
54 83 }
55 84  
56 85 IPC::Request::~Request() {
57 86  
58   - for(auto block : input) {
59   - delete[] ((uint8_t *) block);
60   - }
61   -
62   - for(auto block : output) {
63   - delete[] ((uint8_t *) block);
64   - }
  87 + delete[] ((uint8_t *) in.block);
  88 + delete[] ((uint8_t *) out.block);
65 89  
66 90 }
67 91  
68 92 /// @brief Create DataBlock
69   - IPC::Request::DataBlock * IPC::Request::createDataBlock(const void *ptr, size_t length) {
  93 + IPC::Request::DataBlock * IPC::Request::pushBlock(const void *ptr, size_t length) {
70 94  
71   - IPC::Request::DataBlock * rc = (IPC::Request::DataBlock *) (new uint8_t[sizeof(IPC::Request::DataBlock)+length]);
72   - memset((void *) rc, 0, sizeof(IPC::Request::DataBlock));
  95 + if((out.used + length + sizeof(IPC::Request::DataBlock)) >= out.length) {
  96 + throw std::runtime_error("Too big");
  97 + }
  98 +
  99 + IPC::Request::DataBlock * rc = (IPC::Request::DataBlock *) (out.block + out.used);
73 100 memcpy(((uint8_t *) (rc+1)), ((uint8_t *) ptr), length);
74 101  
  102 + out.used += (sizeof(IPC::Request::DataBlock) + length);
  103 +
75 104 return rc;
  105 +
76 106 }
77 107  
78 108 IPC::Request & IPC::Request::call() {
... ... @@ -80,9 +110,7 @@
80 110 }
81 111  
82 112 IPC::Request & IPC::Request::push(const char *arg) {
83   - IPC::Request::DataBlock * block = createDataBlock(arg, strlen(arg)+1);
84   - block->type = IPC::Request::String;
85   - output.push_back(block);
  113 + pushBlock(arg, strlen(arg)+1)->type = IPC::Request::String;
86 114 return *this;
87 115 }
88 116  
... ...