Mistake on this page? Email us
pt_api.h
Go to the documentation of this file.
1 /*
2  * ----------------------------------------------------------------------------
3  * Copyright 2018 ARM Ltd.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ----------------------------------------------------------------------------
19  */
20 
21 #ifndef PT_API_VERSION
22 #define PT_API_VERSION 1
23 #endif
24 #if PT_API_VERSION != 1
25 #error "Including mixed versions of Protocol API"
26 #endif
27 
28 #ifndef PT_API_H_
29 #define PT_API_H_
30 
31 #ifdef __GNUC__
32 #define DEPRECATED(func) func __attribute__((deprecated))
33 #else
34 #pragma message("WARNING: Implement DEPRECATED macro, it is missing.")
35 #define DEPRECATED(func) func
36 #endif
37 
38 #include "ns_list.h"
39 
40 #include "common/constants.h"
42 #include "edge-rpc/rpc.h"
43 
165 typedef struct pt_resource pt_resource_t;
166 typedef struct pt_resource pt_resource_opaque_t;
168 typedef struct pt_object pt_object_t;
169 typedef struct pt_device pt_device_t;
170 
196 DEPRECATED(
197  typedef void (*pt_resource_callback)(const pt_resource_t *resource,
198  const uint8_t *value,
199  const uint32_t size,
200  void *userdata));
201 
209 DEPRECATED(typedef void (*pt_connection_ready_cb)(struct connection *connection, void *userdata));
210 
218 DEPRECATED(typedef void (*pt_disconnected_cb)(struct connection *connection, void *userdata));
219 
227 DEPRECATED(typedef void (*pt_connection_shutdown_cb)(struct connection **connection, void *userdata));
228 
251 DEPRECATED(
252  typedef int (*pt_received_write_handler)(struct connection *connection,
253  const char *device_id, const uint16_t object_id,
254  const uint16_t instance_id,
255  const uint16_t resource_id,
256  const unsigned int operation,
257  const uint8_t *value, const uint32_t value_size,
258  void *userdata));
259 
260 typedef enum {
261  NONE,
262  QUEUE
263 } queuemode_t;
264 
265 typedef enum {
266  PT_STATUS_SUCCESS = 0,
267  PT_STATUS_ERROR,
268  PT_STATUS_ITEM_EXISTS,
269  PT_STATUS_INVALID_PARAMETERS,
270  PT_STATUS_ALLOCATION_FAIL,
271  PT_STATUS_NOT_CONNECTED
272 } pt_status_t;
273 
274 typedef struct pt_resource {
275  ns_list_link_t link;
276  pt_object_instance_t *parent;
277  Lwm2mResourceType type;
278  uint16_t id;
279  unsigned int operations;
280  uint8_t *value;
281  uint32_t value_size;
282  pt_resource_callback callback;
283 } pt_resource_t;
284 
285 typedef NS_LIST_HEAD(pt_resource_t, link) pt_resource_list_t;
286 
287 typedef struct pt_object_instance {
288  ns_list_link_t link;
289  pt_object_t *parent;
290  pt_resource_list_t *resources;
291  uint16_t id;
293 
294 typedef NS_LIST_HEAD(pt_object_instance_t, link) pt_object_instance_list_t;
295 
296 typedef struct pt_object {
297  ns_list_link_t link;
298  pt_device_t *parent;
299  pt_object_instance_list_t *instances;
300  uint16_t id;
301 } pt_object_t;
302 
303 typedef NS_LIST_HEAD(pt_object_t, link) pt_object_list_t;
304 
305 struct pt_device_userdata_s;
306 
307 typedef void (*pt_device_free_userdata_cb_t)(void *data);
308 
319 typedef struct pt_device_userdata_s {
320  void *data;
321  pt_device_free_userdata_cb_t
324 
325 typedef struct pt_device {
326  ns_list_link_t link;
327  char* device_id;
328  uint32_t lifetime;
329  queuemode_t queuemode;
330  pt_device_userdata_t *userdata;
331  pt_object_list_t *objects;
332 } pt_device_t;
333 
334 typedef struct client_data_s {
335  char* name;
336  bool registered;
337  int id;
338  void* method_table;
339 } client_data_t;
340 
345  pt_connection_ready_cb connection_ready_cb;
346  pt_disconnected_cb disconnected_cb;
347  pt_received_write_handler received_write_cb;
348  pt_connection_shutdown_cb connection_shutdown_cb;
350 
351 typedef struct connection connection_t;
352 
366 DEPRECATED(typedef void (*pt_response_handler)(void* userdata));
367 
382 DEPRECATED(typedef void (*pt_device_response_handler)(const char* device_id, void* userdata));
383 
400 DEPRECATED(
401  pt_status_t pt_register_protocol_translator(connection_t *connection,
402  pt_response_handler success_handler,
403  pt_response_handler failure_handler,
404  void* userdata));
405 
421 DEPRECATED(
422  pt_status_t pt_register_device(connection_t *connection,
423  pt_device_t *device,
424  pt_device_response_handler success_handler,
425  pt_device_response_handler failure_handler,
426  void *userdata));
427 
442 DEPRECATED(
443  pt_status_t pt_unregister_device(connection_t *connection,
444  pt_device_t *device,
445  pt_device_response_handler success_handler,
446  pt_device_response_handler failure_handler,
447  void *userdata));
448 
461 DEPRECATED(pt_device_userdata_t *pt_api_create_device_userdata(void *data,
462  pt_device_free_userdata_cb_t free_userdata_cb));
463 
482 DEPRECATED(
483  pt_device_t *pt_create_device_with_userdata(char *device_id,
484  const uint32_t lifetime,
485  const queuemode_t queuemode,
486  pt_status_t *status,
487  pt_device_userdata_t *userdata));
488 
504 DEPRECATED(
505  pt_device_t *pt_create_device(char *device_id,
506  const uint32_t lifetime,
507  const queuemode_t queuemode,
508  pt_status_t *status));
509 
518 DEPRECATED(void pt_device_free(pt_device_t *device));
519 
531 DEPRECATED(pt_object_t *pt_device_add_object(pt_device_t *device, uint16_t id, pt_status_t *status));
532 
542 DEPRECATED(pt_object_t *pt_device_find_object(pt_device_t *device, uint16_t id));
543 
554 DEPRECATED(pt_object_instance_t * pt_object_add_object_instance(pt_object_t *object, uint16_t id, pt_status_t *status));
555 
565 DEPRECATED(pt_object_instance_t *pt_object_find_object_instance(pt_object_t *object, uint16_t id));
566 
598 DEPRECATED(
599  pt_resource_t *pt_object_instance_add_resource(pt_object_instance_t *object_instance,
600  uint16_t id,
601  Lwm2mResourceType type,
602  uint8_t *value,
603  uint32_t value_size,
604  pt_status_t *status));
605 
650 DEPRECATED(
651  pt_resource_t *pt_object_instance_add_resource_with_callback(pt_object_instance_t *object_instance,
652  uint16_t id,
653  Lwm2mResourceType type,
654  uint8_t operations,
655  uint8_t *value,
656  uint32_t value_size,
657  pt_status_t *status,
658  pt_resource_callback callback));
659 
669 DEPRECATED(pt_resource_t *pt_object_instance_find_resource(pt_object_instance_t *instance, uint16_t id));
670 
686 DEPRECATED(
687  pt_status_t pt_write_value(connection_t *connection,
688  pt_device_t *device,
689  pt_object_list_t *objects,
690  pt_device_response_handler success_handler,
691  pt_device_response_handler failure_handler,
692  void *userdata));
693 
705 DEPRECATED(int pt_receive_write_value(json_t *request, json_t *json_params, json_t **result, void *userdata));
706 
721 DEPRECATED(
722  int pt_client_start(const char *socket_path,
723  const char *name,
724  const protocol_translator_callbacks_t *pt_cbs,
725  void *userdata,
726  connection_t **connection));
727 
732 DEPRECATED(void pt_client_shutdown(connection_t *connection));
733 
739 #endif /* PT_API_H_ */
Contains fields for client user data.
Definition: pt_api.h:319
Lwm2mResourceType
LwM2M resource type enumeration constants.
Definition: constants.h:48
void(* pt_connection_ready_cb)(connection_id_t connection_id, const char *name, void *userdata)
A function prototype for calling the client code when the connection is ready for passing messages...
Definition: pt_client_api.h:75
void * data
Definition: pt_api.h:320
Common constants used in Edge Core.
struct protocol_translator_callbacks protocol_translator_callbacks_t
A structure to hold the callbacks of the protocol translator.
void(* pt_disconnected_cb)(connection_id_t connection_id, void *userdata)
A function prototype for calling the client code when the connection is disconnected.
Definition: pt_client_api.h:84
pt_status_t pt_client_shutdown(pt_client_t *client)
Gracefully shuts down the protocol translator client.
pt_received_write_handler received_write_cb
Definition: pt_api.h:347
Definition: pt_api.h:334
void(* pt_device_response_handler)(const connection_id_t connection_id, const char *device_id, void *userdata)
A function pointer type definition for callbacks given in the device API functions as an argument...
Definition: pt_api.h:207
Definition: pt_api.h:296
pt_device_free_userdata_cb_t pt_device_free_userdata
Definition: pt_api.h:322
Default message ID generator for JSON-RPC messages.
pt_status_t(* pt_resource_callback)(const connection_id_t connection_id, const char *device_id, const uint16_t object_id, const uint16_t object_instance_id, const uint16_t resource_id, const uint8_t operation, const uint8_t *value, const uint32_t size, void *userdata)
Callback function prototype for the device resource specific action on OPERATION_WRITE or OPERATION_E...
Definition: pt_api.h:178
A structure to hold the callbacks of the protocol translator.
Definition: pt_api.h:344
Definition: pt_api.h:287
void(* pt_connection_shutdown_cb)(connection_id_t connection_id, void *userdata)
A function prototype for calling the client code when the connection is shutting down.
Definition: pt_client_api.h:93
int pt_client_start(pt_client_t *client, pt_response_handler success_handler, pt_response_handler failure_handler, const char *name, void *userdata)
Starts the protocol translator client event loop and tries to connect to a local instance of Device M...
struct pt_device_userdata_s pt_device_userdata_t
Contains fields for client user data.
pt_status_t
Enumeration containing the possible return status codes for Protocol API functions.
Definition: pt_common_api.h:51
void(* pt_response_handler)(void *userdata)
A function pointer type definition for callbacks given in the protocol translator API functions as an...
Definition: pt_client_api.h:65
DEPRECATED(typedef void(*pt_resource_callback)(const pt_resource_t *resource, const uint8_t *value, const uint32_t size, void *userdata))
Callback function prototype for the device resource specific action on OPERATION_WRITE or OPERATION_E...
Definition: pt_api.h:325
Definition: pt_api.h:274