Skip to content

Commit

Permalink
Merge pull request #163 from ezloteam/EZPI-466_fixing_buffer_release_…
Browse files Browse the repository at this point in the history
…failed

Ezpi 466 fixing buffer release failed
  • Loading branch information
lomasSE89 authored Aug 21, 2024
2 parents b6283ca + c841141 commit db4ed23
Show file tree
Hide file tree
Showing 13 changed files with 2,241 additions and 268 deletions.
14 changes: 11 additions & 3 deletions ezlopi-cloud/ezlopi-cloud-items/ezlopi_cloud_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "ezlopi_service_webprov.h"

static cJSON* ezlopi_device_create_item_table_from_prop(l_ezlopi_device_t *device_prop, l_ezlopi_item_t* item_properties)
static cJSON* ezlopi_device_create_item_table_from_prop(l_ezlopi_device_t* device_prop, l_ezlopi_item_t* item_properties)
{
cJSON* cj_item_properties = cJSON_CreateObject(__FUNCTION__);
if (cj_item_properties)
Expand Down Expand Up @@ -171,8 +171,11 @@ void items_set_value_v3(cJSON* cj_request, cJSON* cj_response)
}
}

#if 0
void items_update_v3(cJSON* cj_request, cJSON* cj_response)
{
bool _break_loop = false;

cJSON* cjson_params = cJSON_GetObjectItem(__FUNCTION__, cj_request, ezlopi_params_str);
if (cjson_params)
{
Expand Down Expand Up @@ -204,7 +207,7 @@ void items_update_v3(cJSON* cj_request, cJSON* cj_response)
cJSON_AddStringToObject(__FUNCTION__, cj_result, ezlopi_deviceCategory_str, curr_device->cloud_properties.category);
cJSON_AddStringToObject(__FUNCTION__, cj_result, ezlopi_deviceSubcategory_str, curr_device->cloud_properties.subcategory);

char * room_name = ezlopi_core_room_get_name_by_id(curr_device->cloud_properties.room_id);
char* room_name = ezlopi_core_room_get_name_by_id(curr_device->cloud_properties.room_id);
if (room_name)
{
cJSON_AddStringToObject(__FUNCTION__, cj_result, ezlopi_roomName_str, room_name);
Expand All @@ -227,18 +230,23 @@ void items_update_v3(cJSON* cj_request, cJSON* cj_response)
cJSON_AddStringToObject(__FUNCTION__, cj_result, ezlopi_valueType_str, curr_item->cloud_properties.value_type);
}

_break_loop = true;
break;
}

curr_item = curr_item->next;
}

if (_break_loop == true)
{
break;
}

curr_device = curr_device->next;
}
}
}

#if 0
cJSON* ezlopi_cloud_items_updated_from_devices_v3(l_ezlopi_device_t* device, l_ezlopi_item_t* item)
{
cJSON* cjson_response = cJSON_CreateObject(__FUNCTION__);
Expand Down
2 changes: 1 addition & 1 deletion ezlopi-cloud/ezlopi-cloud-items/ezlopi_cloud_items.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C"
#endif
void items_list_v3(cJSON* cj_request, cJSON* cj_response);
void items_set_value_v3(cJSON* cj_request, cJSON* cj_response);
void items_update_v3(cJSON* cj_request, cJSON* cj_response);
// void items_update_v3(cJSON* cj_request, cJSON* cj_response);

void items_list(cJSON* cj_request, cJSON* cj_response);
void items_update(cJSON* cj_request, cJSON* cj_response);
Expand Down
38 changes: 30 additions & 8 deletions ezlopi-core/ezlopi-core-buffer/ezlopi_core_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ void ezlopi_core_buffer_deinit(void)
__buffer_lock = NULL;
}

if (__buffer)
{
ezlopi_free(__FUNCTION__, __buffer);
__buffer = NULL;
}
ezlopi_free(__FUNCTION__, __buffer);
__buffer = NULL;

__buffer_len = 0;
__buffer_lock_state = EZ_BUFFER_STATE_NOT_INITIATED;
Expand Down Expand Up @@ -90,7 +87,7 @@ void ezlopi_core_buffer_init(uint32_t len)
}
}

