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-types.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 <stdint.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <float.h>
26 #include <sol-common-buildopts.h>
27 #include <sol-vector.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
58 #define _SOL_TYPE_CHECK(type, var, value) \
59  ({ type var = (value); var; })
60 
95 #define SOL_TYPE_CHECK(type, value) \
96  _SOL_TYPE_CHECK(type, __dummy_ ## __COUNTER__, (value))
97 
98 #ifndef SSIZE_MAX
99 
102 #define SSIZE_MAX LONG_MAX
103 #endif
104 
105 #ifndef SSIZE_MIN
106 
109 #define SSIZE_MIN LONG_MIN
110 #endif
111 
125 typedef struct sol_direction_vector {
126  double x;
127  double y;
128  double z;
129  double min;
130  double max;
132 
141 bool sol_direction_vector_eq(const struct sol_direction_vector *var0, const struct sol_direction_vector *var1);
142 
146 typedef struct sol_location {
147  double lat;
148  double lon;
149  double alt;
150 } sol_location;
151 
155 typedef struct sol_rgb {
156  uint32_t red;
157  uint32_t green;
158  uint32_t blue;
159  uint32_t red_max;
160  uint32_t green_max;
161  uint32_t blue_max;
162 } sol_rgb;
163 
172 bool sol_rgb_eq(const struct sol_rgb *var0, const struct sol_rgb *var1);
173 
182 int sol_rgb_set_max(struct sol_rgb *color, uint32_t max_value);
183 
187 typedef struct sol_drange {
188  double val;
189  double min;
190  double max;
191  double step;
192 } sol_drange;
193 
199 typedef struct sol_drange_spec {
200  double min;
201  double max;
202  double step;
204 
208 #define SOL_DRANGE_INIT() \
209  { \
210  .val = 0, \
211  .min = -DBL_MAX, \
212  .max = DBL_MAX, \
213  .step = DBL_MIN \
214  }
215 
221 #define SOL_DRANGE_INIT_VALUE(value_) \
222  { \
223  .val = value_, \
224  .min = -DBL_MAX, \
225  .max = DBL_MAX, \
226  .step = DBL_MIN \
227  }
228 
241 int sol_drange_add(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result);
242 
255 int sol_drange_div(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result);
256 
270 int sol_drange_mod(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result);
271 
284 int sol_drange_mul(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result);
285 
298 int sol_drange_sub(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result);
299 
300 
311 bool sol_drange_eq(const struct sol_drange *var0, const struct sol_drange *var1);
312 
322 int sol_drange_compose(const struct sol_drange_spec *spec, double value, struct sol_drange *result);
323 
327 typedef struct sol_irange {
328  int32_t val;
329  int32_t min;
330  int32_t max;
331  int32_t step;
332 } sol_irange;
333 
339 typedef struct sol_irange_spec {
340  int32_t min;
341  int32_t max;
342  int32_t step;
344 
348 #define SOL_IRANGE_INIT() \
349  { \
350  .val = 0, \
351  .min = INT32_MIN, \
352  .max = INT32_MAX, \
353  .step = 1 \
354  }
355 
361 #define SOL_IRANGE_INIT_VALUE(value_) \
362  { \
363  .val = value_, \
364  .min = INT32_MIN, \
365  .max = INT32_MAX, \
366  .step = 1 \
367  }
368 
381 int sol_irange_add(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result);
382 
395 int sol_irange_div(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result);
396 
410 int sol_irange_mod(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result);
411 
424 int sol_irange_mul(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result);
425 
438 int sol_irange_sub(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result);
439 
450 bool sol_irange_eq(const struct sol_irange *var0, const struct sol_irange *var1);
451 
461 int sol_irange_compose(const struct sol_irange_spec *spec, int32_t value, struct sol_irange *result);
462 
463 struct sol_blob_type;
464 
468 typedef struct sol_blob {
469  const struct sol_blob_type *type;
470  struct sol_blob *parent;
471  void *mem;
472  size_t size;
473  uint16_t refcnt;
474 } sol_blob;
475 
482 typedef struct sol_blob_type {
483 #ifndef SOL_NO_API_VERSION
484 #define SOL_BLOB_TYPE_API_VERSION (1)
485  uint16_t api_version;
486  uint16_t sub_api;
487 #endif
488  void (*free)(struct sol_blob *blob);
489 } sol_blob_type;
490 
496 extern const struct sol_blob_type SOL_BLOB_TYPE_DEFAULT;
497 
507 extern const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE_DATA;
508 
515 extern const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE;
516 
527 struct sol_blob *sol_blob_new(const struct sol_blob_type *type, struct sol_blob *parent, const void *mem, size_t size);
528 
539 int sol_blob_setup(struct sol_blob *blob, const struct sol_blob_type *type, const void *mem, size_t size);
540 
548 struct sol_blob *sol_blob_ref(struct sol_blob *blob);
549 
557 void sol_blob_unref(struct sol_blob *blob);
558 
565 void sol_blob_set_parent(struct sol_blob *blob, struct sol_blob *parent);
566 
578 static inline struct sol_blob *
579 sol_blob_new_dup(const void *mem, size_t size)
580 {
581  struct sol_blob *blob;
582  void *v;
583 
584  if (!mem)
585  return NULL;
586 
587  v = malloc(size);
588  if (!v)
589  return NULL;
590 
591  memcpy(v, mem, size);
592 
593  blob = sol_blob_new(&SOL_BLOB_TYPE_DEFAULT, NULL, v, size);
594  if (!blob)
595  goto fail;
596 
597  return blob;
598 
599 fail:
600  free(v);
601  return NULL;
602 }
603 
608 #define SOL_BLOB_NEW_DUP(mem_) sol_blob_new_dup((&mem_), sizeof(mem_))
609 
617 static inline struct sol_blob *
618 sol_blob_new_dup_str(const char *str)
619 {
620  if (!str)
621  return NULL;
622 
623  return sol_blob_new_dup(str, strlen(str) + 1);
624 }
625 
629 typedef struct sol_key_value {
630  const char *key;
631  const char *value;
632 } sol_key_value;
633 
638 #ifdef __cplusplus
639 }
640 #endif
struct sol_blob_type sol_blob_type
Data type describing a blob type.
int sol_drange_add(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result)
Adds the double ranges var0 and var1 and stores the result in result.
int sol_rgb_set_max(struct sol_rgb *color, uint32_t max_value)
Set a maximum value for all components of a RGB color.
void(* free)(struct sol_blob *blob)
Callback to free an instance.
Definition: sol-types.h:488
Data type to describe <key, value> pairs of strings.
Definition: sol-types.h:629
struct sol_blob sol_blob
Data type describing the default blob implementation.
double alt
Altitude.
Definition: sol-types.h:149
int32_t step
Range step.
Definition: sol-types.h:342
static struct sol_blob * sol_blob_new_dup(const void *mem, size_t size)
Creates a new blob duplicating target memory,.
Definition: sol-types.h:579
uint32_t blue_max
Blue component maximum value.
Definition: sol-types.h:161
uint32_t green_max
Green component maximum value.
Definition: sol-types.h:160
Data type describing a blob type.
Definition: sol-types.h:482
int32_t max
Range maximum value.
Definition: sol-types.h:330
int sol_irange_div(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result)
Divides the integer range var0 by var1 and stores the result in result.
int sol_drange_div(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result)
Divides the double range var0 by var1 and stores the result in result.
uint32_t red_max
Red component maximum value.
Definition: sol-types.h:159
double max
Range maximum value.
Definition: sol-types.h:190
double max
Range maximum value.
Definition: sol-types.h:201
const char * value
Pair's value.
Definition: sol-types.h:631
double min
Range minimum value.
Definition: sol-types.h:189
int32_t max
Range maximum value.
Definition: sol-types.h:341
int sol_irange_sub(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result)
Subtracts the integer range var1 from var0 and stores the result in result.
double val
Current value.
Definition: sol-types.h:188
uint32_t blue
Blue component.
Definition: sol-types.h:158
uint16_t refcnt
Blob reference counter.
Definition: sol-types.h:473
int sol_drange_mul(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result)
Multiplies the double ranges var0 and var1 and stores the result in result.
Data type describing a Double range.
Definition: sol-types.h:187
int sol_blob_setup(struct sol_blob *blob, const struct sol_blob_type *type, const void *mem, size_t size)
Setup a blob structure with the given parameters.
int sol_irange_mul(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result)
Multiplies the integer ranges var0 and var1 and stores the result in result.
uint32_t red
Red component.
Definition: sol-types.h:156
struct sol_location sol_location
Data type to describe a location.
double step
Range step.
Definition: sol-types.h:202
struct sol_blob * sol_blob_new(const struct sol_blob_type *type, struct sol_blob *parent, const void *mem, size_t size)
Creates a new blob instance of the given type type.
const struct sol_blob_type SOL_BLOB_TYPE_DEFAULT
Blob type object for the default implementation.
bool sol_rgb_eq(const struct sol_rgb *var0, const struct sol_rgb *var1)
Checks the ranges of var0 and var1 for equality.
struct sol_blob * sol_blob_ref(struct sol_blob *blob)
Increments the reference counter of the given blob.
int sol_drange_sub(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result)
Subtracts the double range var1 from var0 and stores the result in result.
static struct sol_buffer value
Definition: server.c:42
Data type to describe a direction vector.
Definition: sol-types.h:125
double x
X coordinate.
Definition: sol-types.h:126
const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE
Blob type object for the nofree implementation.
static struct sol_blob * sol_blob_new_dup_str(const char *str)
Creates a new blob duplicating target NUL terminated string.
Definition: sol-types.h:618
struct sol_blob * parent
Pointer to the parent Blob.
Definition: sol-types.h:470
uint16_t sub_api
Type API version.
Definition: sol-types.h:486
Data type describing Integer ranges.
Definition: sol-types.h:327
const char * key
Pair's key.
Definition: sol-types.h:630
void * mem
Blob data.
Definition: sol-types.h:471
bool sol_direction_vector_eq(const struct sol_direction_vector *var0, const struct sol_direction_vector *var1)
Checks the ranges of var0 and var1 for equality.
Data type to describe a location.
Definition: sol-types.h:146
struct sol_drange sol_drange
Data type describing a Double range.
Data type to describe a RGB color.
Definition: sol-types.h:155
double lat
Latitude.
Definition: sol-types.h:147
int32_t val
Current value.
Definition: sol-types.h:328
bool sol_irange_eq(const struct sol_irange *var0, const struct sol_irange *var1)
Checks the integer ranges var0 and var1 for equality.
int32_t step
Range step.
Definition: sol-types.h:331
double max
Maximum value of a coordinate for all axis.
Definition: sol-types.h:130
Data type describing the default blob implementation.
Definition: sol-types.h:468
struct sol_rgb sol_rgb
Data type to describe a RGB color.
int sol_drange_mod(const struct sol_drange *var0, const struct sol_drange *var1, struct sol_drange *result)
Calculates the module of the double range var0 by var1 and stores the result in result.
struct sol_drange_spec sol_drange_spec
Data type describing a spec for Double ranges.
bool sol_drange_eq(const struct sol_drange *var0, const struct sol_drange *var1)
Checks the double ranges var0 and var1 for equality.
int sol_irange_compose(const struct sol_irange_spec *spec, int32_t value, struct sol_irange *result)
Initializes result with the given spec and value.
double lon
Longitude.
Definition: sol-types.h:148
struct sol_irange sol_irange
Data type describing Integer ranges.
double step
Range step.
Definition: sol-types.h:191
size_t size
Blob size.
Definition: sol-types.h:472
int32_t min
Range minimum value.
Definition: sol-types.h:340
uint16_t api_version
API version.
Definition: sol-types.h:485
double min
Range minimum value.
Definition: sol-types.h:200
int sol_irange_mod(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result)
Calculates the module of the integer range var0 by var1 and stores the result in result.
int sol_drange_compose(const struct sol_drange_spec *spec, double value, struct sol_drange *result)
Initializes result with the given spec and value.
double min
Minimum value of a coordinate for all axis.
Definition: sol-types.h:129
Data type describing a spec for Integer ranges.
Definition: sol-types.h:339
struct sol_key_value sol_key_value
Data type to describe <key, value> pairs of strings.
These are routines that Soletta provides for its vector implementation.
double z
Z coordinate.
Definition: sol-types.h:128
Data type describing a spec for Double ranges.
Definition: sol-types.h:199
double y
Y coordinate.
Definition: sol-types.h:127
struct sol_irange_spec sol_irange_spec
Data type describing a spec for Integer ranges.
const struct sol_blob_type * type
Blob type.
Definition: sol-types.h:469
int32_t min
Range minimum value.
Definition: sol-types.h:329
const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE_DATA
Blob type object for the nofree implementation.
struct sol_direction_vector sol_direction_vector
Data type to describe a direction vector.
void sol_blob_set_parent(struct sol_blob *blob, struct sol_blob *parent)
Set the blob's parent.
int sol_irange_add(const struct sol_irange *var0, const struct sol_irange *var1, struct sol_irange *result)
Adds the integer ranges var0 and var1 and stores the result in result.
uint32_t green
Green component.
Definition: sol-types.h:157
void sol_blob_unref(struct sol_blob *blob)
Decreases the reference counter of the given blob.