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-flow-packet.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 <stdbool.h>
22 #include <stddef.h>
23 #include <time.h>
24 
25 #include "sol-common-buildopts.h"
26 #include "sol-str-slice.h"
27 #include "sol-types.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
53 struct sol_flow_packet;
55 
60 typedef struct sol_flow_packet_type {
61 #ifndef SOL_NO_API_VERSION
62 #define SOL_FLOW_PACKET_TYPE_API_VERSION (1)
63  uint16_t api_version;
64 #endif
65  uint16_t data_size;
66  const char *name;
77  int (*init)(const struct sol_flow_packet_type *packet_type, void *mem, const void *input);
78 
87  int (*get)(const struct sol_flow_packet_type *packet_type, const void *mem, void *output);
88 
95  void (*dispose)(const struct sol_flow_packet_type *packet_type, void *mem);
96 
105  struct sol_flow_packet *(*get_constant)(const struct sol_flow_packet_type *packet_type, const void *value);
107 
116 struct sol_flow_packet *sol_flow_packet_new(const struct sol_flow_packet_type *type, const void *value);
117 
123 void sol_flow_packet_del(struct sol_flow_packet *packet);
124 
132 const struct sol_flow_packet_type *sol_flow_packet_get_type(const struct sol_flow_packet *packet);
133 
142 int sol_flow_packet_get(const struct sol_flow_packet *packet, void *output);
143 
148 
153 
158 
163 
168 
173 
178 
183 
188 
193 
198 
203 
208 
213 
218 
223 
224 
225 /*
226  * Convenience functions to use certain types of common packets.
227  */
228 
235 
243 struct sol_flow_packet *sol_flow_packet_new_bool(bool boolean);
244 
253 int sol_flow_packet_get_bool(const struct sol_flow_packet *packet, bool *boolean);
254 
262 struct sol_flow_packet *sol_flow_packet_new_byte(unsigned char byte);
263 
272 int sol_flow_packet_get_byte(const struct sol_flow_packet *packet, unsigned char *byte);
273 
283 struct sol_flow_packet *sol_flow_packet_new_irange(const struct sol_irange *irange);
284 
295 
306 int sol_flow_packet_get_irange(const struct sol_flow_packet *packet, struct sol_irange *irange);
307 
318 int sol_flow_packet_get_irange_value(const struct sol_flow_packet *packet, int32_t *value);
319 
331 
343 
352 int sol_flow_packet_get_string(const struct sol_flow_packet *packet, const char **value);
353 
369 
378 
387 int sol_flow_packet_get_blob(const struct sol_flow_packet *packet, struct sol_blob **value);
388 
401 
410 int sol_flow_packet_get_json_object(const struct sol_flow_packet *packet, struct sol_blob **value);
411 
424 
433 int sol_flow_packet_get_json_array(const struct sol_flow_packet *packet, struct sol_blob **value);
434 
444 struct sol_flow_packet *sol_flow_packet_new_drange(const struct sol_drange *drange);
445 
456 
467 int sol_flow_packet_get_drange(const struct sol_flow_packet *packet, struct sol_drange *drange);
468 
479 int sol_flow_packet_get_drange_value(const struct sol_flow_packet *packet, double *value);
480 
489 struct sol_flow_packet *sol_flow_packet_new_error(int code, const char *msg);
490 
500 int sol_flow_packet_get_error(const struct sol_flow_packet *packet, int *code, const char **msg);
501 
511 struct sol_flow_packet *sol_flow_packet_new_rgb(const struct sol_rgb *rgb);
512 
524 struct sol_flow_packet *sol_flow_packet_new_rgb_components(uint32_t red, uint32_t green, uint32_t blue);
525 
536 int sol_flow_packet_get_rgb(const struct sol_flow_packet *packet, struct sol_rgb *rgb);
537 
550 int sol_flow_packet_get_rgb_components(const struct sol_flow_packet *packet, uint32_t *red, uint32_t *green, uint32_t *blue);
551 
561 struct sol_flow_packet *sol_flow_packet_new_direction_vector(const struct sol_direction_vector *direction_vector);
562 
574 struct sol_flow_packet *sol_flow_packet_new_direction_vector_components(double x, double y, double z);
575 
586 int sol_flow_packet_get_direction_vector(const struct sol_flow_packet *packet, struct sol_direction_vector *direction_vector);
587 
600 int sol_flow_packet_get_direction_vector_components(const struct sol_flow_packet *packet, double *x, double *y, double *z);
601 
609 struct sol_flow_packet *sol_flow_packet_new_location(const struct sol_location *location);
610 
622 struct sol_flow_packet *sol_flow_packet_new_location_components(double lat, double lon, double alt);
623 
632 int sol_flow_packet_get_location(const struct sol_flow_packet *packet, struct sol_location *location);
633 
646 int sol_flow_packet_get_location_components(const struct sol_flow_packet *packet, double *lat, double *lon, double *alt);
647 
655 struct sol_flow_packet *sol_flow_packet_new_timestamp(const struct timespec *timestamp);
656 
665 int sol_flow_packet_get_timestamp(const struct sol_flow_packet *packet, struct timespec *timestamp);
666 
675 
684 
694 int sol_flow_packet_get_composed_members_packet_types(const struct sol_flow_packet_type *type, const struct sol_flow_packet_type ***children, uint16_t *len);
695 
707 int sol_flow_packet_get_composed_members(const struct sol_flow_packet *packet, struct sol_flow_packet ***children, uint16_t *len);
708 
716 struct sol_flow_packet *sol_flow_packet_dup(const struct sol_flow_packet *packet);
717 
730 struct sol_flow_packet *sol_flow_packet_new_http_response(int response_code, const char *url, const char *content_type, const struct sol_blob *content, const struct sol_vector *cookies, const struct sol_vector *headers);
731 
745 int sol_flow_packet_get_http_response(const struct sol_flow_packet *packet, int *response_code, const char **url, const char **content_type, const struct sol_blob **content, struct sol_vector *cookies, struct sol_vector *headers);
746 
768 const char *sol_flow_get_packet_type_name(const struct sol_str_slice type);
769 
785 
790 #ifdef __cplusplus
791 }
792 #endif
struct sol_flow_packet * sol_flow_packet_new_byte(unsigned char byte)
Creates a new packet of type Byte.
bool sol_flow_packet_is_composed_type(const struct sol_flow_packet_type *type)
Checks if a given packet type is a composed packet type.
struct sol_flow_packet * sol_flow_packet_new_rgb(const struct sol_rgb *rgb)
Creates a new packet of type RGB.
int sol_flow_packet_get_location_components(const struct sol_flow_packet *packet, double *lat, double *lon, double *alt)
Retrieves the location components contained in a Location packet.
struct sol_flow_packet * sol_flow_packet_new_rgb_components(uint32_t red, uint32_t green, uint32_t blue)
Creates a new packet of type RGB from the given red, green and blue components.
struct sol_flow_packet * sol_flow_packet_new_direction_vector_components(double x, double y, double z)
Creates a new packet of type Direction Vector from the given x, y and z components.
int sol_flow_packet_get_error(const struct sol_flow_packet *packet, int *code, const char **msg)
Retrieves the content of an Error packet.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_ANY
Type of the Any packet.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_HTTP_RESPONSE
Type of the Http Response packet.
struct sol_flow_packet * sol_flow_packet_new_irange_value(int32_t value)
Creates a new packet of type Irange with initial value value and default spec.
const char * name
Type's name.
Definition: sol-flow-packet.h:66
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_BOOL
Type of the Boolean packet.
struct sol_flow_packet * sol_flow_packet_new_drange_value(double value)
Creates a new packet of type Drange with initial value value and default spec.
int sol_flow_packet_get_json_array(const struct sol_flow_packet *packet, struct sol_blob **value)
Retrieves the content of a JSON Array packet.
int sol_flow_packet_get_rgb(const struct sol_flow_packet *packet, struct sol_rgb *rgb)
Retrieves the content of a RGB packet.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_DIRECTION_VECTOR
Type of the Direction Vector packet.
struct sol_flow_packet * sol_flow_packet_new_http_response(int response_code, const char *url, const char *content_type, const struct sol_blob *content, const struct sol_vector *cookies, const struct sol_vector *headers)
Creates a new packet of type HTTP Response.
These routines are used for Soletta types' manipulation.
int sol_flow_packet_get_rgb_components(const struct sol_flow_packet *packet, uint32_t *red, uint32_t *green, uint32_t *blue)
Retrieves the RGB components contained in a RGB packet.
struct sol_flow_packet * sol_flow_packet_new_json_array(const struct sol_blob *value)
Creates a new packet of type JSON Array.
int sol_flow_packet_get_json_object(const struct sol_flow_packet *packet, struct sol_blob **value)
Retrieves the content of a JSON Object packet.
void sol_flow_packet_del(struct sol_flow_packet *packet)
Deletes a packet.
struct sol_flow_packet * sol_flow_packet_new_location_components(double lat, double lon, double alt)
Creates a new packet of type Location from the given lat, lon, alt components.
struct sol_flow_packet * sol_flow_packet_new_bool(bool boolean)
Creates a new packet of type Boolean.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_ERROR
Type of the Error packet.
Data type describing a Double range.
Definition: sol-types.h:187
int sol_flow_packet_get_bool(const struct sol_flow_packet *packet, bool *boolean)
Retrieves the content of a Boolean packet.
struct sol_flow_packet * sol_flow_packet_new_drange(const struct sol_drange *drange)
Creates a new packet of type Drange.
int sol_flow_packet_get_timestamp(const struct sol_flow_packet *packet, struct timespec *timestamp)
Retrieves the content of a Timestamp packet.
int sol_flow_packet_get_location(const struct sol_flow_packet *packet, struct sol_location *location)
Retrieves the content of a Location packet.
struct sol_flow_packet * sol_flow_packet_new_string_slice(struct sol_str_slice slice)
Creates a new packet of type String from string slice slice.
static struct sol_buffer value
Definition: server.c:42
struct sol_flow_packet sol_flow_packet
A packet is a generic container for different kinds (types) of contents.
Definition: sol-flow-packet.h:54
static struct sol_blob lat
Definition: lwm2m-server.c:61
String slice type.
Definition: sol-str-slice.h:84
Data type to describe a direction vector.
Definition: sol-types.h:125
int sol_flow_packet_get_string(const struct sol_flow_packet *packet, const char **value)
Retrieves the content of a String packet.
int sol_flow_packet_get_irange(const struct sol_flow_packet *packet, struct sol_irange *irange)
Retrieves the content of an Irange packet.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_TIMESTAMP
Type of the Timestamp packet.
int sol_flow_packet_get_http_response(const struct sol_flow_packet *packet, int *response_code, const char **url, const char **content_type, const struct sol_blob **content, struct sol_vector *cookies, struct sol_vector *headers)
Retrieves the content of a Timestamp packet.
Data type describing Integer ranges.
Definition: sol-types.h:327
Data type to describe a location.
Definition: sol-types.h:146
const struct sol_flow_packet_type * sol_flow_packet_type_composed_new(const struct sol_flow_packet_type **types)
Creates a new packet type that is composed by the packets types in types.
struct sol_flow_packet * sol_flow_packet_new_blob(const struct sol_blob *value)
Creates a new packet of type Blob.
const char * sol_flow_get_packet_type_name(const struct sol_str_slice type)
Returns the packet type variable as string.
Data type to describe a RGB color.
Definition: sol-types.h:155
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_JSON_ARRAY
Type of the JSON Array packet.
struct sol_flow_packet * sol_flow_packet_new_empty(void)
Creates a new packet of type Empty.
int(* init)(const struct sol_flow_packet_type *packet_type, void *mem, const void *input)
Initializes a packet instance of this type.
Definition: sol-flow-packet.h:77
struct sol_flow_packet * sol_flow_packet_new_error(int code, const char *msg)
Creates a new packet of type Error.
Data type describing the default blob implementation.
Definition: sol-types.h:468
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_DRANGE
Type of the Drange packet.
struct sol_flow_packet * sol_flow_packet_dup(const struct sol_flow_packet *packet)
Duplicates a packet.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_BYTE
Type of the Byte packet.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_STRING
Type of the String packet.
struct sol_flow_packet * sol_flow_packet_new_string_take(char *value)
Similar to sol_flow_packet_new_string() but takes ownership of value to use as the packet content...
int sol_flow_packet_get(const struct sol_flow_packet *packet, void *output)
Retrieves the packet's content.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_IRANGE
Type of the Irange packet.
uint16_t api_version
API version number.
Definition: sol-flow-packet.h:63
struct sol_flow_packet * sol_flow_packet_new_timestamp(const struct timespec *timestamp)
Creates a new packet of type Timestamp.
int sol_flow_packet_get_drange(const struct sol_flow_packet *packet, struct sol_drange *drange)
Retrieves the content of an Drange packet.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_RGB
Type of the RGB packet.
int sol_flow_packet_get_composed_members_packet_types(const struct sol_flow_packet_type *type, const struct sol_flow_packet_type ***children, uint16_t *len)
Retrieves the list of packet types that composes type.
int sol_flow_packet_get_drange_value(const struct sol_flow_packet *packet, double *value)
Retrieves the Drange value of an Drange packet.
struct sol_flow_packet * sol_flow_packet_new_json_object(const struct sol_blob *value)
Creates a new packet of type JSON Object.
void(* dispose)(const struct sol_flow_packet_type *packet_type, void *mem)
Disposes a packet instance of this type.
Definition: sol-flow-packet.h:95
struct sol_flow_packet * sol_flow_packet_new_location(const struct sol_location *location)
Creates a new packet of type Location.
These are routines that Soletta provides for its string slice implementation.
struct sol_flow_packet_type sol_flow_packet_type
A packet type defines what's the content of a packet and how it's stored and retrieved.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_BLOB
Type of the Blob packet.
int sol_flow_packet_get_byte(const struct sol_flow_packet *packet, unsigned char *byte)
Retrieves the content of a Byte packet.
struct sol_flow_packet * sol_flow_packet_new_direction_vector(const struct sol_direction_vector *direction_vector)
Creates a new packet of type Direction Vector.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_EMPTY
Type of the Empty packet.
int sol_flow_packet_get_irange_value(const struct sol_flow_packet *packet, int32_t *value)
Retrieves the Irange value of an Irange packet.
struct sol_flow_packet * sol_flow_packet_new_string(const char *value)
Creates a new packet of type String.
int sol_flow_packet_get_blob(const struct sol_flow_packet *packet, struct sol_blob **value)
Retrieves the content of a Blob packet.
const struct sol_flow_packet_type * sol_flow_packet_get_type(const struct sol_flow_packet *packet)
Retrieves the packet's type.
struct sol_flow_packet * sol_flow_packet_new(const struct sol_flow_packet_type *type, const void *value)
Creates a packet.
Soletta vector is an array that grows dynamically.
Definition: sol-vector.h:58
int sol_flow_packet_get_direction_vector(const struct sol_flow_packet *packet, struct sol_direction_vector *direction_vector)
Retrieves the content of a Direction Vector packet.
uint16_t data_size
Data's size of a given packet type.
Definition: sol-flow-packet.h:65
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_JSON_OBJECT
Type of the JSON Object packet.
int sol_flow_packet_get_direction_vector_components(const struct sol_flow_packet *packet, double *x, double *y, double *z)
Retrieves the direction components contained in a Direction Vector packet.
int sol_flow_packet_get_composed_members(const struct sol_flow_packet *packet, struct sol_flow_packet ***children, uint16_t *len)
Retrieves the list of packets contained in the composed packet.
A packet type defines what's the content of a packet and how it's stored and retrieved.
Definition: sol-flow-packet.h:60
struct sol_flow_packet * sol_flow_packet_new_irange(const struct sol_irange *irange)
Creates a new packet of type Irange.
const struct sol_flow_packet_type * sol_flow_packet_type_from_string(const struct sol_str_slice type)
Returns the packet type from string.
const struct sol_flow_packet_type * SOL_FLOW_PACKET_TYPE_LOCATION
Type of the Location packet.