utest.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Southwest Research Institute
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Southwest Research Institute, nor the names
16  * of its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
50 
51 #include <gtest/gtest.h>
52 #include <thread>
53 #include <chrono>
54 #include <limits>
55 #include <vector>
56 
57 using namespace industrial::simple_message;
58 using namespace industrial::byte_array;
59 using namespace industrial::shared_types;
60 using namespace industrial::smpl_msg_connection;
61 using namespace industrial::udp_socket;
62 using namespace industrial::udp_client;
63 using namespace industrial::udp_server;
64 using namespace industrial::tcp_socket;
65 using namespace industrial::tcp_client;
66 using namespace industrial::tcp_server;
67 using namespace industrial::ping_message;
68 using namespace industrial::ping_handler;
69 using namespace industrial::joint_data;
70 using namespace industrial::joint_message;
71 using namespace industrial::message_manager;
73 using namespace industrial::joint_traj_pt;
74 using namespace industrial::joint_traj_pt_message;
75 using namespace industrial::typed_message;
76 using namespace industrial::joint_traj;
77 
78 // Multiple tests require TEST_PORT_BASE to be defined. This is defined
79 // by the make file at compile time.
80 //#define TEST_PORT_BASE 11000
81 
82 TEST(ByteArraySuite, init)
83 {
84 
85  const shared_int SIZE = 100;
86 
87  ByteArray bytes;
88  char buffer[SIZE];
89 
90  // Valid byte arrays
91  EXPECT_TRUE(bytes.init(&buffer[0], SIZE));
92  EXPECT_EQ((shared_int)bytes.getBufferSize(), SIZE);
93 
94  // Invalid init (too big)
95  if (bytes.getMaxBufferSize() < std::numeric_limits<shared_int>::max())
96  {
97  shared_int TOO_BIG = bytes.getMaxBufferSize()+1;
98  std::vector<char> bigBuffer(TOO_BIG);
99  EXPECT_FALSE(bytes.init(&bigBuffer[0], TOO_BIG));
100  }
101  else
102  std::cout << std::string(15, ' ')
103  << "ByteArray.MaxSize==INT_MAX. Skipping TOO_BIG tests" << std::endl;
104 
105 }
106 
107 TEST(ByteArraySuite, loading)
108 {
109  const shared_int SIZE = 100;
110  char buffer[SIZE];
111 
112  ByteArray bytes;
113  ByteArray empty;
114 
115  ASSERT_TRUE(bytes.init(&buffer[0], SIZE));
116 
117  shared_bool bIN = true, bOUT = false;
118  shared_int iIN = 999, iOUT = 0;
119  shared_real rIN = 9999.9999, rOUT = 0;
120 
121  // Boolean loading
122  EXPECT_TRUE(bytes.load(bIN));
123  EXPECT_EQ(bytes.getBufferSize(), SIZE+sizeof(shared_bool));
124  EXPECT_TRUE(bytes.unload(bOUT));
125  EXPECT_EQ((shared_int)bytes.getBufferSize(), SIZE);
126  EXPECT_EQ(bOUT, bIN);
127 
128  // Integer loading
129  EXPECT_TRUE(bytes.load(iIN));
130  EXPECT_EQ(bytes.getBufferSize(), SIZE+sizeof(shared_int));
131  EXPECT_TRUE(bytes.unload(iOUT));
132  EXPECT_EQ((shared_int)bytes.getBufferSize(), SIZE);
133  EXPECT_EQ(iOUT, iIN);
134 
135  // Real loading
136  EXPECT_TRUE(bytes.load(rIN));
137  EXPECT_EQ(bytes.getBufferSize(), SIZE+sizeof(shared_real));
138  EXPECT_TRUE(bytes.unload(rOUT));
139  EXPECT_EQ((shared_int)bytes.getBufferSize(), SIZE);
140  EXPECT_EQ(rOUT, rIN);
141 
142  // Unloading a single member (down to an empty buffer size)
143  EXPECT_TRUE(empty.load(bIN));
144  EXPECT_EQ(empty.getBufferSize(), sizeof(shared_bool));
145  EXPECT_TRUE(empty.unload(bOUT));
146  EXPECT_EQ((int)empty.getBufferSize(), 0);
147  EXPECT_EQ(bOUT, bIN);
148 
149  // Loading two members (unloading the first) and then checking the value of the second
150  rOUT = 0.0;
151  iOUT = 0;
152  EXPECT_TRUE(empty.load(rIN));
153  EXPECT_EQ(empty.getBufferSize(), sizeof(shared_real));
154  EXPECT_TRUE(empty.load(iIN));
155  EXPECT_EQ(empty.getBufferSize(), sizeof(shared_real)+sizeof(shared_int));
156  EXPECT_TRUE(empty.unloadFront(rOUT));
157  EXPECT_EQ(rOUT, rIN);
158  EXPECT_TRUE(empty.unload(iOUT));
159  EXPECT_EQ((int)empty.getBufferSize(), 0);
160  EXPECT_EQ(iOUT, iIN);
161 }
162 
163 TEST(ByteArraySuite, byteSwapping)
164 {
165  if(ByteArray::isByteSwapEnabled())
166  {
167  ASSERT_TRUE(ByteArray::isByteSwapEnabled());
168 
169  ByteArray swapped;
170  unsigned char buffer[] = {
171  0x00, 0x00, 0x00, 0x38, // be: 56
172  0x00, 0x00, 0x00, 0x0a, // be: 10
173  0x00, 0x00, 0x00, 0x01, // be: 1
174 
175  0x3e, 0x81, 0x32, 0x64, // be: 0.25233757495880127
176  0x3f, 0x30, 0x4b, 0x75, // be: 0.68865138292312622
177  0x3f, 0xa8, 0x9d, 0xd2, // be: 1.3173162937164307
178  0x3f, 0x85, 0x93, 0xdd, // be: 1.0435749292373657
179  0xbf, 0xf4, 0x8c, 0xc5, // be: -1.9105459451675415
180 
181  };
182  const unsigned int bufferLength = 32;
183  shared_int tempInt;
184  shared_real tempReal;
185 
186  swapped.init((const char*) buffer, bufferLength);
187  ASSERT_EQ(swapped.getBufferSize(), bufferLength);
188 
189  ASSERT_TRUE(swapped.unload(tempReal));
190  EXPECT_FLOAT_EQ(tempReal, -1.9105459451675415);
191 
192  ASSERT_TRUE(swapped.unload(tempReal));
193  EXPECT_FLOAT_EQ(tempReal, 1.0435749292373657);
194 
195  ASSERT_TRUE(swapped.unload(tempReal));
196  EXPECT_FLOAT_EQ(tempReal, 1.3173162937164307);
197 
198  ASSERT_TRUE(swapped.unload(tempReal));
199  EXPECT_FLOAT_EQ(tempReal, 0.68865138292312622);
200 
201  ASSERT_TRUE(swapped.unload(tempReal));
202  EXPECT_FLOAT_EQ(tempReal, 0.25233757495880127);
203 
204  ASSERT_TRUE(swapped.unload(tempInt));
205  EXPECT_EQ(tempInt, 1);
206 
207  ASSERT_TRUE(swapped.unload(tempInt));
208  EXPECT_EQ(tempInt, 10);
209 
210  ASSERT_TRUE(swapped.unload(tempInt));
211  EXPECT_EQ(tempInt, 56);
212 
213  ASSERT_EQ(swapped.getBufferSize(), 0);
214  }
215 
216 }
217 
218 TEST(ByteArraySuite, copy)
219 {
220 
221  const shared_int SIZE = 100;
222  char buffer[SIZE];
223 
224  // Copy
225  ByteArray copyFrom;
226  ByteArray copyTo;
227 
228  EXPECT_TRUE(copyFrom.init(&buffer[0], SIZE));
229  EXPECT_TRUE(copyTo.load(copyFrom));
230  EXPECT_EQ((shared_int)copyTo.getBufferSize(), SIZE);
231  EXPECT_TRUE(copyTo.load(copyFrom));
232  EXPECT_EQ((shared_int)copyTo.getBufferSize(), 2*SIZE);
233 
234  // Copy too large
235  ByteArray tooBig;
236  if (tooBig.getMaxBufferSize()-1 <= std::numeric_limits<shared_int>::max())
237  {
238  shared_int TOO_BIG = tooBig.getMaxBufferSize()-1;
239  std::vector<char> bigBuffer(TOO_BIG);
240 
241  EXPECT_TRUE(tooBig.init(&bigBuffer[0], TOO_BIG));
242  EXPECT_FALSE(copyTo.load(tooBig));
243  // A failed load should not change the buffer.
244  EXPECT_EQ((shared_int)copyTo.getBufferSize(), 2*SIZE);
245  }
246  else
247  std::cout << std::string(15, ' ')
248  << "ByteArray.MaxSize==INT_MAX. Skipping TOO_BIG tests" << std::endl;
249 }
250 
251 // Need access to protected members for testing
252 #ifndef UDP_TEST
253 class TestClient : public TcpClient
254 {
255  public:
256  bool sendBytes(ByteArray & buffer)
257  {
258  return TcpClient::sendBytes(buffer);
259  };
260 };
261 class TestServer : public TcpServer
262 {
263  public:
264  bool receiveBytes(ByteArray & buffer, shared_int num_bytes)
265  {
266  return TcpServer::receiveBytes(buffer, num_bytes, -1);
267  }
268 
269  bool receiveBytes(ByteArray & buffer, shared_int num_bytes, shared_int timeout_ms)
270  {
271  return TcpServer::receiveBytes(buffer, num_bytes, timeout_ms);
272  }
273 };
274 #else
275 class TestClient : public UdpClient
276 {
277  public:
278  bool sendBytes(ByteArray & buffer)
279  {
280  return UdpClient::sendBytes(buffer);
281  };
282 };
283 class TestServer : public UdpServer
284 {
285  public:
286  bool receiveBytes(ByteArray & buffer, shared_int num_bytes)
287  {
288  return UdpServer::receiveBytes(buffer, num_bytes, -1);
289  }
290 
291  bool receiveBytes(ByteArray & buffer, shared_int num_bytes, shared_int timeout_ms)
292  {
293  return UdpServer::receiveBytes(buffer, num_bytes, timeout_ms);
294  }
295 };
296 #endif
297 
298 void*
300 {
301  TestServer* server = (TestServer*)arg;
302  server->makeConnect();
303  return NULL;
304 }
305 
306 TEST(SocketSuite, read)
307 {
308  const int port = TEST_PORT_BASE;
309  char ipAddr[] = "127.0.0.1";
310 
311  TestClient client;
312  TestServer server;
313  ByteArray send, recv;
314  shared_int DATA = 99;
315  shared_int TWO_INTS = 2 * sizeof(shared_int);
316  shared_int ONE_INTS = 1 * sizeof(shared_int);
317 
318  // Construct server
319  ASSERT_TRUE(server.init(port));
320 
321  // Construct a client
322  ASSERT_TRUE(client.init(&ipAddr[0], port));
323 
324  std::thread serverConnectThrd(connectServerFunc, &server);
325 
326  ASSERT_TRUE(client.makeConnect());
327  serverConnectThrd.join();
328 
329  ASSERT_TRUE(send.load(DATA));
330 
331  // Send just right amount
332  ASSERT_TRUE(client.sendBytes(send));
333  ASSERT_TRUE(client.sendBytes(send));
334  std::this_thread::sleep_for(std::chrono::seconds(2));
335  ASSERT_TRUE(server.receiveBytes(recv, TWO_INTS));
336  ASSERT_EQ(TWO_INTS, recv.getBufferSize());
337 
338  // Send too many bytes
339  ASSERT_TRUE(client.sendBytes(send));
340  ASSERT_TRUE(client.sendBytes(send));
341  ASSERT_TRUE(client.sendBytes(send));
342  ASSERT_TRUE(server.receiveBytes(recv, TWO_INTS));
343  ASSERT_EQ(TWO_INTS, recv.getBufferSize());
344  ASSERT_TRUE(server.receiveBytes(recv, ONE_INTS));
345  ASSERT_EQ(ONE_INTS, recv.getBufferSize());
346 }
347 
348 TEST(SocketSuite, readTimeout)
349 {
350  const int port = TEST_PORT_BASE;
351  char ipAddr[] = "127.0.0.1";
352 
353  TestClient client;
354  TestServer server;
355  ByteArray send, recv;
356  shared_int DATA = 99;
357  shared_int TWO_INTS = 2 * sizeof(shared_int);
358  shared_int ONE_INTS = 1 * sizeof(shared_int);
359  shared_int TIMEOUT_MS = 100;
360 
361  // Construct server
362  ASSERT_TRUE(server.init(port));
363 
364  // Construct a client
365  ASSERT_TRUE(client.init(&ipAddr[0], port));
366  pthread_t serverConnectThrd;
367  pthread_create(&serverConnectThrd, NULL, connectServerFunc, &server);
368 
369  ASSERT_TRUE(client.makeConnect());
370  pthread_join(serverConnectThrd, NULL);
371 
372  ASSERT_TRUE(send.load(DATA));
373 
374  // Try a read without sending anything
375  ASSERT_FALSE(server.receiveBytes(recv, TWO_INTS, TIMEOUT_MS));
376  ASSERT_EQ(0, recv.getBufferSize());
377 
378  // Send too few bytes
379  ASSERT_TRUE(client.sendBytes(send));
380  sleep(2);
381  ASSERT_FALSE(server.receiveBytes(recv, TWO_INTS, TIMEOUT_MS));
382  ASSERT_EQ(ONE_INTS, recv.getBufferSize());
383 }
384 
385 // Utility for running tcp client in sending loop
386 void
387 spinSender(void* arg, bool &running)
388 {
389  TestClient* client = (TestClient*)arg;
390  ByteArray send;
391  const int DATA = 256;
392 
393  send.load(DATA);
394 
395  while(running)
396  {
397  client->sendBytes(send);
398  std::this_thread::sleep_for(std::chrono::milliseconds(100));
399  }
400 }
401 
402 TEST(SocketSuite, splitPackets)
403 {
404  const int port = TEST_PORT_BASE + 1;
405  char ipAddr[] = "127.0.0.1";
406  const int RECV_LENGTH = 64;
407 
408  TestClient client;
409  TestServer server;
410  ByteArray recv;
411  // Construct server
412  ASSERT_TRUE(server.init(port));
413 
414  // Construct a client
415  ASSERT_TRUE(client.init(&ipAddr[0], port));
416  std::thread serverConnectThrd(connectServerFunc, &server);
417 
418  ASSERT_TRUE(client.makeConnect());
419  serverConnectThrd.join();
420 
421  bool senderRunning = true;
422  std::thread senderThrd(spinSender, &client, std::ref(senderRunning));
423 
424  ASSERT_TRUE(server.receiveBytes(recv, RECV_LENGTH));
425  ASSERT_EQ(RECV_LENGTH, recv.getBufferSize());
426 
427  senderRunning = false;
428  senderThrd.join();
429 }
430 
431 
432 TEST(SimpleMessageSuite, init)
433 {
434  SimpleMessage msg;
435  ByteArray bytes;
436 
437  // Valid messages
442 
443  // Unused command
445 
446  // Service request with a reply
449 }
450 
451 TEST(PingMessageSuite, init)
452 {
453  PingMessage ping;
454  SimpleMessage msg;
455 
456  EXPECT_FALSE(ping.init(msg));
457  ping.init();
458  EXPECT_EQ(StandardMsgTypes::PING, ping.getMessageType());
459 
460  ping = PingMessage();
462  EXPECT_TRUE(ping.init(msg));
463  EXPECT_EQ(StandardMsgTypes::PING, ping.getMessageType());
464 }
465 
466 TEST(PingMessageSuite, toMessage)
467 {
468  PingMessage ping;
469  SimpleMessage msg;
470 
471  ping.init();
472 
473  ASSERT_TRUE(ping.toReply(msg, ReplyTypes::SUCCESS));
474  EXPECT_EQ(StandardMsgTypes::PING, msg.getMessageType());
475  EXPECT_EQ(CommTypes::SERVICE_REPLY, msg.getCommType());
476  EXPECT_EQ(ReplyTypes::SUCCESS, msg.getReplyCode());
477 
478  ASSERT_TRUE(ping.toRequest(msg));
479  EXPECT_EQ(StandardMsgTypes::PING, msg.getMessageType());
480  EXPECT_EQ(CommTypes::SERVICE_REQUEST, msg.getCommType());
481  EXPECT_EQ(ReplyTypes::INVALID, msg.getReplyCode());
482 
483  EXPECT_FALSE(ping.toTopic(msg));
484 
485 }
486 
487 TEST(PingHandlerSuite, init)
488 {
489  PingHandler handler;
490  TestClient client;
491 
492  ASSERT_TRUE(handler.init(&client));
493  EXPECT_EQ(StandardMsgTypes::PING, handler.getMsgType());
494 
495  EXPECT_FALSE(handler.init(NULL));
496 
497 }
498 
499 TEST(MessageManagerSuite, init)
500 {
501  MessageManager manager;
502  TestClient client;
503 
504  EXPECT_TRUE(manager.init(&client));
505  EXPECT_FALSE(manager.init(NULL));
506 
507 }
508 
509 TEST(MessageManagerSuite, addHandler)
510 {
511  MessageManager manager;
512  TestClient client;
513  PingHandler handler;
514 
515  EXPECT_EQ(0, (int)manager.getNumHandlers());
516 
517  ASSERT_TRUE(manager.init(&client));
518  EXPECT_EQ(1, (int)manager.getNumHandlers());
519  EXPECT_FALSE(manager.add(NULL));
520 
521  ASSERT_TRUE(handler.init(&client));
522  EXPECT_FALSE(manager.add(&handler));
523 }
524 
525 // wrapper around MessageManager::spin() that can be passed to
526 // pthread_create()
527 void*
528 spinFunc(void* arg)
529 {
530  MessageManager* mgr = (MessageManager*)arg;
531  mgr->spin();
532  return NULL;
533 }
534 
535 /* Commenting out this test because build shows "unstable" with disabled tests
536 // See https://github.com/ros-industrial/industrial_core/issues/149 for details
537 TEST(DISABLED_MessageManagerSuite, tcp)
538 {
539  const int port = TEST_PORT_BASE + 201;
540  char ipAddr[] = "127.0.0.1";
541 
542  TestClient* client = new TestClient();
543  TestServer server;
544  SimpleMessage pingRequest, pingReply;
545  MessageManager msgManager;
546 
547  // MessageManager uses ros::ok, which needs ros spinner
548  ros::AsyncSpinner spinner(0);
549  spinner.start();
550 
551  ASSERT_TRUE(pingRequest.init(StandardMsgTypes::PING, CommTypes::SERVICE_REQUEST, ReplyTypes::INVALID));
552 
553  // TCP Socket testing
554 
555  // Construct server
556  ASSERT_TRUE(server.init(port));
557 
558  // Construct a client
559  ASSERT_TRUE(client->init(&ipAddr[0], port));
560 
561  // Connect server and client
562  pthread_t serverConnectThrd;
563  pthread_create(&serverConnectThrd, NULL, connectServerFunc, &server);
564 
565  ASSERT_TRUE(client->makeConnect());
566  pthread_join(serverConnectThrd, NULL);
567 
568  // Listen for client connection, init manager and start thread
569  ASSERT_TRUE(msgManager.init(&server));
570 
571  // TODO: The message manager is not thread safe (threads are used for testing,
572  // but running the message manager in a thread results in errors when the
573  // underlying connection is deconstructed before the manager
574  //boost::thread spinSrvThrd(boost::bind(&MessageManager::spin, &msgManager));
575  pthread_t spinSrvThrd;
576  pthread_create(&spinSrvThrd, NULL, spinFunc, &msgManager);
577 
578  // Ping the server
579  ASSERT_TRUE(client->sendMsg(pingRequest));
580  ASSERT_TRUE(client->receiveMsg(pingReply));
581  ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply));
582 
583  // Delete client and try to reconnect
584 
585  delete client;
586  sleep(10); //Allow time for client to destruct and free up port
587  client = new TestClient();
588 
589  ASSERT_TRUE(client->init(&ipAddr[0], port));
590  ASSERT_TRUE(client->makeConnect());
591  ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply));
592 
593  pthread_cancel(spinSrvThrd);
594  pthread_join(spinSrvThrd, NULL);
595 
596  delete client;
597 }
598 */
599 
600 // Run all the tests that were declared with TEST()
601 int main(int argc, char **argv)
602 {
603  ros::init(argc, argv, "test"); // some tests need ROS framework
604  testing::InitGoogleTest(&argc, argv);
605  return RUN_ALL_TESTS();
606 }
Defines TCP server functions.
Definition: tcp_server.h:49
int getMessageType() const
gets message type (enumeration)
bool init(char *buff, int port_num)
initializes TCP client socket. Object can either be a client OR a server, NOT BOTH.
Definition: tcp_client.cpp:55
void * spinFunc(void *arg)
Definition: utest.cpp:528
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
Contains platform specific type definitions that guarantee the size of primitive data types...
Definition: shared_types.h:52
void init()
Initializes or Reinitializes an empty buffer.
Definition: byte_array.cpp:62
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
Class initializer.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
This class defines a simple messaging protocol for communicating with an industrial robot controller...
int getMessageType()
Gets message type(see StandardMsgType)
bool unloadFront(industrial::shared_types::shared_real &value)
unloads a double value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped.
Definition: byte_array.cpp:334
bool load(industrial::shared_types::shared_bool value)
loads a boolean into the byte array
Definition: byte_array.cpp:142
virtual bool toRequest(industrial::simple_message::SimpleMessage &msg)
creates a simple_message request
Definition: typed_message.h:96
Class encapsulated ping message generation methods (either to or from a SimpleMessage type...
Definition: ping_message.h:60
unsigned int getNumHandlers()
Gets number of handlers.
bool receiveBytes(ByteArray &buffer, shared_int num_bytes)
Definition: utest.cpp:264
bool makeConnect()
connects to the remote host
Definition: tcp_server.cpp:118
int getMsgType()
Gets message type that callback expects.
void spin()
Perform a indefinite execution of the message manager.
void spinSender(void *arg, bool &running)
Definition: utest.cpp:387
bool add(industrial::message_handler::MessageHandler *handler, bool allow_replace=false)
Adds a message handler to the manager.
Message handler that handles ping messages.
Definition: ping_handler.h:60
The byte array wraps a dynamic array of bytes (i.e. char).
Definition: byte_array.h:80
bool sendBytes(ByteArray &buffer)
Method used by send message interface method. This should be overridden for the specific connection t...
Definition: utest.cpp:256
int main(int argc, char **argv)
Definition: utest.cpp:601
bool toTopic(industrial::simple_message::SimpleMessage &msg)
The ping message overrides the base method toTopic to always return false. A ping cannot be sent as a...
Definition: ping_message.h:96
unsigned int getMaxBufferSize()
gets current buffer size
Definition: byte_array.cpp:392
The message manager handles communications for a simple server.
bool init(int msgType, int commType, int replyCode, industrial::byte_array::ByteArray &data)
Initializes a fully populated simple message.
bool receiveBytes(ByteArray &buffer, shared_int num_bytes, shared_int timeout_ms)
Method used by receive message interface method. This should be overridden for the specific connectio...
Definition: utest.cpp:269
virtual bool toReply(industrial::simple_message::SimpleMessage &msg, industrial::simple_message::ReplyType reply)
creates a simple_message reply
bool makeConnect()
connects to the remote host
Definition: tcp_client.cpp:91
void * connectServerFunc(void *arg)
Definition: utest.cpp:299
unsigned int getBufferSize()
gets current buffer size
Definition: byte_array.cpp:387
TEST(ByteArraySuite, init)
Definition: utest.cpp:82
bool unload(industrial::shared_types::shared_bool &value)
unloads a boolean value from the byte array
Definition: byte_array.cpp:233
bool init(int port_num)
initializes TCP server socket. The connect method must be called following initialization in order to...
Definition: tcp_server.cpp:57
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
Class initializer.
Defines TCP client functions.
Definition: tcp_client.h:52
int getReplyCode()
Gets reply code(see ReplyType)
int getCommType()
Gets message type(see CommType)


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Feb 28 2022 22:34:36