Gocator API
 All Classes Files Functions Variables Typedefs Macros Modules Pages
GoAcceleratorMgr.h
Go to the documentation of this file.
1 /**
2  * @file GoAcceleratorMgr.h
3  * @brief Declares the GoAcceleratorMgr class public interfaces.
4  *
5  * @internal
6  * Copyright (C) 2018 by LMI Technologies Inc.
7  * Licensed under the MIT License.
8  * Redistributed files must retain the above copyright notice.
9  *
10  * The SDK Accelerator Manager object allows SDK clients to accelerate more than
11  * one sensor within a single platform. SDK client can build its own accelerator
12  * application using the SDK Accelerator Manager. The SDK Accelerator Manager
13  * provides a mechanism for the SDK client to receive event updates from the
14  * Accelerator Manager.
15  *
16  * A brief description of how to use the SDK Accelerator Manager follows.
17  * Note the description omits error checking and parameters to focus on the
18  * call sequences.
19  *
20  * A. Initializing the Accelerator Manager.
21  * Here is sample code showing how to initialize the Accelerator Manager and how
22  * to start it running.
23  *
24  * kStatus kCall MyApp_UpdateHandler(MyAppClass MyApp, kPointer caller, GoAcceleratorMgrAccelUpdate* update)
25  * {
26  * printf(
27  * "Sensor %u event - %d\n",
28  * update->sensorId,
29  * update->accelEvent);
30  * }
31  *
32  * // Construct the Accelerator Manager.
33  * GoAcceleratorMgr_Construct();
34  *
35  * // Set up the update handler so the SDK client can receive events
36  * // from the Accelerator Manager. This step is optional.
37  * GoAcceleratorMgr_SetAccelUpdateHandler(MyApp_UpdateHandler, MyApp);
38  *
39  * // Must give the Accelerator Manager the system object before starting it.
40  * GoSystem system = kNULL;
41  *
42  * GoSystem_Construct(&system, ...);
43  * GoAcceleratorMgr_SetSystem(system);
44  *
45  * // Now start the Accelerator Manager.
46  * GoAcceleratorMgr_Start();
47  *
48  * // Set the range of port numbers any time as long as no sensor is configured
49  * // for acceleration. This is an optional step to change the default
50  * // range. See the section on changing the port range for more details.
51  * GoAcceleratorMgr_SetPortRange(startPort, endPort);
52  *
53  * B. Accelerating a Sensor.
54  *
55  * // Set up the parameters in a GoAcceleratorMgrSensorParam structure and
56  * // call the accelerate interface.
57  * GoAcceleratorMgrSensorParam param;
58  * k32u sensorId = 12345;
59  *
60  * if (useAutomaticAllocation)
61  * {
62  * param.ports.controlPort = 0;
63  * param.ports.upgradePort = 0;
64  * param.ports.healthPort = 0;
65  * param.ports.privateDataPort = 0;
66  * param.ports.publicDataPort = 0;
67  * param.ports.webPort = 0;
68  * }
69  * else
70  * {
71  * // Manually specify ports that the SDK client is allowed to set up
72  * // TCP/IP connections through a network to the accelerated sensor.
73  * // This example assumes ports 4000 and up are available for use.
74  * param.ports.controlPort = 4000;
75  * param.ports.upgradePort = 4001;
76  * param.ports.healthPort = 4002;
77  * param.ports.privateDataPort = 4003;
78  * param.ports.publicDataPort = 4004;
79  * param.ports.webPort = 4005;
80  * }
81  * // Assume okay to use any IPv4 address (ie. 0.0.0.0).
82  * // Otherwise choose one of the accelerator platform's network interface
83  * // IP address.
84  * param.platforIpAddress = kIpAddress_AnyV4();
85  *
86  * GoAcceleratorMgr_Accelerate(sensorId, &param);
87  *
88  * C. Decelerating (Unaccelerating) a Sensor.
89  *
90  * k32u sensorId = 12345;
91  *
92  * GoAcceleratorMgr_Decelerate(sensorId);
93  *
94  * D. Get the List of Sensors Managed by the Accelerator Manager.
95  *
96  * kArrayList sensorList = kNULL;
97  *
98  * kArrayList_Construct(&sensorList, kTypeOf(GoAcceleratorMgrSensorInfo), 0, kObject_Alloc(myApp));
99  * GoAcceleratorMgr_ListSensors(sensorList);
100  *
101  * E. Get the port range limits and change the port range.
102  *
103  * k16u startLimit;
104  * k16u endLimit;
105  * k16u minNumPorts;
106  * k16u userStartPort;
107  * k16u userEndPort;
108  *
109  * // Some code initializes userStartPort and userEndPort.
110  * userStartPort = 4000;
111  * userEndPort = 4010;
112  *
113  * // Get the min and max values of the port range and the minimum number
114  * // of ports within the port range to help with user configuration
115  * // validation.
116  * GoAcceleratorMgr_GetPortRangeLimits(startLimit, endLimit, minNumPorts);
117  *
118  * if ((userStartPort >= startLimit) && (userEndPort <= endLimit) &&
119  * ((userEndPort - userStartPort + 1) >= minNumPorts)
120  * {
121  * GoAcceleratorMgr_SetPortRange(userStartPort, userEndPort);
122  * }
123  * else
124  * {
125  * printf("Invalid user port range\n");
126  * }
127  *
128  * F. Get current port range.
129  *
130  * k16u startPort;
131  * k16u endPort;
132  *
133  * GoAcceleratorMgr_GetPortRange(&startPort, &endPort);
134  *
135  * G. Get the number of sensors managed by the Accelerator Manager.
136  *
137  * if (GoAcceleratorMgr_AccelSensorCount() > 0)
138  * {
139  * printf("Sensors configured for acceleration\n");
140  * }
141  * else
142  * {
143  * printf("No sensors configured for acceleration\n");
144  * }
145  *
146  */
147 #ifndef GO_ACCELERATOR_MGR_H
148 #define GO_ACCELERATOR_MGR_H
149 
150 #include <GoSdk/GoSdk.h>
151 // Don't know why need to explicitly include GoSystem header file again
152 // here when GoSdk.h already includes it. If this is not done, compile fails
153 // to find GoSystem declaration!?
154 #include <GoSdk/GoSystem.h>
156 
157 /**
158  * @class GoAcceleratorMgr
159  * @extends kObject
160  * @ingroup GoSdk
161  * @brief Represents an GoAcceleratorMgr instance.
162  */
163 typedef kObject GoAcceleratorMgr;
164 
165 /**
166 * @class GoAcceleratorMgr
167 * @extends kValue
168 * @ingroup GoSdk
169 * @brief Represents an GoAcceleratorMgr events passed into the acceleration
170 * update callback handler bound in by SDK client.
171 * Meaning of the events are:
172 * - GO_ACCELERATOR_MGR_EVENT_ACCELERATING - Sensor acceleration is in progress.
173 * - GO_ACCELERATOR_MGR_EVENT_ACCELERATED: - Sensor is accelerated successfully.
174 * - GO_ACCELERATOR_MGR_EVENT_DECELERATING: - Sensor deceleration is in progress.
175 * - GO_ACCELERATOR_MGR_EVENT_DECELERATED: - Sensor is no longer accelerated.
176 * - GO_ACCELERATOR_MGR_EVENT_STOPPED: - Sensor acceleration stopped or failed to start.
177 * - GO_ACCELERATOR_MGR_EVENT_DISCONNECTED: - Accelerated sensor is disconnected from network.
178 * - GO_ACCELERATOR_MGR_EVENT_PROCESS_STOPPED: - Special case for the STOPPED event to indicate acceleration
179 * was in progress but terminated unexpectedly.
180 * This stop reason differs from other stop reasons,
181 * such as firmware mismatch etc.
182 */
183 typedef enum GoAcceleratorMgrAccelEvents
184 {
185  GO_ACCELERATOR_MGR_EVENT_ACCELERATING = 0,
186  GO_ACCELERATOR_MGR_EVENT_ACCELERATED,
187  GO_ACCELERATOR_MGR_EVENT_DECELERATING,
188  GO_ACCELERATOR_MGR_EVENT_DECELERATED,
189  GO_ACCELERATOR_MGR_EVENT_STOPPED,
190  GO_ACCELERATOR_MGR_EVENT_DISCONNECTED,
191  GO_ACCELERATOR_MGR_EVENT_PROCESS_STOPPED
192 } GoAcceleratorMgrAccelEvents;
193 
194 /**
195 * @struct GoAcceleratorMgrAccelUpdate
196 * @extends kValue
197 * @ingroup GoSdk
198 * @brief Structure to hold data for the acceleration update handler.
199 */
201 {
202  k32u sensorId;
203  GoAcceleratorMgrAccelEvents accelEvent;
205 
206 /**
207 * @struct GoAcceleratorMgrSensorParam
208 * @extends kValue
209 * @ingroup GoSdk
210 * @brief Structure to hold user configuration parameters from SDK client
211 * for a sensor that is to be accelerated.
212 */
214 {
215  GoAccelSensorPortAllocPorts ports;
216  kIpAddress platformIpAddress; // Bind an accelerated sensor to this accelerator host interface IP address.
218 
219 /**
220 * @struct GoAcceleratorMgrSensorInfo
221 * @extends kValue
222 * @ingroup GoSdk
223 * @brief Structure to return accelerated sensor information to SDK client.
224 * The param field contains information received from the SDK client, except if
225 * SDK client requested automatic port selection. In this case, the ports in the
226 * param field are the ports selected by the SDK for the SDK client.
227 */
229 {
230  k32u sensorId;
231  GoSensorAccelStatus status;
234 
235 /**
236 * Constructs the accelerator manager object
237 *
238 * @public @memberof GoAcceleratorMgr
239  * @version Introduced in firmware 5.2.18.3
240 * @param manager Address of uninitialized manager object.
241 * @param allocator Allocator object (kNULL for fallback allocator).
242 * @return Operation status.
243 */
244 GoFx(kStatus) GoAcceleratorMgr_Construct(GoAcceleratorMgr* manager, kAlloc allocator);
245 
246 /**
247 * Assigns the SDK GoSystem object to the accelerator manager object. This must be
248 * done before starting the accelerator manager.
249 *
250 * @public @memberof GoAcceleratorMgr
251  * @version Introduced in firmware 5.2.18.3
252 * @param manager GoAcceleratorMgr object.
253 * @param system Instance of GoSystem
254 * @return Operation status.
255 */
257 
258 /**
259 * Starts the accelerator manager object after it has been configured.
260 *
261 * @public @memberof GoAcceleratorMgr
262  * @version Introduced in firmware 5.2.18.3
263 * @param manager GoAcceleratorMgr object.
264 * @return Operation status.
265 */
267 
268 /**
269 * Accelerate the specified sensor with the given set of parameters.
270 * The parameter structure contains the accelerator host IP address to
271 * associate with the accelerated sensor, and the ports the accelerated
272 * sensor should use to communicate with the SDK client.
273 * If the SDK client wishes to have the GoAcceleratorMgr dynamically/automatically
274 * allocate the port numbers from within the configured port range,
275 * the SDK client must set all the ports in the parameter structure to
276 * zero (0).
277 * Any non-zero value for a port in the port parameter list is treated
278 * as if the client is providing ALL the port numbers to use. If the
279 * client provided port numbers are valid, then they will be used by
280 * the accelerated sensor.
281 
282 *
283 * @public @memberof GoAcceleratorMgr
284  * @version Introduced in firmware 5.2.18.3
285 * @param manager GoAcceleratorMgr object.
286 * @param sensorId Identifier of the sensor.
287 * @param param Pointer to parameter structure for accelerating the sensor.
288 * @return Operation status.
289 */
291 
292 /**
293 * Decelerate (unaccelerate) a sensor.
294 *
295 * @public @memberof GoAcceleratorMgr
296  * @version Introduced in firmware 5.2.18.3
297 * @param manager GoAcceleratorMgr object.
298 * @param sensorId Identifier of the sensor.
299 * @return Operation status.
300 */
302 
303 /**
304 * Get a list of accelerated sensors. The list is returned in an array list
305 * of GoAcceleratorMgrSensorInfo. Caller must construct the kArrayList and
306 * pass the it as an argument to this API. The API will fill this list.
307 *
308 * Each entry includes the set of ports used by the accelerated sensor.
309 * If the client had specified the ports to use, then the list entry's
310 * set of ports should be the same as the client specified ports.
311 * If the client had specified the Accelerator Manager dynamically
312 * allocate ports from the configured port range, then the list entry's
313 * set of ports contains the ports allocated to the sensor.
314 * The current acceleration status of the sensor is returned in the
315 * list entry for each sensor.
316 *
317 * @public @memberof GoAcceleratorMgr
318  * @version Introduced in firmware 5.2.18.3
319 * @param manager GoAcceleratorMgr object.
320 * @param sensorList Array list of GoAcceleratorMgrSensorInfo for each
321 * accelerated sensor.
322 * @return Operation status.
323 */
325 
326 /**
327 * Set up the update handler so that the SDK client can receive events
328 * from the Accelerator Manager about a sensor. This step is optional. If update handler
329 * is not bound in, then client will not receive any event notifications.
330 * Update handler is called with a pointer to GoAcceleratorMgrAccelUpdate which
331 * contains event information about a sensor.
332 * The update handler does not free the memory for the GoAcceleratorMgrAccelUpdate
333 * structure.
334 *
335 * @public @memberof GoAcceleratorMgr
336  * @version Introduced in firmware 5.2.18.3
337 * @param manager GoAcceleratorMgr object.
338 * @param function Update callback handler function.
339 * @param context SDK client context for the callback handler.
340 * It is a pointer to GoAcceleratorMgrAccelUpdate.
341 * @return Operation status.
342 */
343 GoFx(kStatus) GoAcceleratorMgr_SetAccelUpdateHandler(GoAcceleratorMgr manager, kCallbackFx function, kPointer context);
344 
345 /**
346 * Set the range of port numbers used to communicate with the accelerated
347 * sensors. Changes to the port range is allowed only if no sensor is
348 * configured for acceleration.
349 * Changing the port range is optional if the client application can use
350 * the default port range.
351 * The port numbers range must be within the port range limits (see
352 * GoAcceleratorMgr_GetPortRangeLimits()).
353 * Configure the port range if your network places limits on what ports are
354 * permitted for communication use or if some range of ports is known to be used
355 * by another application.
356 *
357 * @public @memberof GoAcceleratorMgr
358  * @version Introduced in firmware 5.2.18.3
359 * @param manager GoAcceleratorMgr object.
360 * @param startPort Starting port number in the range
361 * @param endPort Last port number in the range.
362 * @return Operation status.
363 */
364 GoFx(kStatus) GoAcceleratorMgr_SetPortRange(GoAcceleratorMgr manager, k16u startPort, k16u endPort);
365 
366 /**
367 * Get the range of port numbers to assign to accelerated sensors.
368 * The ports within the port range are used by the Accelerator Manager
369 * to allocate ports for the accelerated sensors.
370 *
371 * @public @memberof GoAcceleratorMgr
372  * @version Introduced in firmware 5.2.18.3
373 * @param manager GoAcceleratorMgr object.
374 * @param startPort Returns the starting port number in the range
375 * @param endPort Returns the last port number in the range.
376 * @return Operation status.
377 */
378 GoFx(kStatus) GoAcceleratorMgr_GetPortRange(GoAcceleratorMgr manager, k16u* startPort, k16u* endPort);
379 
380 /**
381 * Get the min and max values of the port range and the minimum number
382 * of ports within the port range. These limits are the default port range.
383 * The upper limit is set to just below the start of the ephemeral port
384 * range that are available for use by any network application.
385 *
386 * @public @memberof GoAcceleratorMgr
387  * @version Introduced in firmware 5.2.18.3
388 * @param manager GoAcceleratorMgr object.
389 * @param startLimit Returns the limit for the starting port number in the range
390 * @param endLimit Returns the limit for the last port number in the range.
391 * @param minNumPorts Returns the minimum number of ports that the range must support.
392 * @return Operation status.
393 */
394 GoFx(kStatus) GoAcceleratorMgr_GetPortRangeLimits(GoAcceleratorMgr manager, k16u* startLimit, k16u* endLimit, k16u* minNumPorts);
395 
396 /**
397 * Get the number of sensors which the accelerator manager has been configured
398 * to accelerate. The count includes sensors whose acceleration may have failed
399 * for whatever reason.
400 * This is a convenient interface to find out how many sensors have
401 * been configured without having to get the list of sensors. This count
402 * should match the number of successful calls to GoAcceleratorMgr_Accelerate()
403 * less successful calls to GoAcceleratorMgr_Decelerate().
404 *
405 * @public @memberof GoAcceleratorMgr
406  * @version Introduced in firmware 5.2.18.3
407 * @param manager GoAcceleratorMgr object.
408 * @return Number of sensors configured for acceleration.
409 */
411 
412 #include <GoSdk/GoAcceleratorMgr.x.h>
413 
414 #endif // GO_ACCELERATOR_MGR_H
kStatus GoAcceleratorMgr_SetAccelUpdateHandler(GoAcceleratorMgr manager, kCallbackFx function, kPointer context)
Set up the update handler so that the SDK client can receive events from the Accelerator Manager abou...
Represents a system of Gocator devices.
kStatus GoAcceleratorMgr_SetSystem(GoAcceleratorMgr manager, GoSystem system)
Assigns the SDK GoSystem object to the accelerator manager object.
Includes all Gocator SDK headers.
kStatus GoAcceleratorMgr_Construct(GoAcceleratorMgr *manager, kAlloc allocator)
Constructs the accelerator manager object.
kStatus GoAcceleratorMgr_Accelerate(GoAcceleratorMgr manager, k32u sensorId, GoAcceleratorMgrSensorParam *param)
Accelerate the specified sensor with the given set of parameters.
Declares the GoAccelSensorPortAlloc class.
kSize GoAcceleratorMgr_AccelSensorCount(GoAcceleratorMgr manager)
Get the number of sensors which the accelerator manager has been configured to accelerate.
kStatus GoAcceleratorMgr_ListSensors(GoAcceleratorMgr manager, kArrayList sensorList)
Get a list of accelerated sensors.
Structure to hold user configuration parameters from SDK client for a sensor that is to be accelerate...
Definition: GoAcceleratorMgr.h:213
kStatus GoAcceleratorMgr_Decelerate(GoAcceleratorMgr manager, k32u sensorId)
Decelerate (unaccelerate) a sensor.
Represents the acceleration status of a sensor that is available or being accelerated by the local ho...
kStatus GoAcceleratorMgr_GetPortRangeLimits(GoAcceleratorMgr manager, k16u *startLimit, k16u *endLimit, k16u *minNumPorts)
Get the min and max values of the port range and the minimum number of ports within the port range...
kStatus GoAcceleratorMgr_SetPortRange(GoAcceleratorMgr manager, k16u startPort, k16u endPort)
Set the range of port numbers used to communicate with the accelerated sensors.
Structure to return accelerated sensor information to SDK client. The param field contains informatio...
Definition: GoAcceleratorMgr.h:228
Structure to hold data for the acceleration update handler.
Definition: GoAcceleratorMgr.h:200
Declares the GoSystem class.
kStatus GoAcceleratorMgr_Start(GoAcceleratorMgr manager)
Starts the accelerator manager object after it has been configured.
kStatus GoAcceleratorMgr_GetPortRange(GoAcceleratorMgr manager, k16u *startPort, k16u *endPort)
Get the range of port numbers to assign to accelerated sensors.
Represents an GoAcceleratorMgr instance.