char *ezlopi_core_buffer_acquire(uint32_t *len, uint32_t wait_to_acquired_ms)
char *ezlopi_core_buffer_acquire(const char *who, uint32_t *len, uint32_t wait_to_acquired_ms)
{
char *ret = NULL;
// uint32_t start_time = xTaskGetTickCount();
Expand All @@ -101,23 +98,48 @@ char *ezlopi_core_buffer_acquire(uint32_t *len, uint32_t wait_to_acquired_ms)
ret = __buffer;
*len = __buffer_len;
__buffer_lock_state = EZ_BUFFER_STATE_BUSY;
TRACE_I("(%s): buffer acquired", who);
}
else
{
TRACE_E("(%s): buffer acquire failed!", who);
}
}
else
{
TRACE_E("(%s): __buffer_lock = NULL!", who);
}

return ret;
}

void ezlopi_core_buffer_release(void)
void ezlopi_core_buffer_release(const char *who)
{
#if 0
if (__buffer_lock && (EZ_BUFFER_STATE_BUSY == __buffer_lock_state))
{
xSemaphoreGive(__buffer_lock);
__buffer_lock_state = EZ_BUFFER_STATE_AVAILABLE;
TRACE_I("(%s): buffer release success", who);
}
else
{
TRACE_E("__buffer_lock: %p", __buffer_lock);
TRACE_E("__buffer_lock_state: %d", __buffer_lock_state);
TRACE_E("buffer release failed!");
TRACE_E("(%s): buffer release failed!", who);
}
#endif

if (__buffer_lock && (pdTRUE == xSemaphoreGive(__buffer_lock)))
{
// xSemaphoreGive(__buffer_lock);
__buffer_lock_state = EZ_BUFFER_STATE_AVAILABLE;
TRACE_I("(%s): buffer release success", who);
}
else
{
TRACE_E("__buffer_lock: %p", __buffer_lock);
// TRACE_E("__buffer_lock_state: %d", __buffer_lock_state);
TRACE_E("(%s): buffer release failed!", who);
}
}
7 changes: 5 additions & 2 deletions ezlopi-core/ezlopi-core-buffer/ezlopi_core_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ e_buffer_state_t ezlopi_core_buffer_status(void);
void ezlopi_core_buffer_deinit(void);
void ezlopi_core_buffer_init(uint32_t len);

void ezlopi_core_buffer_release(void);
char *ezlopi_core_buffer_acquire(uint32_t *len, uint32_t wait_to_acquired_ms);
// void ezlopi_core_buffer_release(void);
void ezlopi_core_buffer_release(const char *who);

// char *ezlopi_core_buffer_acquire(uint32_t *len, uint32_t wait_to_acquired_ms);
char *ezlopi_core_buffer_acquire(const char *who, uint32_t *len, uint32_t wait_to_acquired_ms);

#endif // __EZLOPI_CORE_BUFFER_H__
49 changes: 22 additions & 27 deletions ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
#include "EZLOPI_USER_CONFIG.h"

// static uint32_t __message_count = 0;
static l_broadcast_method_t* __method_head = NULL;
static int (*__broadcast_queue_func)(cJSON* cj_data) = NULL;
static l_broadcast_method_t *__method_head = NULL;
static int (*__broadcast_queue_func)(cJSON *cj_data) = NULL;

static int __call_broadcast_methods(char* data);
static l_broadcast_method_t* __method_create(f_broadcast_method_t method, char* name, uint32_t retries);
static int __call_broadcast_methods(char *data);
static l_broadcast_method_t *__method_create(f_broadcast_method_t method, char *name, uint32_t retries);

void ezlopi_core_broadcast_methods_set_queue(int (*func)(cJSON*))
void ezlopi_core_broadcast_methods_set_queue(int (*func)(cJSON *))
{
__broadcast_queue_func = func;
}

int ezlopi_core_broadcast_add_to_queue(cJSON* cj_data)
int ezlopi_core_broadcast_add_to_queue(cJSON *cj_data)
{
int ret = 0;
if (cj_data && __broadcast_queue_func)
Expand All @@ -40,6 +40,7 @@ int ezlopi_core_broadcast_add_to_queue(cJSON* cj_data)
}
return ret;
}

