summaryrefslogtreecommitdiffstats
path: root/Src/ConnectionInfo.h
blob: 13016f5ff0d9d21d4764760ae258ee65464b8a79 (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
/*
 * 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 3 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 a helper class to store MOST connections
 */
/*----------------------------------------------------------*/
#ifndef CONNECTIONINFO_H
#define CONNECTIONINFO_H

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "SafeVector.h"
#include "Types.h"
#include "MacAddr.h"

/*!
 * \brief  This is a helper class for the CNetworkManagerHandler. It keeps track of the reported connections
 * and the instanced CMultiplexer classes.
 */
class CConnectionInfo
{
public:
    CConnectionInfo();
    CConnectionInfo( CMacAddr *macAddr, TChannelId channelId, uint8_t mostInstance, bool isTx );
    ~CConnectionInfo();

    ///The Ethernet MAC address of this connection.
    CMacAddr *macAddr;

    ///The device type as specified in XML file and configured in the config string (Group-Address)
    TDeviceId deviceType;

    ///The instance count of this device class. Starting at 0 for the first instance. Incremented with every occurrence.
    uint8_t deviceInstance;

    ///The channel ID as declared in the configuration XML file.
    TChannelId channelId;

    ///The MOST ring instance. Starting at 0 for the first MOST ring, on the first OS81110.
    TMostInstace mostInstance;

    ///The MOST data used by this channel.
    EPDataType_t dataType;

    ///The reserved MOST bandwidth in bytes for this channel.
    TBlockwidth reservedBandwidth;

    ///The amount of bytes reserved for this channel in Driver. If no buffers were allocated, this value is -1.
    int32_t bufferSize;

    ///In case this is a local connection, the path of the character device is stored in this variable. (e.g. /dev/mdev0).
    char deviceName[64];

    ///TRUE if this connections is a source. FALSE if this connection is a sink,
    bool isTX;

    //TRUE, if the input socket of this connection was successfully created.
    bool inSocketCreated;

    //TRUE, if the output socket of this connection was successfully created.
    bool outSocketCreated;

    //TRUE, if the input socket and the output socket of this connection were successfully connected.
    bool socketsConnected;

    ///The MOST connection label.
    uint32_t mostConnectionLabel;

    ///If this socket is a splitted / combined socket, this value holds the offset in byte. -1 if this is a normal socket.
    int16_t splittedOffset;

    ///If this socket is a splitted / combined socket, this value holds the maximum bandwidth of all splitted sockets in byte. -1 if this is a normal socket.
    int16_t splittedMaxBandwidth;
    
    ///This is USB specific. It describes how many sub-frames are concatenated into a single USB microframe.
    uint16_t packetsPerXact;
};

/*!
 * \brief  This is a storage class holding multiple CConnectionInfo in a container.
 *         It supports adding, removing, serializing and deserializing
 */
class CConnectionInfoContainer
{
private:
    CSafeVector<CConnectionInfo *> allInfos;
    bool Compare( CConnectionInfo *c, CConnectionInfo *t );
public:

    /*----------------------------------------------------------*/
    /*! \brief Default Constructor of CConnectionInfoContainer
     */
    /*----------------------------------------------------------*/
    CConnectionInfoContainer();

    /*----------------------------------------------------------*/
    /*! \brief Default Destructor of CConnectionInfoContainer
     */
    /*----------------------------------------------------------*/
    ~CConnectionInfoContainer();



    /*----------------------------------------------------------*/
    /*! \brief Gets the amount of entries stored in the whole database.
     *  \return The amount of entries.
     */
    /*----------------------------------------------------------*/
    uint32_t GetAllInfoAmount();



    /*----------------------------------------------------------*/
    /*! \brief Gets the information at the corresponding position.
     *  \param index - the position inside the database
     *  \note Use GetAllInfoAmount() to get the max index (n-1).
     *  \return The information if found, NULL if out of range
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetInfo( uint32_t index );


    /*----------------------------------------------------------*/
    /*! \brief Compares to container.
     *  \param containerToCompare - The container to compare.
     *  \return true, if both containers stores the same information. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool Compare( CConnectionInfoContainer *containerToCompare );



    /*----------------------------------------------------------*/
    /*! \brief Checks if the given information is already stored inside the database.
     *  \param checkInfo - the information object to be checked
     *  \return true, if the information is already stored inside the database. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool ExistsEntry( CConnectionInfo *checkInfo );


    /*----------------------------------------------------------*/
    /*! \brief Gets an info object with the given parameters
     *  \param macAddr - The MAC address of the device
     *  \param channelId - The channel identifier as used in the XML file.
     *  \param mostInstance - The MOST ring instance, starting 0 for the first MOST instance.
     *  \return The info object if found. NULL, otherwise.
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetInfo( CMacAddr *macAddr, TChannelId channelId, uint8_t mostInstance );


    /*----------------------------------------------------------*/
    /*! \brief Gets the amount of devices with the same 
     *  \param mostInstance - The MOST ring instance. Starting at 0 for the first MOST ring.
     *  \param deviceId - The device ID as declared in the configuration XML file.
     *  \return The Amount of devices found, with the given deviceId
     */
    /*----------------------------------------------------------*/
    uint8_t GetAmountOfDevices( TMostInstace mostInstance, TDeviceId deviceId );


    /*----------------------------------------------------------*/
    /*! \brief Helper function, which delivers a CConnectionInfo object to the given search parameters.
     *  \param macAddr - Searches for the given MAC address.
     *  \param channelId - Search for the given Channel address.
     *  \param mostInstance - Search on the given MOST ring instance.
     *  \param isTx - true, search for a transmission connection. false, search for a reception connection.
     *  \return An pointer to the matching CConnectionInfo object if found. NULL otherwise.
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetInfo( CMacAddr *macAddr, TChannelId channelId, uint8_t mostInstance, bool isTx );


    /*----------------------------------------------------------*/
    /*! \brief Stores the given information inside the database.
     *  \param info - The information to be stored.
     */
    /*----------------------------------------------------------*/
    void AddInfo( CConnectionInfo *info );


    /*----------------------------------------------------------*/
    /*! \brief Helper function, which deletes all stored informations retrieved so far.
     */
    /*----------------------------------------------------------*/
    void DestroyAllInfos();


    /*----------------------------------------------------------*/
    /*! \brief Helper function, which delete the information matching to the given parameters.
     *  \param macAddr - Searches for the given MAC address.
     *  \param channelId - Search for the given Channel address.
     *  \param mostInstance - Search on the given MOST ring instance.
     */
    /*----------------------------------------------------------*/
    void DestroyInfo( CMacAddr *macAddr, TChannelId channelId, uint8_t mostInstance );

    /*----------------------------------------------------------*/
    /*! \brief Helper function, which prints all available information to the console.
     *  \param hideTx - true, when transmission connections shall not be shown in the table.
     *  \param hideRx - true, when reception connections shall not be shown in the table.
     */
    /*----------------------------------------------------------*/
    void PrintTable( bool hideTx, bool hideRx );

    /*----------------------------------------------------------*/
    /*! \brief Serializes all connection informations to multi line string.
     *  \param pBuffer, buffer which then will hold the serialized string.
     *  \param bufferLen, the size of the given buffer.
     * \return The amount of bytes used from the given buffer.
     */
    /*----------------------------------------------------------*/
    uint32_t SerializeToString( char *pBuffer, uint32_t bufferLen );

    /*----------------------------------------------------------*/
    /*! \brief Deserializes all connection informations to multi line string.
     *  \param pBuffer, buffer which will read of the serialized string.
     * \return True, if the string could be used to deserialize all data. False, error occurred.
     * \note The given buffer will be manipulated by strtok operation!
     */
    /*----------------------------------------------------------*/
    bool DeserializeFromString( char *pBuffer );


    /*----------------------------------------------------------*/
    /*! \brief Returns the amount of entries, which contains a CDEV device name
     *  \return The amount of devices.
     */
    /*----------------------------------------------------------*/
    uint32_t GetAmountOfCDevs();


    /*----------------------------------------------------------*/
    /*! \brief Retrieves the information of the specific CDEV.
     *  \param cdevInst - The index of the CDEV device, starting with 0 for the first device.
     *  \note Use GetAmountOfCDevs() the get the maximum possible index (n-1).
     *  \return The information object, if found. NULL, otherwise.
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetConnectionInfoOfCdev( uint32_t cdevInst );



    /*----------------------------------------------------------*/
    /*! \brief Retrieves the information of the specific CDEV.
     *  \param cdevInst - The index of the CDEV device, starting with 0 for the first device.
     *  \param splittedIndex - Index of splitted socket entry, starting with 0 for the first splitted entry which has an offset greater than zero.
     *  \note Use GetAmountOfCDevs() the get the maximum possible index (n-1).
     *  \return The information object, if found. NULL, otherwise.
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetConnectionInfoOfCdev( uint32_t cdevInst, uint32_t splittedIndex );


    /*----------------------------------------------------------*/
    /*! \brief Returns the amount of entries, which acts as a sink channel.
     *  \return The amount of devices.
     */
    /*----------------------------------------------------------*/
    uint32_t GetAmountOfSinks();


    /*----------------------------------------------------------*/
    /*! \brief Retrieves the information of the specific sink.
     *  \param cdevInst - The index of the sink, starting with 0 for the sink.
     *  \note Use GetAmountOfSinks() the get the maximum possible index (n-1).
     *  \return The information object, if found. NULL, otherwise.
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetConnectionInfoOfSink( uint32_t sinkInst );



    /*----------------------------------------------------------*/
    /*! \brief Gets the information object by the given MAC address.
     *  \param mac - The MAC address of the searched device.
     *  \return The information object, if found. NULL, otherwise. 
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetConnectionInfoByMacAddress( const uint8_t *mac );


    /*----------------------------------------------------------*/
    /*! \brief Gets the opposite device information connected with given MAC address.
     *  \param mac - The MAC address of the device, which then the information of connected opposite device is returned.
     *  \return The information object, if found. NULL, otherwise.
     */
    /*----------------------------------------------------------*/
    CConnectionInfo *GetRemoteConnectionInfoByMacAddress( const uint8_t *mac );
};

#endif //CONNECTIONINFO_H