diff --git a/BuiltinServices/Expression.c b/BuiltinServices/Expression.c index a3c0365..2ad60a9 100644 --- a/BuiltinServices/Expression.c +++ b/BuiltinServices/Expression.c @@ -42,8 +42,8 @@ variant_t* process_template_impl(struct service_method_t* method, va_list args) if(NULL != service_stack) { - variant_t* token_table_var = stack_pop_front(service_stack->stack); - hash_table_t* token_table = (hash_table_t*)variant_get_ptr(token_table_var); + //variant_t* token_table_var = stack_pop_front(service_stack->stack); + hash_table_t* token_table = (hash_table_t*)service_stack->data_storage;//variant_get_ptr(token_table_var); // Replace all tokens starting with "$" with matching values from token table char* template = (char*)variant_get_string(template_var); @@ -111,7 +111,7 @@ variant_t* process_template_impl(struct service_method_t* method, va_list args) ++tokens; } - variant_free(token_table_var); + //variant_free(token_table_var); } // Remove last space... diff --git a/Makefile b/Makefile index c5ae2b0..9e2d266 100644 --- a/Makefile +++ b/Makefile @@ -30,10 +30,10 @@ COMMON_OBJ=$(OUTDIR)/Conditional.o $(OUTDIR)/Expression.o \ $(OUTDIR)/cli_sensor.o $(OUTDIR)/cli_service.o \ $(OUTDIR)/command_class.o $(OUTDIR)/command_parser.o \ $(OUTDIR)/config.o $(OUTDIR)/data_callbacks.o \ - $(OUTDIR)/device_callbacks.o $(OUTDIR)/event_manager.o \ - $(OUTDIR)/http_server.o $(OUTDIR)/logging_modules.o \ - $(OUTDIR)/operator.o $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o \ - $(OUTDIR)/scene.o $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ + $(OUTDIR)/device_callbacks.o $(OUTDIR)/http_server.o \ + $(OUTDIR)/logging_modules.o $(OUTDIR)/operator.o \ + $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o $(OUTDIR)/scene.o \ + $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ $(OUTDIR)/script_action_handler.o $(OUTDIR)/service_manager.o \ $(OUTDIR)/user_manager.o $(OUTDIR)/vty_io.o \ $(OUTDIR)/zwave-automation-engine.o @@ -45,10 +45,10 @@ ALL_OBJ=$(OUTDIR)/Conditional.o $(OUTDIR)/Expression.o \ $(OUTDIR)/cli_sensor.o $(OUTDIR)/cli_service.o \ $(OUTDIR)/command_class.o $(OUTDIR)/command_parser.o \ $(OUTDIR)/config.o $(OUTDIR)/data_callbacks.o \ - $(OUTDIR)/device_callbacks.o $(OUTDIR)/event_manager.o \ - $(OUTDIR)/http_server.o $(OUTDIR)/logging_modules.o \ - $(OUTDIR)/operator.o $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o \ - $(OUTDIR)/scene.o $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ + $(OUTDIR)/device_callbacks.o $(OUTDIR)/http_server.o \ + $(OUTDIR)/logging_modules.o $(OUTDIR)/operator.o \ + $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o $(OUTDIR)/scene.o \ + $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ $(OUTDIR)/script_action_handler.o $(OUTDIR)/service_manager.o \ $(OUTDIR)/user_manager.o $(OUTDIR)/vty_io.o \ $(OUTDIR)/zwave-automation-engine.o -l:libreadline.a -l:libncurses.a \ @@ -107,10 +107,10 @@ COMMON_OBJ=$(OUTDIR)/Conditional.o $(OUTDIR)/Expression.o \ $(OUTDIR)/cli_sensor.o $(OUTDIR)/cli_service.o \ $(OUTDIR)/command_class.o $(OUTDIR)/command_parser.o \ $(OUTDIR)/config.o $(OUTDIR)/data_callbacks.o \ - $(OUTDIR)/device_callbacks.o $(OUTDIR)/event_manager.o \ - $(OUTDIR)/http_server.o $(OUTDIR)/logging_modules.o \ - $(OUTDIR)/operator.o $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o \ - $(OUTDIR)/scene.o $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ + $(OUTDIR)/device_callbacks.o $(OUTDIR)/http_server.o \ + $(OUTDIR)/logging_modules.o $(OUTDIR)/operator.o \ + $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o $(OUTDIR)/scene.o \ + $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ $(OUTDIR)/script_action_handler.o $(OUTDIR)/service_manager.o \ $(OUTDIR)/user_manager.o $(OUTDIR)/vty_io.o \ $(OUTDIR)/zwave-automation-engine.o @@ -122,10 +122,10 @@ ALL_OBJ=$(OUTDIR)/Conditional.o $(OUTDIR)/Expression.o \ $(OUTDIR)/cli_sensor.o $(OUTDIR)/cli_service.o \ $(OUTDIR)/command_class.o $(OUTDIR)/command_parser.o \ $(OUTDIR)/config.o $(OUTDIR)/data_callbacks.o \ - $(OUTDIR)/device_callbacks.o $(OUTDIR)/event_manager.o \ - $(OUTDIR)/http_server.o $(OUTDIR)/logging_modules.o \ - $(OUTDIR)/operator.o $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o \ - $(OUTDIR)/scene.o $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ + $(OUTDIR)/device_callbacks.o $(OUTDIR)/http_server.o \ + $(OUTDIR)/logging_modules.o $(OUTDIR)/operator.o \ + $(OUTDIR)/parser_dfa.o $(OUTDIR)/resolver.o $(OUTDIR)/scene.o \ + $(OUTDIR)/scene_action.o $(OUTDIR)/scene_manager.o \ $(OUTDIR)/script_action_handler.o $(OUTDIR)/service_manager.o \ $(OUTDIR)/user_manager.o $(OUTDIR)/vty_io.o \ $(OUTDIR)/zwave-automation-engine.o -l:libreadline.a -l:libncurses.a \ diff --git a/builtin_service.c b/builtin_service.c index d03fce3..4ec4cdf 100644 --- a/builtin_service.c +++ b/builtin_service.c @@ -4,6 +4,8 @@ DECLARE_LOGGER(BuiltinService) +static hash_table_t* service_stack_table; + builtin_service_t* builtin_service_create(hash_table_t* service_table, const char* name, const char* description) { builtin_service_t* new_service = calloc(1, sizeof(builtin_service_t)); @@ -34,25 +36,32 @@ void service_stack_delete(void* arg) service_stack_t* s = (service_stack_t*)arg; free(s->service_name); stack_free(s->stack); + variant_hash_free(s->data_storage); free(s); } void builtin_service_stack_create(const char* service_name) { + uint32_t key = crc32(0, service_name, strlen(service_name)); + if(NULL == service_stack_table) { service_stack_table = variant_hash_init(); } + + if(NULL != variant_hash_get(service_stack_table, key)) + { + return; + } service_stack_t* s = malloc(sizeof(service_stack_t)); s->service_name = strdup(service_name); s->stack = stack_create(); - - uint32_t key = crc32(0, service_name, strlen(service_name)); + s->data_storage = variant_hash_init(); variant_hash_insert(service_stack_table, key, variant_create_ptr(DT_PTR, s, service_stack_delete)); } -void builtin_service_stack_add(const char* service_name, variant_t* data) +void builtin_service_stack_add(const char* service_name, uint32_t value_key, variant_t* value) { uint32_t key = crc32(0, service_name, strlen(service_name)); variant_t* stack_var = variant_hash_get(service_stack_table, key); @@ -60,7 +69,7 @@ void builtin_service_stack_add(const char* service_name, variant if(NULL != stack_var) { service_stack_t* s = (service_stack_t*)variant_get_ptr(stack_var); - stack_push_front(s->stack, data); + variant_hash_insert(s->data_storage, value_key, value); } } @@ -77,9 +86,12 @@ service_stack_t* builtin_service_stack_get(const char* service_name) return NULL; } -void builtin_service_stack_clear(const char* service_name) +void builtin_service_stack_clear() { - uint32_t key = crc32(0, service_name, strlen(service_name)); - variant_hash_remove(service_stack_table, key); + if(NULL != service_stack_table) + { + variant_hash_free(service_stack_table); + service_stack_table = NULL; + } } diff --git a/builtin_service.h b/builtin_service.h index 519e292..c317f3c 100644 --- a/builtin_service.h +++ b/builtin_service.h @@ -19,14 +19,13 @@ typedef struct service_stack_t { char* service_name; variant_stack_t* stack; + hash_table_t* data_storage; } service_stack_t; -static hash_table_t* service_stack_table; - builtin_service_t* builtin_service_create(hash_table_t* service_table, const char* name, const char* description); void builtin_service_add_method(builtin_service_t* service, const char* name, const char* help, int args, variant_t* (*eval_callback)(struct service_method_t*, va_list)); void builtin_service_stack_create(const char* service_name); -void builtin_service_stack_add(const char* service_name, variant_t* data); +void builtin_service_stack_add(const char* service_name, uint32_t value_key, variant_t* value); service_stack_t* builtin_service_stack_get(const char* service_name); -void builtin_service_stack_clear(const char* service_name); +void builtin_service_stack_clear(); diff --git a/cli_scene.c b/cli_scene.c index c338720..1eaed7f 100644 --- a/cli_scene.c +++ b/cli_scene.c @@ -49,7 +49,7 @@ bool cmd_scene_disable(vty_t* vty, variant_stack_t* params); void show_scene_helper(scene_t* scene, void* arg); void show_scene_action_helper(action_t* action, void* arg); void show_scene_action_env_helper(env_t* env, void* arg); -void show_scene_action_token_helper(env_t* env, void* arg); +void show_scene_action_token_helper(method_stack_item_t* env, void* arg); USING_LOGGER(Scene); @@ -91,8 +91,8 @@ cli_command_t scene_action_command_list[] = { }; cli_command_t scene_template_command_list[] = { - {"template-token WORD value LINE", cmd_add_action_token, "Add token value to command action"}, - {"no template-token WORD", cmd_del_action_token, "Remove token value from command action"}, + {"argument class WORD name WORD value LINE", cmd_add_action_token, "Add argument to command action"}, + {"no argument class WORD name WORD", cmd_del_action_token, "Remove argument from command action"}, //{"end", cmd_exit_node, "Exit environment configuration"}, {NULL, NULL, NULL} }; @@ -230,11 +230,11 @@ bool cmd_add_action_environment(vty_t* vty, variant_stack_t* params) bool cmd_add_action_token(vty_t* vty, variant_stack_t* params) { char command[1024] = {0}; - cli_assemble_line(params, 3, command); + cli_assemble_line(params, 6, command); scene_t* scene = scene_manager_get_scene(scene_node->context); action_t* action = scene_get_action(scene, scene_template_token_node->context); - scene_action_add_environment(action, - variant_get_string(stack_peek_at(params, 1)), + scene_action_add_method_stack_item(action, variant_get_string(stack_peek_at(params, 2)), + variant_get_string(stack_peek_at(params, 4)), command); } @@ -243,7 +243,7 @@ bool cmd_del_action_token(vty_t* vty, variant_stack_t* params) scene_t* scene = scene_manager_get_scene(scene_node->context); action_t* action = scene_get_action(scene, scene_template_token_node->context); - scene_action_del_environment(action, variant_get_string(stack_peek_at(params, 2))); + scene_action_del_method_stack_item(action, variant_get_string(stack_peek_at(params, 3)), variant_get_string(stack_peek_at(params, 5))); } bool cmd_delete_scene_action_script(vty_t* vty, variant_stack_t* params) @@ -409,7 +409,7 @@ void show_scene_action_helper(action_t* action, void* arg) break; case A_COMMAND: vty_write(vty, " action command %s\n", action->path); - scene_action_for_each_environment(action, show_scene_action_token_helper, vty); + scene_action_for_each_method_stack_item(action, show_scene_action_token_helper, vty); vty_write(vty, " !\n"); break; case A_SCENE: @@ -435,8 +435,8 @@ void show_scene_action_env_helper(env_t* env, void* arg) vty_write(vty, " environment %s value %s\n", env->name, env->value); } -void show_scene_action_token_helper(env_t* env, void* arg) +void show_scene_action_token_helper(method_stack_item_t* env, void* arg) { vty_t* vty = (vty_t*)arg; - vty_write(vty, " template-token %s value %s\n", env->name, env->value); + vty_write(vty, " argument class %s name %s value %s\n", env->stack_name, env->name, env->value); } diff --git a/event_manager.c b/event_manager.c index e228fb8..23fd178 100644 --- a/event_manager.c +++ b/event_manager.c @@ -20,7 +20,7 @@ void event_received(int sig); //pthread_cond_t event_received_condition; //pthread_mutex_t event_received_cond_mutex; -sem_t event_semaphore; +extern sem_t event_semaphore; DECLARE_LOGGER(Event) diff --git a/libZaeUtil/event.c b/libZaeUtil/event.c index 4ea6767..a99d9ff 100644 --- a/libZaeUtil/event.c +++ b/libZaeUtil/event.c @@ -2,12 +2,38 @@ #include #include #include +#include +#include "logger.h" variant_stack_t* event_list; +variant_stack_t* registered_handlers; + pthread_mutex_t event_list_mutex; +sem_t event_semaphore; void event_destroy(void* arg); +DECLARE_LOGGER(Event) + +void* event_handle_event(void* arg); + +void event_manager_init() +{ + LOG_ADVANCED(Event, "Initializing event manager"); + event_list = stack_create(); + registered_handlers = stack_create(); + + // Init the semaphore + sem_init(&event_semaphore, 0, 0); + + // Now create event thread + pthread_t event_thread; + pthread_create(&event_thread, NULL, event_handle_event, NULL); + pthread_detach(event_thread); + + LOG_ADVANCED(Event, "Event manager initialized"); +} + event_t* event_create(int source_id, variant_t* data) { event_t* new_event = (event_t*)malloc(sizeof(event_t)); @@ -28,7 +54,8 @@ void event_post(event_t* event) pthread_mutex_lock(&event_list_mutex); stack_push_back(event_list, variant_create_ptr(DT_PTR, event, NULL)); pthread_mutex_unlock(&event_list_mutex); - raise(SIGUSR1); + sem_post(&event_semaphore); + //raise(SIGUSR1); } event_t* event_receive() @@ -40,3 +67,28 @@ event_t* event_receive() free(event_variant); return event; } + +void event_register_handler(void (*event_handler)(event_t*)) +{ + stack_push_back(registered_handlers, variant_create_ptr(DT_PTR, event_handler, NULL)); +} + +void* event_handle_event(void* arg) +{ + while(true) + { + sem_wait(&event_semaphore); + LOG_DEBUG(Event, "Event received"); + event_t* event = event_receive(); + LOG_ADVANCED(Event, "Received event id %d", event->source_id); + + stack_for_each(registered_handlers, handler_var) + { + void (*event_handler)(event_t*); + + event_handler = (void(*)(event_t*))variant_get_ptr(handler_var); + event_handler(event); + } + event_delete(event); + } +} diff --git a/libZaeUtil/event.h b/libZaeUtil/event.h index 978097a..1ba9606 100644 --- a/libZaeUtil/event.h +++ b/libZaeUtil/event.h @@ -27,6 +27,8 @@ typedef struct service_event_data_t char* data; } service_event_data_t; +void event_manager_init(); +void event_register_handler(void (*event_handler)(event_t*)); event_t* event_create(int source_id, variant_t* data); void event_delete(event_t* event); void event_post(event_t* event); diff --git a/libZaeUtil/hash.c b/libZaeUtil/hash.c index b84b49c..9d55d52 100644 --- a/libZaeUtil/hash.c +++ b/libZaeUtil/hash.c @@ -419,3 +419,9 @@ variant_t* variant_hash_iterator_value(hash_iterator_t* it) { return it->hash_table->node_array[it->index]->data; } + +uint32_t variant_hash_iterator_key(hash_iterator_t* it) +{ + return it->hash_table->node_array[it->index]->key; +} + diff --git a/libZaeUtil/hash.h b/libZaeUtil/hash.h index 329b2fa..702a39d 100644 --- a/libZaeUtil/hash.h +++ b/libZaeUtil/hash.h @@ -57,3 +57,5 @@ hash_iterator_t* variant_hash_end(hash_table_t* hash_table); bool variant_hash_iterator_is_end(hash_iterator_t* it); hash_iterator_t* variant_hash_iterator_next(hash_iterator_t* it); variant_t* variant_hash_iterator_value(hash_iterator_t* it); +uint32_t variant_hash_iterator_key(hash_iterator_t* it); + diff --git a/scene_action.c b/scene_action.c index b8e77fd..fca392a 100644 --- a/scene_action.c +++ b/scene_action.c @@ -24,6 +24,16 @@ void environment_delete(void* arg) free(env); } +void method_stack_delete(void* arg) +{ + method_stack_item_t* item = (method_stack_item_t*)arg; + + free(item->stack_name); + free(item->name); + free(item->value); + free(item); +} + /*env_t* create_environment(struct json_object* record) { env_t* new_env = (env_t*)malloc(sizeof(env_t)); @@ -86,53 +96,38 @@ void scene_action_del_environment(action_t* action, const char* name) } } -/*action_t* scene_action_create_old(struct json_object* record) +void scene_action_add_method_stack_item(action_t* action, const char* stack_name, const char* name, const char* value) { - action_t* new_action = (action_t*)malloc(sizeof(action_t)); - new_action->environment = stack_create(); - - json_object_object_foreach(record, key, val) + stack_for_each(action->environment, env_variant) { - if(strcmp(key, "url") == 0) + method_stack_item_t* env = (method_stack_item_t*)variant_get_ptr(env_variant); + if(strcmp(env->name, name) == 0 && strcmp(env->stack_name, stack_name) == 0) { - LOG_DEBUG(Scene, "New_action URL: %s", json_object_get_string(val)); - new_action->url = strdup(json_object_get_string(val)); - - char scheme[10] = {0}; - char path[100] = {0}; + stack_remove(action->environment, env_variant); + break; + } + } - // cut the schema part from thw path - sscanf(new_action->url, "%9[^:]://%99[^:]", scheme, path); - new_action->path = strdup(path); + method_stack_item_t* new_env = (method_stack_item_t*)malloc(sizeof(method_stack_item_t)); + new_env->stack_name = strdup(stack_name); + new_env->name = strdup(name); + new_env->value = strdup(value); + stack_push_back(action->environment, variant_create_ptr(DT_PTR, new_env, &method_stack_delete)); +} - if(strcmp(scheme, "file") == 0) - { - new_action->type = A_SCRIPT; - } - else if(strcmp(scheme, "scene") == 0) - { - new_action->type = A_SCENE; - } - else if(strcmp(scheme, "cmd") == 0) - { - new_action->type = A_COMMAND; - } - } - else if(strcmp(key, "environment") == 0) +void scene_action_del_method_stack_item(action_t* action, const char* stack_name, const char* name) +{ + stack_for_each(action->environment, env_variant) + { + method_stack_item_t* env = (method_stack_item_t*)variant_get_ptr(env_variant); + if(strcmp(env->name, name) == 0 && strcmp(env->stack_name, stack_name) == 0) { - int num_environment = json_object_array_length(val); - - for(int i = 0; i < num_environment; i++) - { - struct json_object* record = json_object_array_get_idx(val, i); - env_t* new_env = create_environment(record); - stack_push_back(new_action->environment, variant_create_ptr(DT_PTR, new_env, &environment_delete)); - } + stack_remove(action->environment, env_variant); + variant_free(env_variant); + break; } } - - return new_action; -}*/ +} void scene_action_exec(action_t* action) { @@ -207,10 +202,12 @@ void scene_action_exec_command(action_t* action) if(action->environment->count > 0) { // Compile all environment and prepare token table - hash_table_t* token_table = variant_hash_init(); + //hash_table_t* token_table = variant_hash_init(); stack_for_each(action->environment, env_variant) { - env_t* env = (env_t*)variant_get_ptr(env_variant); + method_stack_item_t* env = (method_stack_item_t*)variant_get_ptr(env_variant); + builtin_service_stack_create(env->stack_name); + bool isOk; variant_stack_t* compiled_value = command_parser_compile_expression(env->value, &isOk); @@ -226,16 +223,15 @@ void scene_action_exec_command(action_t* action) { uint32_t key = crc32(0, env->name, strlen(env->name)); //printf("Inserting value with name %s and key %u, and val: %s\n", env->name, key, variant_get_string(env_value)); - - variant_hash_insert(token_table, key, env_value); + builtin_service_stack_add(env->stack_name, key, env_value); } } stack_free(compiled_value); } - builtin_service_stack_create("Expression.ProcessTemplate"); - builtin_service_stack_add("Expression.ProcessTemplate", variant_create_ptr(DT_PTR, token_table, variant_hash_free_void)); + //builtin_service_stack_create("Expression.ProcessTemplate"); + //builtin_service_stack_add("Expression.ProcessTemplate", variant_create_ptr(DT_PTR, token_table, variant_hash_free_void)); } variant_t* result = command_parser_execute_expression(compiled); @@ -245,7 +241,7 @@ void scene_action_exec_command(action_t* action) variant_free(result); } - builtin_service_stack_clear("Expression.ProcessTemplate"); + builtin_service_stack_clear(); } stack_free(compiled); @@ -310,3 +306,12 @@ void scene_action_for_each_environment(action_t* action, void (*visitor)(env_ } } +void scene_action_for_each_method_stack_item(action_t* action, void (*visitor)(method_stack_item_t*, void*), void* arg) +{ + stack_for_each(action->environment, env_variant) + { + method_stack_item_t* env = (method_stack_item_t*)variant_get_ptr(env_variant); + visitor(env, arg); + } +} + diff --git a/scene_action.h b/scene_action.h index e9f96e7..01e3e12 100644 --- a/scene_action.h +++ b/scene_action.h @@ -15,6 +15,13 @@ typedef struct env_t variant_stack_t* compiled_value; } env_t; +typedef struct method_stack_item_t +{ + char* stack_name; + char* name; + char* value; +} method_stack_item_t; + typedef enum ActionType_e { A_SCRIPT, @@ -35,8 +42,12 @@ typedef struct action_t action_t* scene_action_create(ActionType type, const char* record); void scene_action_add_environment(action_t* action, const char* name, const char* value); void scene_action_del_environment(action_t* action, const char* name); -//action_t* scene_action_create_old(struct json_object* record); + +void scene_action_add_method_stack_item(action_t* action, const char* stack_name, const char* name, const char* value); +void scene_action_del_method_stack_item(action_t* action, const char* stack_name, const char* name); + void scene_action_exec(action_t* action); void scene_action_delete(void* arg); void scene_action_for_each_environment(action_t* action, void (*visitor)(env_t*, void*), void* arg); +void scene_action_for_each_method_stack_item(action_t* action, void (*visitor)(method_stack_item_t*, void*), void* arg); diff --git a/scene_manager.c b/scene_manager.c index 6fde2af..dc19201 100644 --- a/scene_manager.c +++ b/scene_manager.c @@ -7,6 +7,7 @@ #include "logger.h" #include "variant_types.h" #include "service_manager.h" +#include #include #include @@ -20,6 +21,7 @@ void scene_manager_init() LOG_ADVANCED(Scene, "Initializing scene manager"); //scene_list = stack_create(); scene_table = variant_hash_init(); + event_register_handler(scene_manager_on_event); } void scene_manager_add_scene(const char* name) diff --git a/service_manager.c b/service_manager.c index 0974b27..5250abe 100644 --- a/service_manager.c +++ b/service_manager.c @@ -9,6 +9,7 @@ #include "variant_types.h" #include "cli_logger.h" #include "cli_service.h" +#include #include #include @@ -84,6 +85,8 @@ void service_manager_init(const char* service_dir) closedir(dp); LOG_ADVANCED(ServiceManager, "Service manager initialized with %d services", service_table->count); + + event_register_handler(service_manager_on_event); } else { diff --git a/services/SMS/SMS.c b/services/SMS/SMS.c index 05d89a8..3257520 100644 --- a/services/SMS/SMS.c +++ b/services/SMS/SMS.c @@ -33,7 +33,9 @@ void send_sms_visitor(const char* phone, void* arg) char sms_address[128] = {0}; snprintf(sms_address, 127, "%s%s", phone, data->sms_gw); - variant_t* ret = service_call_method("Mail", "SendTo", data->message, variant_create_string(sms_address)); + variant_t* sms_addr_var = variant_create_string(sms_address); + variant_t* ret = service_call_method("Mail", "SendTo", data->message, sms_addr_var); + free(sms_addr_var); variant_free(ret); } diff --git a/zwave-automation-engine.c b/zwave-automation-engine.c index ffc8f33..7733465 100644 --- a/zwave-automation-engine.c +++ b/zwave-automation-engine.c @@ -6,7 +6,7 @@ #include "command_parser.h" #include "scene_manager.h" #include "service_manager.h" -#include "event_manager.h" +//#include "event_manager.h" #include "logger.h" #include "cli_commands.h" #include "cli_auth.h" @@ -28,6 +28,7 @@ #include "user_manager.h" #include "http_server.h" #include "builtin_service_manager.h" +#include #define DEFAULT_PORT 9231 @@ -226,12 +227,12 @@ int main (int argc, char *argv[]) if(r == NoError) { LOG_ADVANCED(General, "Zway API initialized"); + event_manager_init(); resolver_init(); cli_init(); service_manager_init(global_config.services_prefix); scene_manager_init(); - event_manager_init(); user_manager_init(); builtin_service_manager_init(); diff --git a/zwave-automation-engine.vpj b/zwave-automation-engine.vpj index 2109ba1..0d49c1b 100644 --- a/zwave-automation-engine.vpj +++ b/zwave-automation-engine.vpj @@ -351,8 +351,6 @@ - -