tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
TPiD.cpp
1 #ifndef TPID_CPP
2 #define TPID_CPP
3 
4 #include "TPiD.hpp"
5 #include <tobicore/TCBlock.hpp>
6 
7 TPiD::TPiD(void) {
8 }
9 
10 TPiD::~TPiD(void) {
11 }
12 #include <iostream>
13 int TPiD::ConfAsClient(const std::string &ip, const std::string& port) {
14  int status = TPInterface::ConfAsClient(ip, port);
15  if(status == TPInterface::Successful)
16  this->_com->Async(true);
17  return status;
18 }
19 
20 int TPiD::ConfAsServer(const std::string &ip, const std::string& port) {
22 }
23 
24 int TPiD::Set(IDSerializer* serializer, int bidx, int* abidx) {
25  if(TPInterface::_com == NULL)
27  if(TPInterface::_com->IsConnected() == false)
29 
30  if(abidx != NULL)
31  *abidx = TCBlock::BlockIdxUnset;
32 
33  serializer->message->SetBlockIdx(bidx);
34  serializer->message->absolute.Tic();
35  serializer->Serialize(&this->_cache);
36  if(TPInterface::_com->Send(TPInterface::_cache) <= 0)
38 
39  int count = 0;
40  while(true) {
41  TPInterface::_cache.clear();
42  if(TPInterface::_com->Recv(&this->_cache) <= 0) {
43  if(count++ == 100)
45  TCSleep(1.000f);
46  continue;
47  }
48 
49 
50  this->_stream.Append(TPInterface::_cache);
51  TPInterface::_cache.clear();
52  if(this->_stream.Extract(&this->_cache, "<tcstatus", "/>") == true) {
53  break;
54  } else {
55  }
56  }
57 
58  int comp, status, fidx;
59  if(this->_lang.IsStatus(this->_cache, &comp, &status, &fidx) == true) {
60  if(abidx != NULL)
61  *abidx = fidx;
63  }
64 
66 }
67 
68 int TPiD::Get(IDSerializer* serializer) {
69  if(TPInterface::_com == NULL)
71  if(TPInterface::_com->IsConnected() == false)
73 
74  TPInterface::_cache.clear();
75  if(TPInterface::_com->Recv(&this->_cache) > 0)
76  this->_stream.Append(TPInterface::_cache);
77 
78  if(this->_stream.Extract(&this->_cache, "<tobiid", "/>") == false)
80 
81  serializer->Deserialize(&this->_cache);
83 }
84 
85 #endif