#if 0
int ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data)
{
Expand All @@ -65,9 +66,9 @@ int ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data)

return ret;
}
#endif
#endif

int ezlopi_core_broadcast_cjson(cJSON* cj_data)
int ezlopi_core_broadcast_cjson(cJSON *cj_data)
{
int ret = 0;

Expand All @@ -83,11 +84,10 @@ int ezlopi_core_broadcast_cjson(cJSON* cj_data)
uint32_t buffer_len = 0;

TRACE_I("%d -> -----------------------------> waiting for static buffer!", xTaskGetTickCount());
char* data_buffer = ezlopi_core_buffer_acquire(&buffer_len, 5000);
char *data_buffer = ezlopi_core_buffer_acquire(__FUNCTION__, &buffer_len, 5000);

if (data_buffer && buffer_len)
{
TRACE_I("%d -> -----------------------------> buffer acquired!", xTaskGetTickCount());
memset(data_buffer, 0, buffer_len);

// TRACE_D("buffer_len = [%d]", buffer_len);
Expand All @@ -98,23 +98,18 @@ int ezlopi_core_broadcast_cjson(cJSON* cj_data)
ret = __call_broadcast_methods(data_buffer);
}

ezlopi_core_buffer_release();
TRACE_I("%d -> -----------------------------> buffer released!", xTaskGetTickCount());
}
else
{
TRACE_E("-----------------------------> buffer acquired failed!");
ezlopi_core_buffer_release(__FUNCTION__);
}
}

return ret;
}

l_broadcast_method_t* ezlopi_core_broadcast_method_add(f_broadcast_method_t broadcast_method, char* method_name, uint32_t retries)
l_broadcast_method_t *ezlopi_core_broadcast_method_add(f_broadcast_method_t broadcast_method, char *method_name, uint32_t retries)
{
int duplicate_method = 0;
l_broadcast_method_t* ret = NULL;
l_broadcast_method_t* curr_node = __method_head;
l_broadcast_method_t *ret = NULL;
l_broadcast_method_t *curr_node = __method_head;

while (curr_node)
{
Expand All @@ -132,7 +127,7 @@ l_broadcast_method_t* ezlopi_core_broadcast_method_add(f_broadcast_method_t broa
{
if (__method_head)
{
l_broadcast_method_t* curr_node = __method_head;
l_broadcast_method_t *curr_node = __method_head;

while (curr_node->next)
{
Expand All @@ -157,18 +152,18 @@ void ezlopi_core_broadcast_remove_method(f_broadcast_method_t broadcast_method)
{
if (broadcast_method == __method_head->func)
{
l_broadcast_method_t* remove_node = __method_head;
l_broadcast_method_t *remove_node = __method_head;
__method_head = __method_head->next;
ezlopi_free(__FUNCTION__, remove_node);
}
else
{
l_broadcast_method_t* curr_node = __method_head;
l_broadcast_method_t *curr_node = __method_head;
while (curr_node->next)
{
if (curr_node->next->func == broadcast_method)
{
l_broadcast_method_t* remove_node = curr_node->next;
l_broadcast_method_t *remove_node = curr_node->next;
curr_node->next = curr_node->next->next;
ezlopi_free(__FUNCTION__, remove_node);

Expand All @@ -181,10 +176,10 @@ void ezlopi_core_broadcast_remove_method(f_broadcast_method_t broadcast_method)
}
}

static int __call_broadcast_methods(char* data)
static int __call_broadcast_methods(char *data)
{
int ret = 0;
l_broadcast_method_t* curr_method = __method_head;
l_broadcast_method_t *curr_method = __method_head;

while (curr_method)
{
Expand Down Expand Up @@ -213,9 +208,9 @@ static int __call_broadcast_methods(char* data)
return ret;
}

static l_broadcast_method_t* __method_create(f_broadcast_method_t method, char* method_name, uint32_t retries)
static l_broadcast_method_t *__method_create(f_broadcast_method_t method, char *method_name, uint32_t retries)
{
l_broadcast_method_t* method_node = NULL;
l_broadcast_method_t *method_node = NULL;

if (method)
{
Expand Down
Loading

0 comments on commit db4ed23

Please sign in to comment.