/*===========================================================================

FUNCTION loc_get_target_name

DESCRIPTION
   Returns pointer to a string that contains name of the target

   XX:XX:XX.000\0

RETURN VALUE
   The target name string

===========================================================================*/
const char *loc_get_target_name(unsigned int target)
{
    int index = 0;
    static char ret[BUFFER_SIZE];

    index =  getTargetGnssType(target);
    if( index >= target_name_num || index < 0)
        index = target_name_num - 1;

    if( (target & HAS_SSC) == HAS_SSC ) {
        snprintf(ret, sizeof(ret), " %s with SSC",
           loc_get_name_from_val(target_name, target_name_num, (long)index) );
    }
    else {
       snprintf(ret, sizeof(ret), " %s  without SSC",
           loc_get_name_from_val(target_name, target_name_num, (long)index) );
    }
    return ret;
}
static void net_ev_cb
(
  dsi_hndl_t handle,
  void* user_data,
  dsi_net_evt_t evt,
  dsi_evt_payload_t *payload_ptr
)
{
    int i;
    (void)handle;
    (void)user_data;
    (void)payload_ptr;
    ds_caller_data *callback_data = (ds_caller_data *)user_data;

    LOC_LOGD("%s:%d]: Enter. Callback data: %p\n", __func__, __LINE__, callback_data);
    if(evt > DSI_EVT_INVALID && evt < DSI_EVT_MAX)
    {
        LOC_LOGE("%s:%d]: Callback received: %s",
                 __func__, __LINE__,
                 loc_get_name_from_val(event_string_tbl,
                         sizeof(event_string_tbl)/sizeof(event_string_tbl[0]), evt));

        switch(evt) {
        case DSI_EVT_NET_IS_CONN:
        case DSI_EVT_WDS_CONNECTED:
        {
            LOC_LOGD("%s:%d]: Emergency call started\n", __func__, __LINE__);
            callback_data->event_cb(E_DS_CLIENT_DATA_CALL_CONNECTED,
                                    callback_data->caller_cookie);
            break;
        }
        case DSI_EVT_NET_NO_NET:
        {
            LOC_LOGD("%s:%d]: Emergency call stopped\n", __func__, __LINE__);
            callback_data->event_cb(E_DS_CLIENT_DATA_CALL_DISCONNECTED,
                                    callback_data->caller_cookie);
            break;
        }
        default:
            LOC_LOGD("%s:%d]: uninteresting event\n", __func__, __LINE__);
        }
    }
    LOC_LOGD("%s:%d]:Exit\n", __func__, __LINE__);
}
const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur)
{
    return loc_get_name_from_val(loc_eng_position_recurrences, loc_eng_position_recurrence_num, (long) recur);
}
const char* loc_get_position_mode_name(GpsPositionMode mode)
{
    return loc_get_name_from_val(loc_eng_position_modes, loc_eng_position_mode_num, (long) mode);
}
/* Find Android GPS status name */
const char* loc_get_gps_status_name(GpsStatusValue gps_status)
{
   return loc_get_name_from_val(gps_status_name, gps_status_num,
         (long) gps_status);
}
const char* loc_get_agps_status_name(AGpsStatusValue status)
{
    return loc_get_name_from_val(loc_eng_agps_status_names, loc_eng_agps_status_num, (long) status);
}
const char* loc_get_position_sess_status_name(enum loc_sess_status status)
{
    return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status);
}
const char* loc_get_server_type_name(LocServerType type)
{
    return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type);
}
const char* loc_get_agps_bear_name(AGpsBearerType bearer)
{
    return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer);
}
const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding)
{
    return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding);
}
const char* loc_get_ni_response_name(GpsUserResponseType response)
{
    return loc_get_name_from_val(loc_eng_ni_responses, loc_eng_ni_reponse_num, (long) response);
}
const char* loc_get_ni_type_name(GpsNiType type)
{
    return loc_get_name_from_val(loc_eng_ni_types, loc_eng_ni_type_num, (long) type);
}
const char* loc_get_agps_type_name(AGpsType type)
{
    return loc_get_name_from_val(loc_eng_agps_types, loc_eng_agps_type_num, (long) type);
}
/* Find msg_q status name */
const char* loc_get_msg_q_status(int status)
{
   return loc_get_name_from_val(loc_msg_q_status, loc_msg_q_status_num, (long) status);
}
/* Find Android GPS status name */
const char* loc_get_msg_name(int id)
{
   return loc_get_name_from_val(loc_eng_msgs, loc_eng_msgs_num, (long) id);
}
/* Finds the first event found in the mask */
const char* loc_get_event_atl_open_name(rpc_loc_server_request_e_type loc_event_atl_open)
{
   return loc_get_name_from_val(loc_event_atl_open_name, loc_event_atl_open_num,
         (long) loc_event_atl_open);
}