iCub-main
embObjGeneralDevPrivData.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #include <string>
10 #include <yarp/os/Network.h>
11 #include <yarp/os/NetType.h>
13 #include <yarp/conf/environment.h>
14 
15 using namespace yarp::dev;
16 
17 yarp::dev::embObjDevPrivData::embObjDevPrivData(std::string name):deviceNameType(name)
18 {
19  ethManager = nullptr;
20  res = nullptr;
21  behFlags.opened = false;
22 
23  std::string tmp = yarp::conf::environment::get_string("ETH_VERBOSEWHENOK");
24  if (tmp != "")
25  {
26  behFlags.verbosewhenok = (bool)(yarp::conf::numeric::from_string(tmp, 0U));
27  }
28  else
29  {
30  behFlags.verbosewhenok = false;
31  }
32 }
33 
35 {;}
36 
38 {
39  if(nullptr == res)
40  {
41  return deviceNameType + ": BOARD name_unknown (IP unknown) ";
42  }
43  else
44  {
45  return (deviceNameType + ": BOARD " + res->getProperties().boardnameString + " (IP " + res->getProperties().ipv4addrString + ") ");
46  }
47 }
48 
49 
51 {
52  // - first thing to do is verify if the eth manager is available. then i parse info about the eth board.
53 
54  ethManager = eth::TheEthManager::instance();
55  if(NULL == ethManager)
56  {
57  yFatal() << deviceNameType << " fails to instantiate ethManager";
58  return false;
59  }
60 
61  string boardIPstring;
62  string boardName;
63  eOipv4addr_t ipv4addr;
64 
65 
66  if(false == ethManager->verifyEthBoardInfo(config, ipv4addr, boardIPstring, boardName))
67  {
68  yError() << deviceNameType << " object TheEthManager fails in parsing ETH propertiex from xml file";
69  return false;
70  }
71 
72  res = ethManager->requestResource2(interface, config);
73  if(NULL == res)
74  {
75  yError() << deviceNameType << ":requestResource fails because could not instantiate the ethResource for BOARD " << getBoardInfo() << " ... unable to continue";
76  return false;
77  }
78 
79  return true;
80 }
81 
83 {
84 
85  if(!isOpen()) return; //already closed
86 
87  if(ethManager == NULL) return;
88 
89  int ret = ethManager->releaseResource2(res, interface);
90  res = NULL;
91  if(ret == -1)
92  ethManager->killYourself();
93  setOpen(false);
94 }
95 
96 bool yarp::dev::embObjDevPrivData::serviceSetRegulars(eOmn_serv_category_t category, vector<eOprotID32_t> &id32vector, double timeout)
97 {
98 
99  if(false == res->serviceSetRegulars(category, id32vector, timeout))
100  {
101  yError() << getBoardInfo() << "initRegulars() fails to add its variables to regulars: cannot proceed any further";
102  return false;
103  }
104  else
105  {
106  if(isVerbose())
107  {
108  yDebug() << getBoardInfo() << "initRegulars() added" << id32vector.size() << "regular rops ";
109  char nvinfo[128];
110  for (size_t r = 0; r<id32vector.size(); r++)
111  {
112  uint32_t item = id32vector.at(r);
113  eoprot_ID2information(item, nvinfo, sizeof(nvinfo));
114  yDebug() << "\t it added regular rop for" << nvinfo;
115  }
116  }
117  }
118  return true;
119 }
120 
static TheEthManager * instance()
Definition: ethManager.cpp:159
bool prerareEthService(yarp::os::Searchable &config, eth::IethResource *interface)
bool serviceSetRegulars(eOmn_serv_category_t category, vector< eOprotID32_t > &id32vector, double timeout=0.500)
void cleanup(eth::IethResource *interface)
eth::AbstractEthResource * res