Skip to content

Commit e2188c7

Browse files
committed
feat : Add tvocHealthConcern cap helper sample example
Signed-off-by: stdk-scm <63764571+stdk-scm@users.noreply.github.com>
1 parent 4d146dc commit e2188c7

File tree

3 files changed

+167
-1
lines changed

3 files changed

+167
-1
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/* ***************************************************************************
2+
*
3+
* Copyright 2019-2020 Samsung Electronics All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
* either express or implied. See the License for the specific
15+
* language governing permissions and limitations under the License.
16+
*
17+
****************************************************************************/
18+
19+
#include <string.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
23+
#include "st_dev.h"
24+
#include "caps_tvocHealthConcern.h"
25+
26+
static int caps_tvocHealthConcern_attr_tvocHealthConcern_str2idx(const char *value)
27+
{
28+
int index;
29+
30+
for (index = 0; index < CAP_ENUM_MOTIONSENSOR_MOTION_VALUE_MAX; index++) {
31+
if (!strcmp(value, caps_helper_tvocHealthConcern.attr_tvocHealthConcern.values[index])) {
32+
return index;
33+
}
34+
}
35+
return -1;
36+
}
37+
38+
static const char *caps_tvocHealthConcern_get_tvocHealthConcern_value(caps_tvocHealthConcern_data_t *caps_data)
39+
{
40+
if (!caps_data) {
41+
printf("caps_data is NULL\n");
42+
return NULL;
43+
}
44+
return caps_data->tvocHealthConcern_value;
45+
}
46+
47+
static void caps_tvocHealthConcern_set_tvocHealthConcern_value(caps_tvocHealthConcern_data_t *caps_data, const char *value)
48+
{
49+
if (!caps_data) {
50+
printf("caps_data is NULL\n");
51+
return;
52+
}
53+
if (caps_data->tvocHealthConcern_value) {
54+
free(caps_data->tvocHealthConcern_value);
55+
}
56+
caps_data->tvocHealthConcern_value = strdup(value);
57+
}
58+
59+
static void caps_tvocHealthConcern_attr_tvocHealthConcern_send(caps_tvocHealthConcern_data_t *caps_data)
60+
{
61+
int sequence_no = -1;
62+
63+
if (!caps_data || !caps_data->handle) {
64+
printf("fail to get handle\n");
65+
return;
66+
}
67+
if (!caps_data->tvocHealthConcern_value) {
68+
printf("value is NULL\n");
69+
return;
70+
}
71+
72+
ST_CAP_SEND_ATTR_STRING(caps_data->handle,
73+
(char *)caps_helper_tvocHealthConcern.attr_tvocHealthConcern.name,
74+
caps_data->tvocHealthConcern_value,
75+
NULL,
76+
NULL,
77+
sequence_no);
78+
79+
if (sequence_no < 0)
80+
printf("fail to send tvocHealthConcern value\n");
81+
else
82+
printf("Sequence number return : %d\n", sequence_no);
83+
84+
}
85+
86+
87+
static void caps_tvocHealthConcern_init_cb(IOT_CAP_HANDLE *handle, void *usr_data)
88+
{
89+
caps_tvocHealthConcern_data_t *caps_data = usr_data;
90+
if (caps_data && caps_data->init_usr_cb)
91+
caps_data->init_usr_cb(caps_data);
92+
caps_tvocHealthConcern_attr_tvocHealthConcern_send(caps_data);
93+
}
94+
95+
caps_tvocHealthConcern_data_t *caps_tvocHealthConcern_initialize(IOT_CTX *ctx, const char *component, void *init_usr_cb, void *usr_data)
96+
{
97+
caps_tvocHealthConcern_data_t *caps_data = NULL;
98+
99+
caps_data = malloc(sizeof(caps_tvocHealthConcern_data_t));
100+
if (!caps_data) {
101+
printf("fail to malloc for caps_tvocHealthConcern_data\n");
102+
return NULL;
103+
}
104+
105+
memset(caps_data, 0, sizeof(caps_tvocHealthConcern_data_t));
106+
107+
caps_data->init_usr_cb = init_usr_cb;
108+
caps_data->usr_data = usr_data;
109+
110+
caps_data->get_tvocHealthConcern_value = caps_tvocHealthConcern_get_tvocHealthConcern_value;
111+
caps_data->set_tvocHealthConcern_value = caps_tvocHealthConcern_set_tvocHealthConcern_value;
112+
caps_data->attr_tvocHealthConcern_str2idx = caps_tvocHealthConcern_attr_tvocHealthConcern_str2idx;
113+
caps_data->attr_tvocHealthConcern_send = caps_tvocHealthConcern_attr_tvocHealthConcern_send;
114+
if (ctx) {
115+
caps_data->handle = st_cap_handle_init(ctx, component, caps_helper_tvocHealthConcern.id, caps_tvocHealthConcern_init_cb, caps_data);
116+
}
117+
if (!caps_data->handle) {
118+
printf("fail to init tvocHealthConcern handle\n");
119+
}
120+
121+
return caps_data;
122+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ***************************************************************************
2+
*
3+
* Copyright 2019-2020 Samsung Electronics All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
* either express or implied. See the License for the specific
15+
* language governing permissions and limitations under the License.
16+
*
17+
****************************************************************************/
18+
19+
#include "caps/iot_caps_helper_tvocHealthConcern.h"
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
typedef struct caps_tvocHealthConcern_data {
26+
IOT_CAP_HANDLE* handle;
27+
void *usr_data;
28+
void *cmd_data;
29+
30+
char *tvocHealthConcern_value;
31+
32+
const char *(*get_tvocHealthConcern_value)(struct caps_tvocHealthConcern_data *caps_data);
33+
void (*set_tvocHealthConcern_value)(struct caps_tvocHealthConcern_data *caps_data, const char *value);
34+
int (*attr_tvocHealthConcern_str2idx)(const char *value);
35+
void (*attr_tvocHealthConcern_send)(struct caps_tvocHealthConcern_data *caps_data);
36+
37+
void (*init_usr_cb)(struct caps_tvocHealthConcern_data *caps_data);
38+
} caps_tvocHealthConcern_data_t;
39+
40+
caps_tvocHealthConcern_data_t* caps_tvocHealthConcern_initialize(IOT_CTX *ctx, const char *component, void *init_usr_cb, void *usr_data);
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+

0 commit comments

Comments
 (0)