summaryrefslogtreecommitdiffstats
path: root/Src/Network/NodeDatabase.h
blob: 11817a18f76dffe42614bffa019b1d9af8867503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
 * Video On Demand Samples
 *
 * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You may also obtain this software under a propriety license from Microchip.
 * Please contact Microchip for further information.
 *
 */

/*----------------------------------------------------------*/
/*! \file
 *  \brief  This file contains the CNodeEntry and the CNodeConnectionEntry class.
 */
/*----------------------------------------------------------*/
#ifndef NODEDATABASE_H
#define NODEDATABASE_H

#include <stdint.h>
#include <stdbool.h>
#include "SafeVector.h"
#include "VodXml.h"
#include "MacAddr.h"

class CNodeEntry;
class CNodeConnectionEntry;

/*----------------------------------------------------------*/
/*! \brief Enumeration describing the state of a Node socket
 */
/*----------------------------------------------------------*/
typedef enum NodeConnectionState_tag
{
    NodeConnection_NotUsed,
    NodeConnection_Pending_Up,
    NodeConnection_Pending_Down,
    NodeConnection_Used
} NodeConnectionState_t;

/*----------------------------------------------------------*/
/*! \brief Storage class holding informations of a specific MOST connection (Ports)
 */
/*----------------------------------------------------------*/
class CNodeConnectionEntry
{
public:
    /*----------------------------------------------------------*/
    /*! \brief Pointer to the device, which this connection belongs to.
     */
    /*----------------------------------------------------------*/
    CNodeEntry *parentNode;


    /*----------------------------------------------------------*/
    /*! \brief Pointer to the XML generated configuration, holding the user specific part of this connection.
     */
    /*----------------------------------------------------------*/
    CChannelConfiguration *channelConfig;


    /*----------------------------------------------------------*/
    /*! \brief Identifier determinating the connection based on the XML configuration.
     */
    /*----------------------------------------------------------*/
    uint32_t channelId;


    /*----------------------------------------------------------*/
    /*! \brief In-Handle provided from INIC when the In-Socket was created
     */
    /*----------------------------------------------------------*/
    uint32_t inHandle;


    /*----------------------------------------------------------*/
    /*! \brief Out-Handle provided from INIC when the Out-Socket was created
     */
    /*----------------------------------------------------------*/
    uint32_t outHandle;


    /*----------------------------------------------------------*/
    /*! \brief Connection-Handle provided from INIC when the In- and the Out-Socket were connected.
     */
    /*----------------------------------------------------------*/
    uint32_t connectHandle;


    /*----------------------------------------------------------*/
    /*! \brief If this connection uses combiner or splitter, this handle points to the source / sink of the splitter / combiner.
    *  \note The idea of storing this handle, is only for cleanup purposes.
    *  \warning Do not use this handle for creating connections.
    */
    /*----------------------------------------------------------*/
    uint32_t splittedSourceHandle;


    /*----------------------------------------------------------*/
    /*! \brief Connection-Handle provided from INIC when the MOST-Socket was created.
     */
    /*----------------------------------------------------------*/
    uint32_t mostConnectionLabel;


    /*----------------------------------------------------------*/
    /*! \brief The state of the In-Socket
     */
    /*----------------------------------------------------------*/
    NodeConnectionState_t inSocketState;


    /*----------------------------------------------------------*/
    /*! \brief The state of the Out-Socket
     */
    /*----------------------------------------------------------*/
    NodeConnectionState_t outSocketState;


    /*----------------------------------------------------------*/
    /*! \brief The connection state between In-Socket and Out-Socket
     */
    /*----------------------------------------------------------*/
    NodeConnectionState_t connectedSocketState;

    /*----------------------------------------------------------*/
    /*! \brief The used buffer size for this connection.
     *  \note bufferSize is -1 in case, there were no buffers configured.
     */
    /*----------------------------------------------------------*/
    int32_t bufferSize;

    /*----------------------------------------------------------*/
    /*! \brief The Linux character device name, when this connection belongs to a local connection. May be strlen of 0.
     */
    /*----------------------------------------------------------*/
    char deviceName[64];


