bool cps_api_send_object(cps_api_channel_t handle, cps_api_object_t obj) { t_std_error rc = STD_ERR_OK; size_t len = cps_api_object_to_array_len(obj); int by = std_write(handle,cps_api_object_array(obj),len, true,&rc); if (by != (int)len) { EV_LOG(ERR,DSAPI,0,"CPS IPC","Was not able to send the full object."); } return (by==(int)len) ; }
cps_api_object_t cps_api_receive_object(cps_api_channel_t handle,size_t len) { if (len==0) return NULL; cps_api_object_guard og(cps_api_object_create()); t_std_error rc = STD_ERR_OK; do { if (cps_api_object_get_reserve_len(og.get()) < len) { if (!cps_api_object_reserve(og.get(),len)) break; } int by = std_read(handle,cps_api_object_array(og.get()),len,true,&rc); if (by!=(int)len) break; if (!cps_api_object_received(og.get(),len)) break; return og.release(); } while (0); EV_LOG(ERR,DSAPI,0,"CPS IPC","Was not able to read the object - MSG (%X)",rc); return NULL; }
static cps_api_return_code_t _cps_api_event_service_publish_msg(cps_api_event_service_handle_t handle, cps_api_object_t msg) { STD_ASSERT(msg!=NULL); STD_ASSERT(handle!=NULL); cps_api_key_t *_okey = cps_api_object_key(msg); if (cps_api_key_get_len(_okey) < CPS_OBJ_KEY_SUBCAT_POS) { //likely invalid message return cps_api_ret_code_ERR; } std_event_key_t key; cps_api_to_std_key(&key,_okey); cps_api_to_std_event_map_t *p = handle_to_data(handle); int retry = (int)p->retry; for (; retry > 0 ; --retry) { std_mutex_simple_lock_guard lg(&p->lock); if (!__connect_to_service(handle)) { std_usleep(MILLI_TO_MICRO(1)); continue; } t_std_error rc = std_client_publish_msg_data( handle_to_std_handle(handle), &key, cps_api_object_array(msg), cps_api_object_to_array_len(msg)); if (rc!=STD_ERR_OK) { __close_channel(handle); } else { return cps_api_ret_code_OK; } } return cps_api_ret_code_ERR; }
static cps_api_return_code_t _cps_api_wait_for_event( cps_api_event_service_handle_t handle, cps_api_object_t msg) { std_event_msg_t m; while (true) { std_event_client_handle h; cps_api_to_std_event_map_t *p = handle_to_data(handle); { std_mutex_simple_lock_guard lg(&p->lock); if (!__connect_to_service(handle)) { //retry every 50ms std_usleep(MILLI_TO_MICRO(50)); continue; } h = handle_to_std_handle(handle); } if (std_client_wait_for_event_data(h,&m, cps_api_object_array(msg), cps_api_object_get_reserve_len(msg))!=STD_ERR_OK) { __close_channel(handle); continue; } if (!cps_api_object_received(msg,m.data_len)) { EV_LOG(ERR,DSAPI,0,"CPS-EV-RX","Invalid message received... returning to client"); __close_channel(handle); continue; } break; } return cps_api_ret_code_OK; }