iCub-main
ethBoards.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2017 iCub Facility - Istituto Italiano di Tecnologia
5  * Author: Marco Accame
6  * email: marco.accame@iit.it
7  * website: www.robotcub.org
8  * Permission is granted to copy, distribute, and/or modify this program
9  * under the terms of the GNU General Public License, version 2 or any
10  * later version published by the Free Software Foundation.
11  *
12  * A copy of the license can be found at
13  * http://www.robotcub.org/icub/license/gpl.txt
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18  * Public License for more details
19 */
20 
21 // - include guard ----------------------------------------------------------------------------------------------------
22 
23 #ifndef _ETHBOARDS_H_
24 #define _ETHBOARDS_H_
25 
26 
27 #include "IethResource.h"
28 #include "EoProtocol.h"
29 #include <abstractEthResource.h>
30 
31 namespace eth {
32 
33  // -- class EthBoards
34  // -- it collects all the ETH boards managed by ethManager.
35  // -- each board surely has an EthResource object associated to it. and it may have one or more interfaces which use the
36  // -- services of EthResource to transmit or receive.
37  // -- it is responsibility of the object which owns EthBoards (it is ethManager) to protect the class EthBoards vs concurrent use.
38  // -- examples of concurrent use are: transmit or receive using an ethresource and ... attempting to create or destroy a resource.
39 
40  typedef struct
41  {
45 
46  class EthBoards
47  {
48 
49  public:
50 
51  enum { maxEthBoards = 32 };
52 
53  public:
54 
55  EthBoards();
56  ~EthBoards();
57 
58  size_t number_of_resources(void);
59  bool add(eth::AbstractEthResource* res);
60  eth::AbstractEthResource* get_resource(eOipv4addr_t ipv4);
61  bool rem(eth::AbstractEthResource* res);
62 
64  bool add(eth::AbstractEthResource* res, eth::IethResource* interface);
65  eth::IethResource* get_interface(eOipv4addr_t ipv4, eOprotID32_t id32);
66  eth::IethResource* get_interface(eOipv4addr_t ipv4, iethresType_t type);
68 
69 
70  // the name of the board
71  const string & name(eOipv4addr_t ipv4);
72 
73  // executes an action on all EthResource which have been added in the class.
74  bool execute(void (*action)(eth::AbstractEthResource* res, void* p), void* par);
75 
76  // executes an action on the ethResource having a specific ipv4.
77  bool execute(eOipv4addr_t ipv4, void (*action)(eth::AbstractEthResource* res, void* p), void* par);
78 
79 
80  private:
81 
82  // private types
83 
84  typedef struct
85  {
86  eOipv4addr_t ipv4;
87  string name;
88  uint8_t numberofinterfaces;
89  uint8_t boardnumber;
90  AbstractEthResource* resource;
92  } ethboardProperties_t;
93 
94 
95  private:
96 
97  // private variables
98 
99  static const string defaultnames[EthBoards::maxEthBoards];
100  static const string errorname[1];
101 
102  int sizeofLUT;
103  ethboardProperties_t LUT[EthBoards::maxEthBoards];
104 
105  private:
106 
107  // private functions
108  bool get_LUTindex(eOipv4addr_t ipv4, uint8_t &index);
109  };
110 
111 } // namespace eth
112 
113 
114 #endif // include-guard
115 
116 
117 // - end-of-file (leave a blank line after)----------------------------------------------------------------------------
118 
119 
120 
121 
122 
123 
124 
size_t number_of_interfaces(eth::AbstractEthResource *res)
Definition: ethBoards.cpp:91
const string & name(eOipv4addr_t ipv4)
Definition: ethBoards.cpp:403
eth::IethResource * get_interface(eOipv4addr_t ipv4, eOprotID32_t id32)
Definition: ethBoards.cpp:325
bool execute(void(*action)(eth::AbstractEthResource *res, void *p), void *par)
Definition: ethBoards.cpp:424
bool add(eth::AbstractEthResource *res)
Definition: ethBoards.cpp:118
bool rem(eth::AbstractEthResource *res)
Definition: ethBoards.cpp:200
size_t number_of_resources(void)
Definition: ethBoards.cpp:86
eth::AbstractEthResource * get_resource(eOipv4addr_t ipv4)
Definition: ethBoards.cpp:270
iethresType_t
Definition: IethResource.h:61
@ iethresType_numberof
Definition: IethResource.h:79
iethresType_t type
Definition: ethBoards.h:43
IethResource * interface
Definition: ethBoards.h:42