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) ;
}
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;
}