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 2
23 #endif
24 #if PT_API_VERSION != 2
25 #error "Including mixed versions of Protocol API"
26 #endif
27 
28 #ifndef PT_API_H_
29 #define PT_API_H_
30 
36 #include <stdbool.h>
37 
42 
178 typedef pt_status_t (*pt_resource_callback)(const connection_id_t connection_id,
179  const char *device_id,
180  const uint16_t object_id,
181  const uint16_t object_instance_id,
182  const uint16_t resource_id,
183  const uint8_t operation,
184  const uint8_t *value,
185  const uint32_t size,
186  void *userdata);
187 
193 typedef void (*pt_resource_value_free_callback)(void *value);
194 
207 typedef void (*pt_device_response_handler)(const connection_id_t connection_id, const char *device_id, void *userdata);
208 
225 pt_status_t pt_device_create_with_userdata(const connection_id_t connection_id,
226  const char *device_id,
227  const uint32_t lifetime,
228  const queuemode_t queuemode,
229  pt_userdata_t *userdata);
230 
249 pt_status_t pt_device_create_with_feature_flags(const connection_id_t connection_id,
250  const char *device_id,
251  const uint32_t lifetime,
252  const queuemode_t queuemode,
253  const uint32_t features,
254  pt_userdata_t *userdata);
255 
268 pt_status_t pt_device_create(const connection_id_t connection_id,
269  const char *device_id,
270  const uint32_t lifetime,
271  const queuemode_t queuemode);
272 
284 pt_status_t pt_device_get_feature_flags(const connection_id_t connection_id,
285  const char *device_id,
286  uint32_t *features);
287 
303 pt_status_t pt_device_register(const connection_id_t connection_id,
304  const char *device_id,
305  pt_device_response_handler success_handler,
306  pt_device_response_handler failure_handler,
307  void *userdata);
308 
324 pt_status_t pt_device_unregister(const connection_id_t connection_id,
325  const char *device_id,
326  pt_device_response_handler success_handler,
327  pt_device_response_handler failure_handler,
328  void *userdata);
329 
345 pt_status_t pt_device_write_values(const connection_id_t connection_id,
346  const char *device_id,
347  pt_device_response_handler success_handler,
348  pt_device_response_handler failure_handler,
349  void *userdata);
350 
370 pt_status_t pt_device_set_resource_value(const connection_id_t connection_id,
371  const char *device_id,
372  const uint16_t object_id,
373  const uint16_t object_instance_id,
374  const uint16_t resource_id,
375  const uint8_t *value,
376  uint32_t value_len,
377  pt_resource_value_free_callback value_free_cb);
378 
387 bool pt_device_exists(const connection_id_t connection_id, const char *device_id);
388 
400 bool pt_device_resource_exists(const connection_id_t connection_id,
401  const char *device_id,
402  const uint16_t object_id,
403  const uint16_t object_instance_id,
404  const uint16_t resource_id);
405 
445 pt_status_t pt_device_add_resource(const connection_id_t connection_id,
446  const char *device_id,
447  const uint16_t object_id,
448  const uint16_t object_instance_id,
449  const uint16_t resource_id,
450  const Lwm2mResourceType type,
451  uint8_t *value,
452  uint32_t value_size,
453  pt_resource_value_free_callback value_free_cb);
454 
505 pt_status_t pt_device_add_resource_with_callback(const connection_id_t connection_id,
506  const char *device_id,
507  const uint16_t object_id,
508  const uint16_t object_instance_id,
509  const uint16_t resource_id,
510  const Lwm2mResourceType type,
511  const uint8_t operations,
512  uint8_t *value,
513  uint32_t value_size,
514  pt_resource_value_free_callback value_free_cb,
515  pt_resource_callback callback);
516 
530 pt_status_t pt_device_get_resource_value(connection_id_t connection_id,
531  const char *device_id,
532  const uint16_t object_id,
533  const uint16_t object_instance_id,
534  const uint16_t resource_id,
535  uint8_t **value_out,
536  uint32_t *value_len_out);
537 
549 int32_t pt_device_get_next_free_object_instance_id(connection_id_t connection_id,
550  const char *device_id,
551  uint16_t object_id);
552 
562 pt_userdata_t *pt_device_get_userdata(connection_id_t connection_id, const char *device_id);
563 
576 pt_userdata_t *pt_resource_get_userdata(connection_id_t connection_id,
577  const char *device_id,
578  const uint16_t object_id,
579  const uint16_t object_instance_id,
580  const uint16_t resource_id);
581 
593 pt_status_t pt_device_set_userdata(connection_id_t connection_id, const char *device_id, pt_userdata_t *userdata);
594 
610 pt_status_t pt_resource_set_userdata(connection_id_t connection_id,
611  const char *device_id,
612  const uint16_t object_id,
613  const uint16_t object_instance_id,
614  const uint16_t resource_id,
615  pt_userdata_t *userdata);
616 
622 #endif /* PT_API_H_ */
pt_status_t pt_device_add_resource(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 Lwm2mResourceType type, uint8_t *value, uint32_t value_size, pt_resource_value_free_callback value_free_cb)
Adds a read-only resource to a device.
int32_t pt_device_get_next_free_object_instance_id(connection_id_t connection_id, const char *device_id, uint16_t object_id)
Get the id of first free object instance for given object.
Lwm2mResourceType
LwM2M resource type enumeration constants.
Definition: constants.h:48
pt_status_t pt_device_set_userdata(connection_id_t connection_id, const char *device_id, pt_userdata_t *userdata)
Set the set user data to the device. This may be useful if the client needs to associate some extra d...
pt_status_t pt_device_get_resource_value(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, uint8_t **value_out, uint32_t *value_len_out)
Utility function to get the current value in a resource.
pt_status_t pt_device_write_values(const connection_id_t connection_id, const char *device_id, pt_device_response_handler success_handler, pt_device_response_handler failure_handler, void *userdata)
Writes changed values from the endpoint device to Edge Core.
pt_status_t pt_device_register(const connection_id_t connection_id, const char *device_id, pt_device_response_handler success_handler, pt_device_response_handler failure_handler, void *userdata)
Endpoint device registration function. Every endpoint device must be registered with the protocol tra...
pt_status_t pt_resource_set_userdata(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, pt_userdata_t *userdata)
Set the set user data to the resource. This may be useful if the client needs to associate some extra...
pt_status_t pt_device_unregister(const connection_id_t connection_id, const char *device_id, pt_device_response_handler success_handler, pt_device_response_handler failure_handler, void *userdata)
Endpoint device unregistration function. If the device unregistration succeeds, the device instance d...
pt_status_t pt_device_create_with_userdata(const connection_id_t connection_id, const char *device_id, const uint32_t lifetime, const queuemode_t queuemode, pt_userdata_t *userdata)
Creates the device structure.
pt_status_t pt_device_get_feature_flags(const connection_id_t connection_id, const char *device_id, uint32_t *features)
Retrieves the feature flags of a device.
Contains the interface to manage multiple devices.
void(* pt_resource_value_free_callback)(void *value)
Callback function prototype for freeing the resource value.
Definition: pt_api.h:193
pt_status_t pt_device_create(const connection_id_t connection_id, const char *device_id, const uint32_t lifetime, const queuemode_t queuemode)
Creates the device structure.
Protocol translator API for client&#39;s data.
pt_userdata_t * pt_resource_get_userdata(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)
Retrieve the set user data in the resource. Client needs to provide the full path to the resource...
Contains common structures and definitions for the protocol translator client.
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
pt_status_t pt_device_set_resource_value(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 *value, uint32_t value_len, pt_resource_value_free_callback value_free_cb)
Set a new value to resource in the device.
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
pt_status_t pt_device_add_resource_with_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 Lwm2mResourceType type, const uint8_t operations, uint8_t *value, uint32_t value_size, pt_resource_value_free_callback value_free_cb, pt_resource_callback callback)
Adds a resource to a device with a callback.
bool pt_device_exists(const connection_id_t connection_id, const char *device_id)
Utility function to check if device already exists for the connection.
pt_status_t pt_device_create_with_feature_flags(const connection_id_t connection_id, const char *device_id, const uint32_t lifetime, const queuemode_t queuemode, const uint32_t features, pt_userdata_t *userdata)
Creates the device structure and enables additional features.
bool pt_device_resource_exists(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)
Utility function to check if resource already exists for the connection and device.
pt_userdata_t * pt_device_get_userdata(connection_id_t connection_id, const char *device_id)
Retrieve the set user data in the device.
pt_status_t
Enumeration containing the possible return status codes for Protocol API functions.
Definition: pt_common_api.h:51
Contains fields for client user data.
Definition: pt_userdata_api.h:62
Contains the interface to create, connect, register, unregister and shut down the protocol translator...