Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-oic.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <sol-common-buildopts.h>
22 #include <sol-vector.h>
23 #include <sol-str-slice.h>
24 #include "sol-coap.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
55 typedef struct sol_oic_platform_info {
56 #ifndef SOL_NO_API_VERSION
57 #define SOL_OIC_PLATFORM_INFO_API_VERSION (1)
58  uint16_t api_version;
59 #endif
60 
61  /* All fields are required by the spec. Some of the fields are
62  * obtained in runtime (such as system time, OS version), and are
63  * not user-specifiable.
64  */
65 
102 
103  /* Read-only fields. */
104 
114 
165 };
166 
175 typedef struct sol_oic_device_info {
176 #ifndef SOL_NO_API_VERSION
177 #define SOL_OIC_DEVICE_INFO_API_VERSION (1)
178  uint16_t api_version;
179 #endif
180 
198 
213 };
214 
225 typedef struct sol_oic_repr_field {
233  const char *key;
238  union {
242  uint64_t v_uint;
246  int64_t v_int;
250  uint8_t v_simple;
259  float v_float;
263  double v_double;
267  void *v_voidptr;
271  bool v_boolean;
272  };
274 
282 #define SOL_OIC_REPR_FIELD(key_, type_, ...) \
283  (struct sol_oic_repr_field){.type = (type_), .key = (key_), { __VA_ARGS__ } }
284 
291 #define SOL_OIC_REPR_UINT(key_, value_) \
292  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_UINT, .v_uint = (value_))
293 
300 #define SOL_OIC_REPR_INT(key_, value_) \
301  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_INT, .v_int = (value_))
302 
309 #define SOL_OIC_REPR_BOOL(key_, value_) \
310  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_BOOL, .v_boolean = !!(value_))
311 
318 #define SOL_OIC_REPR_SIMPLE(key_, value_) \
319  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_SIMPLE, .v_simple = (value_))
320 
329 #define SOL_OIC_REPR_TEXT_STRING(key_, value_, len_) \
330  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_TEXT_STRING, .v_slice = SOL_STR_SLICE_STR((value_), (len_)))
331 
340 #define SOL_OIC_REPR_BYTE_STRING(key_, value_, len_) \
341  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_BYTE_STRING, .v_slice = SOL_STR_SLICE_STR((value_), (len_)))
342 
350 #define SOL_OIC_REPR_HALF_FLOAT(key_, value_) \
351  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_HALF_FLOAT, .v_voidptr = (void *)(value_))
352 
360 #define SOL_OIC_REPR_FLOAT(key_, value_) \
361  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_FLOAT, .v_float = (value_))
362 
369 #define SOL_OIC_REPR_DOUBLE(key_, value_) \
370  SOL_OIC_REPR_FIELD(key_, SOL_OIC_REPR_TYPE_DOUBLE, .v_double = (value_))
371 
383 struct sol_oic_map_writer;
385 
410 };
411 
431 typedef struct sol_oic_map_reader {
432  const void *parser;
433  const void *ptr;
434  const uint32_t remaining;
435  const uint16_t extra;
436  const uint8_t type;
437  const uint8_t flags;
439 
447 struct sol_oic_request;
449 
457 struct sol_oic_response;
459 
473 };
474 
492 enum sol_oic_map_loop_reason sol_oic_map_loop_init(const struct sol_oic_map_reader *map, struct sol_oic_map_reader *iterator, struct sol_oic_repr_field *repr);
493 
510 bool sol_oic_map_loop_next(struct sol_oic_repr_field *repr, struct sol_oic_map_reader *iterator, enum sol_oic_map_loop_reason *reason);
511 
526 int sol_oic_map_append(struct sol_oic_map_writer *oic_map_writer, struct sol_oic_repr_field *repr);
527 
542 int sol_oic_map_set_type(struct sol_oic_map_writer *oic_map_writer, enum sol_oic_map_type type);
543 
552 int sol_oic_map_get_type(struct sol_oic_map_writer *oic_map_writer, enum sol_oic_map_type *type);
553 
561 void sol_oic_repr_field_clear(struct sol_oic_repr_field *field);
562 
600 #define SOL_OIC_MAP_LOOP(map_, current_, iterator_, end_reason_) \
601  for (end_reason_ = sol_oic_map_loop_init(map_, iterator_, current_); \
602  end_reason_ == SOL_OIC_MAP_LOOP_OK && \
603  sol_oic_map_loop_next(current_, iterator_, &end_reason_);)
604 
615 #ifdef SOL_LOG_ENABLED
616 void sol_oic_payload_debug(struct sol_coap_packet *pkt);
617 #else
618 static inline void
620 {
621 }
622 #endif
623 
628 #ifdef __cplusplus
629 }
630 #endif
Double-precision float number type.
Definition: sol-oic.h:211
int sol_oic_map_get_type(struct sol_oic_map_writer *oic_map_writer, enum sol_oic_map_type *type)
get current oic_map_writer type.
struct sol_str_slice model_number
Model number as designated by manufacturer.
Definition: sol-oic.h:81
uint64_t v_uint
Field's data if type is SOL_OIC_REPR_TYPE_UINT.
Definition: sol-oic.h:242
struct sol_oic_map_reader sol_oic_map_reader
Handler for an OIC packet map reader.
Definition: sol-oic.h:203
struct sol_str_slice support_url
URL to manufacturer's support website.
Definition: sol-oic.h:101
struct sol_oic_response sol_oic_response
Information about a server response.
Definition: sol-oic.h:458
const uint16_t extra
Definition: sol-oic.h:435
uint16_t api_version
API version.
Definition: sol-oic.h:58
struct sol_str_slice v_slice
Field's data if type is SOL_OIC_REPR_TYPE_TEXT_STRING or SOL_OIC_REPR_TYPE_BYTE_STRING.
Definition: sol-oic.h:255
Structure containing all fields that are retrieved by sol_oic_client_get_server_info() and sol_oic_cl...
Definition: sol-oic.h:175
Structure to keep a single oic-map's field.
Definition: sol-oic.h:225
struct sol_str_slice manufacture_date
Manufacturing date.
Definition: sol-oic.h:85
void * v_voidptr
Field's data if type is SOL_OIC_REPR_TYPE_HALF_FLOAT.
Definition: sol-oic.h:267
Map with no content.
Definition: sol-oic.h:400
struct sol_str_slice platform_id
Platform identifier.
Definition: sol-oic.h:69
int sol_oic_map_set_type(struct sol_oic_map_writer *oic_map_writer, enum sol_oic_map_type type)
set current oic_map_writer type.
enum sol_oic_map_loop_reason sol_oic_map_loop_init(const struct sol_oic_map_reader *map, struct sol_oic_map_reader *iterator, struct sol_oic_repr_field *repr)
Initialize an iterator to loop through elements of map.
struct sol_oic_platform_info sol_oic_platform_info
Structure containing all fields that are retrieved by sol_oic_client_get_platform_info() and sol_oic_...
const void * ptr
Definition: sol-oic.h:433
Map with content.
Definition: sol-oic.h:409
String with bytes type.
Definition: sol-oic.h:208
const uint8_t type
Definition: sol-oic.h:436
int64_t v_int
Field's data if type is SOL_OIC_REPR_TYPE_INT.
Definition: sol-oic.h:246
struct sol_str_slice firmware_version
Version of the firmware.
Definition: sol-oic.h:97
String slice type.
Definition: sol-str-slice.h:84
uint16_t api_version
API version.
Definition: sol-oic.h:178
The resource is slow.
Definition: sol-oic.h:153
double v_double
Field's data if type is SOL_OIC_REPR_TYPE_DOUBLE.
Definition: sol-oic.h:263
struct sol_str_slice platform_version
Version of the platform.
Definition: sol-oic.h:89
Success termination.
Definition: sol-oic.h:467
struct sol_str_slice hardware_version
Version of the hardware.
Definition: sol-oic.h:93
uint8_t v_simple
Field's data if type is SOL_OIC_REPR_TYPE_SIMPLE.
Definition: sol-oic.h:250
Signed int type.
Definition: sol-oic.h:205
Loop was terminated because an error occurred.
Definition: sol-oic.h:472
Structure containing all fields that are retrieved by sol_oic_client_get_platform_info() and sol_oic_...
Definition: sol-oic.h:55
struct sol_coap_packet sol_coap_packet
Opaque handler for a CoAP packet.
Definition: sol-coap.h:250
struct sol_oic_request sol_oic_request
Information about a client request.
Definition: sol-oic.h:448
bool sol_oic_map_loop_next(struct sol_oic_repr_field *repr, struct sol_oic_map_reader *iterator, enum sol_oic_map_loop_reason *reason)
Get the next element from iterator.
The resource is secure.
Definition: sol-oic.h:159
enum sol_oic_repr_type type
type of the data of this field.
Definition: sol-oic.h:229
const uint8_t flags
Definition: sol-oic.h:437
sol_oic_resource_flag
Flags to set when adding a new resource to a server.
Definition: sol-oic.h:122
struct sol_oic_device_info sol_oic_device_info
Structure containing all fields that are retrieved by sol_oic_client_get_server_info() and sol_oic_cl...
struct sol_str_slice manufacturer_name
Name of manufacturer.
Definition: sol-oic.h:73
struct sol_str_slice device_name
Device name.
Definition: sol-oic.h:184
static void sol_oic_payload_debug(struct sol_coap_packet *pkt)
Print the decoded cbor content of pkt.
Definition: sol-oic.h:619
struct sol_str_slice data_model_version
Spec version of data model.
Definition: sol-oic.h:196
Half-precision float number type.
Definition: sol-oic.h:209
struct sol_str_slice system_time
Current system time in the device.
Definition: sol-oic.h:112
struct sol_str_slice manufacturer_url
URL to manufacturer.
Definition: sol-oic.h:77
Unsigned 8-bit integer type.
Definition: sol-oic.h:206
Single-precision float number type.
Definition: sol-oic.h:210
Unsigned int type.
Definition: sol-oic.h:204
struct sol_str_slice spec_version
Spec version of the core specification implemented by this device.
Definition: sol-oic.h:188
struct sol_oic_map_writer sol_oic_map_writer
Opaque handler for an OIC packet map writer.
Definition: sol-oic.h:384
Boolean precision type.
Definition: sol-oic.h:212
int sol_oic_map_append(struct sol_oic_map_writer *oic_map_writer, struct sol_oic_repr_field *repr)
Append an element to oic_map_writer.
The resource is active.
Definition: sol-oic.h:146
bool v_boolean
Field's data if type is SOL_OIC_REPR_TYPE_BOOL.
Definition: sol-oic.h:271
No flag is set.
Definition: sol-oic.h:128
These are routines that Soletta provides for its string slice implementation.
struct sol_str_slice os_version
Version of the operational system running on the device.
Definition: sol-oic.h:108
void sol_oic_repr_field_clear(struct sol_oic_repr_field *field)
Release memory from field.
The resource is discoverable by clients only if request contains an explicity query.
Definition: sol-oic.h:164
sol_oic_map_loop_reason
Possible reasons a SOL_OIC_MAP_LOOP was terminated.
Definition: sol-oic.h:463
String with text type.
Definition: sol-oic.h:207
sol_oic_map_type
Used in sol_oic_map_writer to state if the map has a content or not.
Definition: sol-oic.h:392
Routines to handle CoAP protocol.
These are routines that Soletta provides for its vector implementation.
The resource is discoverable by clients.
Definition: sol-oic.h:132
const uint32_t remaining
Definition: sol-oic.h:434
Handler for an OIC packet map reader.
Definition: sol-oic.h:431
struct sol_oic_repr_field sol_oic_repr_field
Structure to keep a single oic-map's field.
float v_float
Field's data if type is SOL_OIC_REPR_TYPE_FLOAT.
Definition: sol-oic.h:259
The resource is observable.
Definition: sol-oic.h:139
struct sol_str_slice device_id
Unique device identifier.
Definition: sol-oic.h:192
sol_oic_repr_type
field type of sol_oic_repr_field structure.
Definition: sol-oic.h:202
const void * parser
Definition: sol-oic.h:432
const char * key
Field's key as a string.
Definition: sol-oic.h:233