iCub-main
Loading...
Searching...
No Matches
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
31namespace 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
45
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);
60 eth::AbstractEthResource* get_resource(eOipv4addr_t ipv4);
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 ethboardProperties_t
85 {
86 eOipv4addr_t ipv4 {0};
87 string name {""};
88 uint8_t numberofinterfaces {0};
89 uint8_t boardnumber {0};
90 AbstractEthResource* resource {nullptr};
91 IethResource* interfaces[iethresType_numberof] {nullptr};
92
93 void clear()
94 {
95 ipv4 = 0;
96 name = "";
97 numberofinterfaces = 0;
98 boardnumber = 0;
99 resource = nullptr;
100 for (auto& itf : interfaces) {itf = nullptr;}
101 };
102 };
103
104
105 private:
106
107 // private variables
108
109 inline static const string defaultnames[EthBoards::maxEthBoards] = {"noname-in-xml-board.1", "noname-in-xml-board.2", "noname-in-xml-board.3", "noname-in-xml-board.4",
110 "noname-in-xml-board.5", "noname-in-xml-board.6", "noname-in-xml-board.7", "noname-in-xml-board.8",
111 "noname-in-xml-board.9", "noname-in-xml-board.10", "noname-in-xml-board.11", "noname-in-xml-board.12",
112 "noname-in-xml-board.13", "noname-in-xml-board.14", "noname-in-xml-board.15", "noname-in-xml-board.16",
113 "noname-in-xml-board.17", "noname-in-xml-board.18", "noname-in-xml-board.19", "noname-in-xml-board.20",
114 "noname-in-xml-board.21", "noname-in-xml-board.22", "noname-in-xml-board.23", "noname-in-xml-board.24",
115 "noname-in-xml-board.25", "noname-in-xml-board.26", "noname-in-xml-board.27", "noname-in-xml-board.28",
116 "noname-in-xml-board.29", "noname-in-xml-board.30", "noname-in-xml-board.31", "noname-in-xml-board.32"};
117
118 inline static const string errorname[1] = {"wrong-unknown-board"};
119
120 int sizeofLUT {0};
121 ethboardProperties_t LUT[EthBoards::maxEthBoards] {};
122
123 private:
124
125 // private functions
126 bool get_LUTindex(eOipv4addr_t ipv4, uint8_t &index);
127 };
128
129} // namespace eth
130
131
132#endif // include-guard
133
134
135// - end-of-file (leave a blank line after)----------------------------------------------------------------------------
136
137
138
139
140
141
142
size_t number_of_interfaces(eth::AbstractEthResource *res)
Definition ethBoards.cpp:91
const string & name(eOipv4addr_t ipv4)
eth::IethResource * get_interface(eOipv4addr_t ipv4, eOprotID32_t id32)
bool execute(void(*action)(eth::AbstractEthResource *res, void *p), void *par)
bool add(eth::AbstractEthResource *res)
bool rem(eth::AbstractEthResource *res)
size_t number_of_resources(void)
Definition ethBoards.cpp:86
eth::AbstractEthResource * get_resource(eOipv4addr_t ipv4)
iethresType_t
@ iethresType_numberof
iethresType_t type
Definition ethBoards.h:43
IethResource * interface
Definition ethBoards.h:42