    /*----------------------------------------------------------*/
    /*! \brief Constructor of CNodeConnectionEntry.
     *  \param Pointer to the device this connection belongs to.
     */
    /*----------------------------------------------------------*/
    CNodeConnectionEntry( CNodeEntry *parentNode );


    /*----------------------------------------------------------*/
    /*! \brief Destructor of CNodeConnectionEntry.
     */
    /*----------------------------------------------------------*/
    ~CNodeConnectionEntry();
};

/*----------------------------------------------------------*/
/*! \brief Storage class holding information of a specific MOST device
 */
/*----------------------------------------------------------*/
class CNodeEntry
{
private:
    static CSafeVector<CNodeEntry *> allNodes;
    CSafeVector<CNodeConnectionEntry *> allConnections;

    CNodeEntry();
    static const char *GetConnectionStateString( NodeConnectionState_t state );
public:
    ~CNodeEntry();
    
    /*----------------------------------------------------------*/
    /*! \brief MOST instance. 0 for the first instance. If the server has multiple MOST devices, this value will be increased.
     */
    /*----------------------------------------------------------*/
    uint8_t deviceInstance;


    /*----------------------------------------------------------*/
    /*! \brief The unique address of the MOST device.
     */
    /*----------------------------------------------------------*/
    uint16_t nodeAddress;


    /*----------------------------------------------------------*/
    /*! \brief The type of the device (derived from the group address), as described in the XML configuration.
     */
    /*----------------------------------------------------------*/
    uint16_t deviceType;


    /*----------------------------------------------------------*/
    /*! \brief The unique MAC address of the device.
     */
    /*----------------------------------------------------------*/
    CMacAddr *macAddress;


    /*----------------------------------------------------------*/
    /*! \brief Determines if the TSI port is opened.
     *  \return true, if the port is opened. false
     */
    /*----------------------------------------------------------*/
    bool isTsiPortOpened;
    
    /*----------------------------------------------------------*/
    /*! \brief Determines if the MLB port is opened.
     *  \return true, if the port is opened. false
     */
    /*----------------------------------------------------------*/
    bool isMlbPortOpened;


    /*----------------------------------------------------------*/
    /*! \brief Determines if the USB port is opened.
     *  \return true, if the port is opened. false
     */
    /*----------------------------------------------------------*/
    bool isUsbPortOpened;


    /*----------------------------------------------------------*/
    /*! \brief Determines if the USB port A is opened.
     *  \return true, if the port is opened. false
     */
    /*----------------------------------------------------------*/
    bool isI2SPortOpened;



    /*----------------------------------------------------------*/
    /*! \brief Gets the amount of available MOST devices.
     *  \return The number of MOST devices.
     */
    /*----------------------------------------------------------*/
    static uint16_t GetAmountOfNodeEntries();


    /*----------------------------------------------------------*/
    /*! \brief Gets an instance of CNodeEntry by the given instance index
     *  \param index - starting at 0 for the first instance. "GetAmountOfNodeEntries() - 1" for the last instance.
     *  \return The requested instance, when successful. Otherwise NULL pointer.
     */
    /*----------------------------------------------------------*/
    static CNodeEntry *GetNodeEntry( uint16_t index );


    /*----------------------------------------------------------*/
    /*! \brief Gets an instance of CNodeEntry by the given MOST instance and the unique node address of the device.
     *  \param deviceInstance - MOST instance id, starting at 0 for the first MOST ring. When the server have multiple MOST devices,
     *                          This value may be above 0.
     *  \param nodeAddress - The MOST node address of the specific device (0x100 e.g.).
     *  \return The requested instance, when successful. Otherwise NULL pointer.
     */
    /*----------------------------------------------------------*/
    static CNodeEntry *GetNodeEntry( uint8_t deviceInstance, uint16_t nodeAddress );



    /*----------------------------------------------------------*/
    /*! \brief Gets an instance of CNodeEntry by the given unique MAC address of the device.
     *  \param macAddress - Unique MAC address of the device
     *  \return The requested instance, when successful. Otherwise NULL pointer.
     */
    /*----------------------------------------------------------*/
    static CNodeEntry *GetNodeEntry( CMacAddr *macAddress );

