2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "hs-helper.h"
22 const char* evlist[] = {
30 REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uint16_t *out_id)
33 const char* tmp = afb_req_value (request, source);
38 long tmp_id = strtol(tmp,&endptr,10);
40 /* error check of range */
41 if( (tmp_id > UINT16_MAX) || (tmp_id < 0) )
50 *out_id = (uint16_t)tmp_id;
54 REQ_ERROR get_value_int16(const struct afb_req request, const char *source, int16_t *out_id)
57 const char* tmp = afb_req_value (request, source);
62 long tmp_id = strtol(tmp,&endptr,10);
64 /* error check of range */
65 if( (tmp_id > INT16_MAX) || (tmp_id < INT16_MIN) )
74 *out_id = (int16_t)tmp_id;
78 REQ_ERROR get_value_int32(const struct afb_req request, const char *source, int32_t *out_id)
81 const char* tmp = afb_req_value (request, source);
86 long tmp_id = strtol(tmp,&endptr,10);
88 /* error check of range */
89 if( (tmp_id > INT32_MAX) || (tmp_id < INT32_MIN) )
98 *out_id = (int32_t)tmp_id;
102 void hs_add_object_to_json_object(struct json_object* j_obj, int count,...)
105 va_start(args, count);
106 for(int i = 0; i < count; ++i )
108 char *key = va_arg(args, char*);
109 int value = va_arg(args, int);
110 json_object_object_add(j_obj, key, json_object_new_int((int32_t)value));
116 void hs_add_object_to_json_object_str(struct json_object* j_obj, int count,...)
119 va_start(args, count);
120 for(int i = 0; i < count; ++i )
122 char *key = va_arg(args, char*);
123 char *value = va_arg(args, char*);
124 json_object_object_add(j_obj, key, json_object_new_string(value));
131 void hs_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...)
134 va_start(args, count);
136 json_object_object_add(j_obj,"verb", json_object_new_string(verb_name));
138 for(int i = 0; i < count; ++i )
140 char *key = va_arg(args, char*);
141 int value = va_arg(args, int);
142 json_object_object_add(j_obj, key, json_object_new_int((int32_t)value));
148 int hs_search_event_name_index(const char* value)
150 size_t buf_size = 50;
151 size_t size = sizeof evlist / sizeof *evlist;
153 for(size_t i = 0 ; i < size ; ++i)
155 if(!strncmp(value, evlist[i], buf_size))