    /*----------------------------------------------------------*/
    /*! \brief Gets an instance of CNodeEntry by the given device type and terminal instance
     *  \param deviceInstance - MOST instance id, starting at 0 for the first MOST ring. When the server have multiple MOST devices,
     *                          This value may be above 0.
     *  \param deviceType - The type of the device (derived from the group address), as described in the XML configuration.
     *  \param terminalInstance - The instance of the terminal, starting at 0 for the first terminal.
     *
     *  \return The requested instance, when successful. Otherwise NULL pointer.
     */
    /*----------------------------------------------------------*/
    static CNodeEntry *GetNodeEntry( uint8_t deviceInstance, uint32_t deviceType, uint32_t terminalInstance );


    /*----------------------------------------------------------*/
    /*! \brief Gets the terminal instance number for the given device type.
     *  \param deviceInstance - MOST instance id, starting at 0 for the first MOST ring. When the server have multiple MOST devices,
     *                          This value may be above 0.
     *  \param nodeAddress - The MOST node address of the specific device (0x100 e.g.).
     *  \param deviceType - The type of the device (derived from the group address), as described in the XML configuration.
     *
     *  \return The requested instance, when successful. Otherwise NULL pointer.
     */
    /*----------------------------------------------------------*/
    static uint32_t GetTerminalInstance( uint8_t deviceInstance, uint16_t nodeAddress, uint32_t deviceType );

    /*----------------------------------------------------------*/
    /*! \brief Deleting all informations of any device.
     */
    /*----------------------------------------------------------*/
    static void DeleteAllNodeEntries();



    /*----------------------------------------------------------*/
    /*! \brief Deleting all informations of a specific device.
     *  \param index - starting at 0 for the first instance. "GetAmountOfNodeEntries() - 1" for the last instance.
     */
    /*----------------------------------------------------------*/
    static void DeleteNodeEntry( uint16_t index );



    /*----------------------------------------------------------*/
    /*! \brief Dumps out all information of all devices to stdout
     */
    /*----------------------------------------------------------*/
    static void PrintAllInformations();



    /*----------------------------------------------------------*/
    /*! \brief Gets the amount of connection for the current instance of MOST device.
     *  \return The amount of connections.
     */
    /*----------------------------------------------------------*/
    uint16_t GetAmountOfConnections();



    /*----------------------------------------------------------*/
    /*! \brief Gets an instance of CNodeConnectionEntry by the given instance index.
     *  \param index - starting at 0 for the first instance. "GetAmountOfConnections() - 1" for the last instance.
     *  \return The requested instance, when successful. Otherwise NULL pointer.
     */
    /*----------------------------------------------------------*/
    CNodeConnectionEntry *GetConnectionByIndex( uint16_t index );



    /*----------------------------------------------------------*/
    /*! \brief Gets an instance of CNodeConnectionEntry by the given channel identifier.
     *  \param channelId - The channel identifier as specified in the XML file.
     *  \param createNewIfUnknown - TRUE, if this function shall create a new entry, when there is no existing object.
     *  \return The requested instance, when successful. Otherwise NULL pointer.
     */
    /*----------------------------------------------------------*/
    CNodeConnectionEntry *GetConnectionByChannelId( uint32_t channelId, bool createNewIfUnknown );



    /*----------------------------------------------------------*/
    /*! \brief Retrieves a conflicting connection by the given parameters.#
     *        This method checks if the in and out configurations are unique for one device.
     *  \param channelId - The channel identifier as specified in the XML file.
     *  \param opposite - The other side to be connected to.
     *  \return The instance, which causes an conflict. If there is no conflict, a NULL pointer will be returned.
     */
    /*----------------------------------------------------------*/
    CNodeConnectionEntry *GetConflictingConnection( uint32_t channelId, CNodeEntry *opposite );



    /*----------------------------------------------------------*/
    /*! \brief Delets all informations of the given channel identifier.
     *  \param channelId - The channel identifier as specified in the XML file.
     */
    /*----------------------------------------------------------*/
    void DeleteConnection( uint32_t channelId );
};

#endif //NODEDATABASE_H