Exemplo n.º 1
0
NmpMsgFunRet
nmp_mod_mss_get_store_log_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    NmpModMss *self;
    NmpGetStoreLogRes *res_info;
    NmpGuestBase *mss_base;
    NmpNetIO *io;

    self = (NmpModMss*)app_obj;
    res_info = MSG_GET_DATA(msg);
    BUG_ON(!res_info);

    io = MSG_IO(msg);
    BUG_ON(!io);

    mss_base = nmp_mods_container_get_guest(self->container, io);
    if (G_UNLIKELY(!mss_base))
    {
        SET_CODE(&res_info->code, E_NOSUCHGUEST);
        nmp_warning("<NmpModMss> mssId: No such guest.");
	 nmp_sysmsg_destroy(msg);
        return MFR_ACCEPTED;
    }

    MSG_SET_DSTPOS(msg, BUSSLOT_POS_CU);
    nmp_mods_container_put_guest(self->container, mss_base);

    return MFR_DELIVER_AHEAD;
}
Exemplo n.º 2
0
static NmpMsgFunRet
nmp_mod_cms_query_record_status_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
	NmpQueryRecordStatus *req_info;
	NmpQueryRecordStatusRes res;
	gint sys_mode;

	req_info = MSG_GET_DATA(msg);
	BUG_ON(!req_info);

	sys_mode = nmp_mss_get_running_mode();
	if (sys_mode == MSS_RUNNING_MODE_CONF)
	{
		memset(&res, 0, sizeof(res));
		SET_CODE(&res, 0);
		strncpy(res.session, req_info->session, USER_NAME_LEN - 1);
		res.status = REC_INITSTAT;
		res.status_code = 0;

		nmp_sysmsg_set_private_2(msg, &res, sizeof(res));
		MSG_SET_RESPONSE(msg);
		return MFR_DELIVER_BACK;		
	}

	MSG_SET_DSTPOS(msg, BUSSLOT_POS_POLICY);
	return MFR_DELIVER_AHEAD;
}
Exemplo n.º 3
0
static NmpMsgFunRet
nmp_mod_cms_sync_req_to_disk(NmpAppObj *app_obj, NmpSysMsg *msg, 
	void *req_info, void *res_info, gint req_size, char *operate)
{
	NmpModCms *self = (NmpModCms*)app_obj;
	gint ret, size = 0;
	
	req_info = MSG_GET_DATA(msg);
	BUG_ON(!req_info);
	
	res_info = nmp_mod_cms_sync_req(self, BUSSLOT_POS_DISK, MSG_GETID(msg),
		req_info, req_size, &size);
	if (res_info)
	{
		ret = RES_CODE(res_info);
		MSG_SET_RESPONSE(msg);
		SET_CODE(res_info, -ret);
		nmp_sysmsg_set_private(msg, res_info, size, nmp_mem_kfree);
		return MFR_DELIVER_BACK;
	}
	else
	{
		nmp_warning("<NmpModCms> operate:%s failed!", operate);
		nmp_sysmsg_destroy(msg);
		return MFR_ACCEPTED;
	}
}
Exemplo n.º 4
0
static gint nmp_mod_tw_run_res_to_cu(tw_run_res *in_parm)
{
	nmp_mod_tw_func_begin("\n");

	NmpSysMsg *msg = NULL;
	NmpModTw *self;
	NmpCuExecuteRes res_info;

	self = nmp_get_mod_tw();

 	memset(&res_info, 0, sizeof(res_info));
 	SET_CODE(&res_info, in_parm->result);
 	strncpy(res_info.session, in_parm->session_id, SESSION_ID_LEN - 1);

	if (in_parm->tw_cmd_type == TW_RUN_STEP)
	{
		if (in_parm->cu_seq == TW_ILLEGAL_SEQ_NUM)
		{
			nmp_print("<NmpModTw> link step return, result = %d.", in_parm->result);
			return 0;
		}
		msg = nmp_sysmsg_new_2(MESSAGE_TW_RUN_STEP, &res_info,
			sizeof(res_info), in_parm->cu_seq);
	}
	else
		return -1;
	if (G_UNLIKELY(!msg))
		return -E_NOMEM;

	MSG_SET_DSTPOS(msg, BUSSLOT_POS_CU);
	MSG_SET_RESPONSE(msg);
	nmp_app_obj_deliver_out((NmpAppObj *)self, msg);

	return 0;
}
Exemplo n.º 5
0
static NmpMsgFunRet
nmp_mod_cms_get_format_progress_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
	NmpModCms *self = (NmpModCms*)app_obj;
	NmpGetHdFormatProgress *req_info;
	NmpGetHdFormatProgressRes *res_info;

	gint ret, size = 0;

	req_info = MSG_GET_DATA(msg);
	BUG_ON(!req_info);

	res_info = nmp_mod_cms_sync_req(self, BUSSLOT_POS_DISK, MSG_GETID(msg),
		req_info, sizeof(*req_info), &size);
    if (res_info)
    {
        ret = RES_CODE(res_info);    
		MSG_SET_RESPONSE(msg);
		SET_CODE(res_info, -ret);
		nmp_sysmsg_set_private(msg, res_info, size, nmp_mem_kfree);
    		return MFR_DELIVER_BACK;
    }
    else
    {
		nmp_warning("<NmpModCms> get hd progress failed, oom!");
		nmp_sysmsg_destroy(msg);
		return MFR_ACCEPTED;
    }
}
Exemplo n.º 6
0
static NmpMsgFunRet
nmp_mod_policy_query_record_status_b(NmpAppObj *app_obj, NmpSysMsg *msg)
{
	NmpModPolicy *self = (NmpModPolicy*)app_obj;
	NmpQueryRecordStatus *req_info;
	NmpQueryRecordStatusRes res;
	NmpGuid guid;
	gint ret, recording;

	req_info = MSG_GET_DATA(msg);
	BUG_ON(!req_info);

	nmp_guid_generate(&guid, req_info->domain_id, req_info->guid);
	ret = nmp_gu_pool_get_record_status(self->gu_pool, &guid, &recording); 
	if (ret || !recording)	/* not found, syncing policy ? waiting ?*/
	{
		memset(&res, 0, sizeof(res));
		SET_CODE(&res, 0);
		strncpy(res.session, req_info->session, USER_NAME_LEN - 1);
		res.status = ret ? ( ret == -EAGAIN ? REC_NODISKS : REC_SYNCING) : REC_WAITING;
		res.status_code = 0;

		nmp_sysmsg_set_private_2(msg, &res, sizeof(res));
		MSG_SET_RESPONSE(msg);
		MSG_SET_DSTPOS(msg, BUSSLOT_POS_CMS);
		return MFR_DELIVER_BACK;
	}
	else
	{
		MSG_SET_DSTPOS(msg, BUSSLOT_POS_STREAM);
		return MFR_DELIVER_BACK;
	}
}
Exemplo n.º 7
0
NmpMsgFunRet
nmp_mod_mss_heart_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    NmpModMss *self;
    NmpNetIO *io;
    NmpGuestBase *mss_base;
    NmpMssHeart *req_info;
    NmpMssHeartRes res_info;
    NmpMsgID msg_id;
    gint ret = 0;
    NmpResourcesCap res_cap;

    self = (NmpModMss*)app_obj;
    io = MSG_IO(msg);
    BUG_ON(!io);

    msg_id = MSG_GETID(msg);
    req_info = MSG_GET_DATA(msg);
    BUG_ON(!req_info);

    memset(&res_cap, 0, sizeof(res_cap));
    nmp_mod_get_resource_cap(&res_cap);
    if (!(res_cap.module_bits&MODULE_MSS_BIT))
    {
        nmp_app_obj_deliver_in((NmpAppObj*)self, msg);
        nmp_mod_acc_release_io((NmpModAccess*)self, io);
        nmp_mod_container_del_io(self->container, io);
        return MFR_ACCEPTED;
    }
    memset(&res_info, 0, sizeof(res_info));
    mss_base = nmp_mods_container_get_guest_2(self->container, req_info->mss_id);
    if (G_UNLIKELY(!mss_base))
    {
        ret = -E_NOSUCHGUEST;
        nmp_warning("<NmpModMss> mssId:%s No such guest.", req_info->mss_id);
    }
    else
    {
        nmp_get_utc_time(res_info.server_time);
        nmp_mods_container_put_guest(self->container, mss_base);
    }

    MSG_SET_RESPONSE(msg);
    SET_CODE(&res_info, -ret);
    nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));

    return MFR_DELIVER_BACK;
}
Exemplo n.º 8
0
NmpMsgFunRet
nmp_mod_mds_heart_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    NmpModMds *self;
    NmpNetIO *io;
    NmpGuestBase *mds_base;
    NmpMdsHeart *req_info;
    NmpMdsHeartRes res_info;
    NmpMsgID msg_id;
    gint ret = 0;
    NmpResourcesCap res_cap;

    self = (NmpModMds*)app_obj;
    io = MSG_IO(msg);
    BUG_ON(!io);

    msg_id = MSG_GETID(msg);
    req_info = MSG_GET_DATA(msg);
    BUG_ON(!req_info);

    memset(&res_cap, 0, sizeof(res_cap));
    nmp_mod_get_resource_cap(&res_cap);
    if (!(res_cap.module_bits&MODULE_MDS_BIT))
    {
        nmp_app_obj_deliver_in((NmpAppObj*)self, msg);
        nmp_mod_acc_release_io((NmpModAccess*)self, io);
        nmp_mod_container_del_io(self->container, io);
        return MFR_ACCEPTED;
    }

    memset(&res_info, 0, sizeof(res_info));
    mds_base = nmp_mods_container_get_guest(self->container, io);
    if (G_LIKELY(mds_base))
    {
        nmp_get_ip_from_socket(io, req_info->mds_ip);
	  MSG_SET_DSTPOS(msg, BUSSLOT_POS_DBS);
        nmp_mods_container_put_guest(self->container, mds_base);
	 return MFR_DELIVER_AHEAD;
    }

    ret = -E_NOSUCHGUEST;
    nmp_warning("<NmpModMds> mdsId:%s No such mds.", req_info->mds_id);
    MSG_SET_RESPONSE(msg);
    SET_CODE(&res_info, -ret);
    nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));

    return MFR_DELIVER_BACK;
}
Exemplo n.º 9
0
static gint nmp_mod_tw_operate_result_to_cu(tw_operate_result_to_cu_with_seq *in_parm,
	int operate_type)
{
	nmp_mod_tw_func_begin("\n");

	NmpSysMsg *msg;
	NmpSysMsg *res_msg;
	NmpModTw *self;
	NmpCuExecuteRes res;

	self = nmp_get_mod_tw();

	//operate result
	memset(&res, 0, sizeof(res));
	SET_CODE(&res, in_parm->to_cu.result);
	strncpy(res.session, in_parm->to_cu.session_id, SESSION_ID_LEN - 1);
	res_msg = nmp_sysmsg_new_2(operate_type, &res, sizeof(res), in_parm->seq);
	if (G_UNLIKELY(!res_msg))
		return -E_NOMEM;

	MSG_SET_DSTPOS(res_msg, BUSSLOT_POS_CU);
	MSG_SET_RESPONSE(res_msg);
	nmp_app_obj_deliver_out((NmpAppObj *)self, res_msg);


	if (in_parm->to_cu.result != 0)
	{
		nmp_warning("<NmpModTw> operate result=%d, not to notify.",
			in_parm->to_cu.result);
		return 0;
	}
	//通告
	msg = nmp_sysmsg_new_2(MESSAGE_TW_OPERATE_NOTIFY, &in_parm->to_cu,
		sizeof(tw_operate_result_to_cu), ++msg_seq_generator);
	if (G_UNLIKELY(!msg))
		return -E_NOMEM;

	MSG_SET_DSTPOS(msg, BUSSLOT_POS_CU);
	nmp_app_obj_deliver_out((NmpAppObj *)self, msg);

	return 0;
}
Exemplo n.º 10
0
static NmpMsgFunRet
nmp_mod_system_reboot_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
	NmpSystemReboot *req_info = NULL;
	NmpSystemRebootRes res_info;
	memset(&res_info, 0, sizeof(res_info));

	req_info = MSG_GET_DATA(msg);
	BUG_ON(!req_info);
	
	SET_CODE(&res_info, 0);
	strncpy(res_info.session, req_info->session, USER_NAME_LEN - 1);
	
	nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));
	MSG_SET_RESPONSE(msg);
	
	nmp_will_reboot();
	
	return MFR_DELIVER_BACK;
}
Exemplo n.º 11
0
NmpMsgFunRet
nmp_mod_ams_get_device_info_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
	G_ASSERT(app_obj != NULL && msg != NULL);
	NmpModAms *self;
	NmpNetIO *io;
	NmpGuestBase *ams_base;
	NmpAmsGetDeviceInfo *req_info;
	NmpAmsGetDeviceInfoRes res_info;
	NmpMsgID msg_id;
	gint ret = 0;
	memset(&res_info, 0, sizeof(res_info));

	self = (NmpModAms*)app_obj;
	io = MSG_IO(msg);
	BUG_ON(!io);

	msg_id = MSG_GETID(msg);
	req_info = MSG_GET_DATA(msg);
	BUG_ON(!req_info);

	ams_base = nmp_mods_container_get_guest_2(self->container, req_info->ams_id);
	if (G_UNLIKELY(!ams_base))
	{
		ret = -E_NOSUCHGUEST;
		nmp_warning("<NmpModAms> amsId:%s No such guest.", req_info->ams_id);
	}
	else
	{
		MSG_SET_DSTPOS(msg, BUSSLOT_POS_DBS);
		nmp_mods_container_put_guest(self->container, ams_base);
		return MFR_DELIVER_AHEAD;
	}

	MSG_SET_RESPONSE(msg);
	SET_CODE(&res_info, -ret);
	nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));

	return MFR_DELIVER_BACK;
}
Exemplo n.º 12
0
NmpMsgFunRet
nmp_mod_ams_heart_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    NmpModAms *self;
    NmpNetIO *io;
    NmpGuestBase *ams_base;
    NmpAmsHeart *req_info;
    NmpAmsHeartRes res_info;
    NmpMsgID msg_id;
    gint ret = 0;

    self = (NmpModAms*)app_obj;
    io = MSG_IO(msg);
    BUG_ON(!io);

    msg_id = MSG_GETID(msg);
    req_info = MSG_GET_DATA(msg);
    BUG_ON(!req_info);

    memset(&res_info, 0, sizeof(res_info));
    ams_base = nmp_mods_container_get_guest_2(self->container, req_info->ams_id);
    if (G_UNLIKELY(!ams_base))
    {
        ret = -E_NOSUCHGUEST;
        nmp_warning("<NmpModAms> amsId:%s No such guest.", req_info->ams_id);
    }
    else
    {
        nmp_get_utc_time(res_info.server_time);
        nmp_mods_container_put_guest(self->container, ams_base);
    }

    MSG_SET_RESPONSE(msg);
    SET_CODE(&res_info, -ret);
    nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));

    return MFR_DELIVER_BACK;
}
Exemplo n.º 13
0
NmpMsgFunRet
nmp_mod_mss_get_store_log_b(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    NmpModMss *self;
    NmpGetMssStoreLog *req_info;
    NmpGuestBase *mss_base;
    NmpNetIO *io;
    gint msg_id;
    NmpErrRes      code;

    self = (NmpModMss*)app_obj;
    req_info = MSG_GET_DATA(msg);
    BUG_ON(!req_info);

    memset(&code, 0, sizeof(code));
    msg_id = MSG_GETID(msg);
    mss_base = nmp_mods_container_get_guest_2(self->container, req_info->mss_id);
    if (G_UNLIKELY(!mss_base))
    {
        nmp_warning("<NmpModMss> deliver msg '%s' failed, MssId:%s no such mss.",
            MESSAGE_ID_TO_STR(cms, msg_id), req_info->mss_id);

        SET_CODE(&code.code, E_NOSUCHGUEST);
        memcpy(code.session, req_info->session, SESSION_ID_LEN - 1);
        MSG_SET_DSTPOS(msg, BUSSLOT_POS_CU);
        nmp_sysmsg_set_private_2(msg, &code, sizeof(code));
        MSG_SET_RESPONSE(msg);
        return MFR_DELIVER_BACK;
    }

    io = IO_OF_GUEST(mss_base);
    BUG_ON(!io);

    nmp_sysmsg_attach_io(msg, io);
    nmp_mods_container_put_guest(self->container, mss_base);

    return MFR_DELIVER_AHEAD;
}
Exemplo n.º 14
0
NmpMsgFunRet
nmp_mod_ams_backward_2(NmpModAms *self, NmpSysMsg *msg, const gchar *id_str, const gchar *session_id)
{
    NmpGuestBase *ams_base;
    NmpNetIO *io;
    gint msg_id;
    NmpErrRes      code;

    memset(&code, 0, sizeof(code));
    msg_id = MSG_GETID(msg);
    ams_base = nmp_mods_container_get_guest_2(self->container, id_str);
    if (G_UNLIKELY(!ams_base))
    {
        nmp_warning("<NmpModAms> deliver msg '%s' failed, AmsId:%s no such ams.",
            MESSAGE_ID_TO_STR(cms, msg_id), id_str);
        //nmp_sysmsg_destroy(msg);


        SET_CODE(&code.code, E_NOSUCHGUEST);
	if (session_id)
            memcpy(code.session, session_id, USER_NAME_LEN - 1);

        MSG_SET_DSTPOS(msg, BUSSLOT_POS_BSS);
        nmp_sysmsg_set_private_2(msg, &code, sizeof(code));
        MSG_SET_RESPONSE(msg);
        return MFR_DELIVER_BACK;
    }

    io = IO_OF_GUEST(ams_base);
    BUG_ON(!io);

    nmp_sysmsg_attach_io(msg, io);
    nmp_mods_container_put_guest(self->container, ams_base);

    return MFR_DELIVER_AHEAD;
}
Exemplo n.º 15
0
NmpMsgFunRet
nmp_mod_mss_get_hd_format_progress_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    G_ASSERT(app_obj != NULL && msg != NULL);
    NmpModMss *self;
    NmpGetHdFormatProgressRes *res_info;
    gint ret = 0;

    self = (NmpModMss*)app_obj;

    res_info = MSG_GET_DATA(msg);
    BUG_ON(!res_info);

    ret = nmp_mod_mss_forward(self, msg);
    if (ret)
    {
        SET_CODE(res_info, -ret);
        nmp_warning("<NmpModMss> No such guest.");
	 nmp_sysmsg_destroy(msg);
        return MFR_ACCEPTED;
    }

    return MFR_DELIVER_AHEAD;
}
Exemplo n.º 16
0
gpointer
nmp_mod_mds_sync_req_2(NmpModMds *self, NmpMsgID msg_id,
       gpointer req, gint req_size, gint *res_size)
{
	gint err = 0;
	NmpMsgErrCode *res_info;
	gpointer res;
	NmpSysMsg *msg;
	G_ASSERT(self != NULL);

	msg = nmp_sysmsg_new_2(msg_id, req, req_size, ++msg_seq_generator);
	if (G_UNLIKELY(!msg))
		return NULL;

    MSG_SET_DSTPOS(msg, BUSSLOT_POS_DBS);
    err = nmp_app_mod_sync_request((NmpAppMod*)self, &msg);
    if (G_UNLIKELY(err))	/* send failed */
    {
        nmp_warning(
        	"<NmpModMds> request cmd %d failed!", msg_id
    );

    nmp_sysmsg_destroy(msg);
    res_info = nmp_mem_kalloc(sizeof(NmpMsgErrCode));
    if (res_info)
    {
    	SET_CODE(res_info, err);
    	*res_size = sizeof(NmpMsgErrCode);
    }

    return res_info;
    }

	if (G_UNLIKELY(!msg))	/* sent, but no response */
	{
		nmp_warning(
			"<NmpModMds> request cmd %d timeout!", msg_id
		);
		res_info = nmp_mem_kalloc(sizeof(NmpMsgErrCode));
		err = -E_TIMEOUT;
		if (res_info)
		{
			SET_CODE(res_info, err);
			*res_size = sizeof(NmpMsgErrCode);
		}

		return res_info;
	}

	res = MSG_GET_DATA(msg);
	if (!res)
	{
		nmp_sysmsg_destroy(msg);
		return NULL;
	}

	res_info = nmp_mem_kalloc(MSG_DATA_SIZE(msg));
	if (G_UNLIKELY(!res_info))
       {
       	nmp_sysmsg_destroy(msg);
       	return NULL;
       }

	*res_size =  MSG_DATA_SIZE(msg);
	memcpy(res_info, res, *res_size);
	nmp_sysmsg_destroy(msg);

	return res_info;
}
Exemplo n.º 17
0
NmpMsgFunRet
nmp_mod_ams_register_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    NmpModAms *self;
    NmpNetIO *io;
    NmpAmsRegister *req_info;
    NmpAmsRegisterRes res_info;
    NmpMsgID msg_id;
    NmpGuestBase *ams_base;
    NmpAms *ams;
    NmpMsgAmsOnlineChange notify_info;
    gint ret;

    self = (NmpModAms*)app_obj;
    io = MSG_IO(msg);
    BUG_ON(!io);

    msg_id = MSG_GETID(msg);

    req_info = MSG_GET_DATA(msg);
    BUG_ON(!req_info);

    memset(&notify_info, 0, sizeof(notify_info));
    notify_info.ams_id[AMS_ID_LEN - 1] = 0;
    strncpy(notify_info.ams_id, req_info->ams_id, AMS_ID_LEN - 1);
    memset(&res_info, 0, sizeof(res_info));
    ret = nmp_mod_ams_register(self, io, msg_id, req_info, &res_info);
    if (ret)
    {
        nmp_print(
            "<NmpModAms> ams:%s register failed, err:%d",
            req_info->ams_id, -ret
        );

        SET_CODE(&res_info, -ret);
        MSG_SET_RESPONSE(msg);
        nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));

        nmp_app_obj_deliver_in((NmpAppObj*)self, msg);
        nmp_mod_acc_release_io((NmpModAccess*)self, io);
        nmp_mod_container_del_io(self->container, io);

        return MFR_ACCEPTED;
    }

    ams_base = nmp_mods_container_get_guest(self->container, io);
    if (G_UNLIKELY(!ams_base))
    {
        ret = -E_NOSUCHGUEST;
	 nmp_warning("<NmpModAms> Can't find ams:'%s' in container, io timeout?", notify_info.ams_id);
    }
    else
   {
        ams = (NmpAms *)ams_base;
        ams->ams_state = STAT_AMS_ONLINE;
        nmp_mods_container_put_guest(self->container, ams_base);

         nmp_print(
             "<NmpModAms> ams:%s register ok",
             req_info->ams_id
         );

        strncpy(res_info.domain_id, nmp_get_local_domain_id(), DOMAIN_ID_LEN - 1);

        nmp_check_keepalive_time(&res_info.keep_alive_time);
        nmp_net_io_set_ttd(io, res_info.keep_alive_time*1000*TIMEOUT_N_PERIODS);

        notify_info.new_status = 1;
        nmp_mod_ams_change_ams_online_status(app_obj, notify_info);
    }

    SET_CODE(&res_info, -ret);
    MSG_SET_RESPONSE(msg);
    nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));
    return MFR_DELIVER_BACK;

}
Exemplo n.º 18
0
gpointer
nmp_mod_policy_sync_req(NmpModPolicy *self, gint dst, NmpMsgID msg_id,			
       gpointer req, gint req_size, gint *res_size)
{
    gint err = 0;
    NmpMsgErrCode *res_info;
    gpointer res;
    NmpSysMsg *msg;
    guint len;

    G_ASSERT(self != NULL);

    msg = nmp_sysmsg_new_2(msg_id, req, req_size, 0);
    if (G_UNLIKELY(!msg))
    	return NULL;	

    MSG_SET_DSTPOS(msg, dst);
    len = sizeof(NmpMsgErrCode);
	
    err = nmp_app_mod_sync_request((NmpAppMod*)self, &msg); 
    if (G_UNLIKELY(err))	/* send failed */
    {
    	nmp_warning(
    		"<NmpModPolicy> request cmd %d failed!", msg_id
    	);
    
    	nmp_sysmsg_destroy(msg);

    	res_info = nmp_mem_kalloc(len); 
    	if (res_info)
    	{
    		SET_CODE(res_info, err);
    		*res_size = len;
    	}
    
    	return res_info;
    }

    if (G_UNLIKELY(!msg))	/* sent, but no response */ 
    {
        nmp_warning(
    		"<NmpModPolicy> request cmd %d timeout!", msg_id
    	 );
    	 res_info = nmp_mem_kalloc(len);  
    	 err = -E_TIMEOUT;
        if (res_info)
    	{
    		SET_CODE(res_info, err);
    		*res_size = len;
    	}
    	return res_info;
    }

    res = MSG_GET_DATA(msg);
    if (!res)
    {
    	nmp_sysmsg_destroy(msg);
    	return NULL;
    }
    
    res_info = nmp_mem_kalloc(MSG_DATA_SIZE(msg));      
    if (G_UNLIKELY(!res_info))
    {
    	nmp_sysmsg_destroy(msg);
    	return NULL;
    }

    *res_size =  MSG_DATA_SIZE(msg);
    memcpy(res_info, res, *res_size);
    nmp_sysmsg_destroy(msg);

    return res_info;	
}
Exemplo n.º 19
0
NmpMsgFunRet
nmp_mod_mds_get_media_url_b(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    G_ASSERT(app_obj != NULL && msg != NULL);

    NmpModMds *self;
    NmpMsgGetUrl *req;
    NmpGetMediaUrlRes res;
    NmpGuestBase *mds_base;
    gchar puid[MAX_ID_LEN] = {0};
    gchar tmp[MAX_ID_LEN];
    gint channel, level;
    gint ret = 0;

    req = MSG_GET_DATA(msg);
	memset(&res, 0, sizeof(res));
	strncpy(res.session, req->session, SESSION_ID_LEN - 1);
    self = (NmpModMds*)app_obj;
    mds_base = nmp_mods_container_get_guest_2(self->container, req->mds_id);
    if (G_UNLIKELY(!mds_base))
    {
        ret = -E_NOSUCHGUEST;
        nmp_warning("<NmpModMds> mdsId:%s No such guest.", req->mds_id);
    }
    else
    {
        nmp_mods_container_put_guest(self->container, mds_base);
        sscanf(req->guid, "%16s-%2s-%d-%2d", puid, tmp, &level, &channel);
	 strcpy(res.guid, req->guid);
	 strcpy(res.ip, req->cms_ip);

	 switch (req->media)
	 {
        case MEDIA_VIDEO_BROWSE:
            snprintf(
                res.url, MAX_URL_LEN,
                "rtsp://%s:%d/dev=@%s/media=%d/channel=%d&level=%d",
                req->mds_ip, req->rtsp_port, puid, req->media, channel, level
            );
            break;

        default:
            if (strlen(req->mss_id))
            {
                snprintf(
                    res.url, MAX_URL_LEN,
                    "rtsp://%s:%d/dev=@%s/media=%d",
                    req->mds_ip, req->rtsp_port, req->mss_id, req->media
                 );
             }
             else
             {
                snprintf(
                    res.url, MAX_URL_LEN,
                    "rtsp://%s:%d/dev=@%s/media=%d/channel=%d&level=%d",
                    req->mds_ip, req->rtsp_port, puid, req->media, channel, level
                );
             }
            break;
	 }
    }

    SET_CODE(&res, -ret);
    nmp_sysmsg_set_private_2(msg, &res, sizeof(res));
    printf("nmp_dbs_modify_sysmsg_2 ret = %d,--url= %s\n",ret, res.url);
    MSG_SET_DSTPOS(msg, BUSSLOT_POS_CU);

    return MFR_DELIVER_BACK;
}
Exemplo n.º 20
0
bool TF20::process_cmd()
{
	int drv, trk, sec, dst;
	uint8 *sctr, *sctw;
	
	switch(bufr[3]) {
	case FNC_RESET_P:
	case FNC_RESET_M:
		SET_HEAD(0);
		SET_CODE(ERR_SUCCESS);
		return true;
		
	case FNC_READ:
		drv = (bufr[1] == DID_FIRST) ? 0 : (bufr[1] == DID_SECOND) ? 2 : 4;
		drv += bufr[7] - 1;
		trk = bufr[8];
		sec = bufr[9];
		if(!disk_inserted(drv)) {
			// drive error
			SET_HEAD(0x80);
			for(int i = 0; i < 128; i++) {
				SET_DATA(0xff);
			}
			SET_CODE(ERR_DRIVE);
			return true;
		}
		if((sctr = get_sector(drv, trk, sec)) == NULL) {
			// read error
			SET_HEAD(0x80);
			for(int i = 0; i < 128; i++) {
				SET_DATA(0xff);
			}
			SET_CODE(ERR_READ);
			return true;
		}
		SET_HEAD(0x80);
		for(int i = 0; i < 128; i++) {
			SET_DATA(sctr[i]);
		}
		SET_CODE(ERR_SUCCESS);
		return true;
		
	case FNC_WRITE:
		drv = (bufr[1] == DID_FIRST) ? 0 : (bufr[1] == DID_SECOND) ? 2 : 4;
		drv += bufr[7] - 1;
		trk = bufr[8];
		sec = bufr[9];
		if(!disk_inserted(drv)) {
			// drive error
			SET_HEAD(0);
			SET_CODE(ERR_DRIVE);
			return true;
		}
		if(disk_protected(drv)) {
			// write protect
			SET_HEAD(0);
			SET_CODE(ERR_PROTECTED);
			return true;
		}
		if((sctw = get_sector(drv, trk, sec)) == NULL) {
			// write error
			SET_HEAD(0);
			SET_CODE(ERR_WRITE);
			return true;
		}
		// dont care write type
		for(int i = 0; i < 128; i++) {
			sctw[i] = bufr[11 + i];
		}
		SET_HEAD(0);
		SET_CODE(ERR_SUCCESS);
		return true;
		
	case FNC_WRITEHST:
		SET_HEAD(0);
		SET_CODE(ERR_SUCCESS);
		return true;
		
	case FNC_COPY:
		drv = (bufr[1] == DID_FIRST) ? 0 : (bufr[1] == DID_SECOND) ? 2 : 4;
		drv += bufr[7] - 1;
		dst = (drv & ~1) | (~drv & 1);
		if(!disk_inserted(drv)) {
			// drive error
			SET_HEAD(0);
			SET_CODE(ERR_DRIVE);
			return true;
		}
		if(!disk_inserted(dst)) {
			// drive error
			SET_HEAD(0);
			SET_CODE(ERR_DRIVE);
			return true;
		}
		if(disk_protected(dst)) {
			// write protect
			SET_HEAD(0);
			SET_CODE(ERR_PROTECTED);
			return true;
		}
		for(trk = 0; trk < 40; trk++) {
			for(sec = 1; sec <= 64; sec++) {
				if((sctr = get_sector(drv, trk, sec)) == NULL) {
					// read error
					SET_HEAD(0);
					SET_CODE(ERR_READ);
					return true;
				}
				if((sctw = get_sector(dst, trk, sec)) == NULL) {
					// write error
					SET_HEAD(0);
					SET_CODE(ERR_WRITE);
					return true;
				}
				memcpy(sctw, sctr, 128);
			}
			SET_HEAD(2);
			SET_DATA(trk == 39 ? 0xff : 0);		// high-order
			SET_DATA(trk == 39 ? 0xff : trk);	// low-order
			SET_CODE(ERR_SUCCESS);
		}
		return true;
		
	case FNC_FORMAT:
		drv = (bufr[1] == DID_FIRST) ? 0 : (bufr[1] == DID_SECOND) ? 2 : 4;
		drv += bufr[7] - 1;
		if(!disk_inserted(drv)) {
			// drive error
			SET_HEAD(0);
			SET_CODE(ERR_DRIVE);
			return true;
		}
		if(disk_protected(drv)) {
			// write protect
			SET_HEAD(0);
			SET_CODE(ERR_PROTECTED);
			return true;
		}
		for(trk = 0; trk < 40; trk++) {
			for(sec = 1; sec <= 64; sec++) {
				if((sctw = get_sector(drv, trk, sec)) == NULL) {
					// write error
					SET_HEAD(0);
					SET_CODE(ERR_WRITE);
					return true;
				}
				memset(sctw, 0xe5, 128);
			}
			SET_HEAD(2);
			SET_DATA(trk == 39 ? 0xff : 0);		// high-order
			SET_DATA(trk == 39 ? 0xff : trk);	// low-order
			SET_CODE(ERR_SUCCESS);
		}
		return true;
	}
	// unknown command
	return false;
}
Exemplo n.º 21
0
NmpMsgFunRet
nmp_mod_mds_register_f(NmpAppObj *app_obj, NmpSysMsg *msg)
{
    NmpModMds *self;
    NmpNetIO *io;
    NmpMdsRegister *req_info;
    NmpMdsRegisterRes res_info;
    NmpMsgID msg_id;
    NmpGuestBase *mds_base;
    NmpMds *mds;
    NmpMsgMdsOnlineChange notify_info;
    gint ret;
    NmpResourcesCap res_cap;

    self = (NmpModMds*)app_obj;
    io = MSG_IO(msg);
    BUG_ON(!io);

    msg_id = MSG_GETID(msg);

    req_info = MSG_GET_DATA(msg);
    BUG_ON(!req_info);

    memset(&res_cap, 0, sizeof(res_cap));
    nmp_mod_get_resource_cap(&res_cap);
    if (!(res_cap.module_bits&MODULE_MDS_BIT))
    {
        ret = E_EXPIRED;
        goto mds_register_err;
    }
    memset(&notify_info, 0, sizeof(notify_info));
    notify_info.mds_id[MDS_ID_LEN - 1] = 0;
    strncpy(notify_info.mds_id, req_info->mds_id, MDS_ID_LEN - 1);
    memset(&res_info, 0, sizeof(res_info));
    nmp_get_ip_from_socket(io, req_info->mds_ip);
    ret = nmp_mod_mds_mds_register(self, io, msg_id, req_info, &res_info);
mds_register_err:
    if (ret)
    {
        nmp_print(
            "<NmpModMds> mds:%s register failed, err:%d",
            req_info->mds_id, -ret
        );

        SET_CODE(&res_info, -ret);
        MSG_SET_RESPONSE(msg);
        nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));

        nmp_app_obj_deliver_in((NmpAppObj*)self, msg);
        nmp_mod_acc_release_io((NmpModAccess*)self, io);
        nmp_mod_container_del_io(self->container, io);

        return MFR_ACCEPTED;
    }

    mds_base = nmp_mods_container_get_guest(self->container, io);
    if (G_UNLIKELY(!mds_base))
    {
        ret = -E_NOSUCHGUEST;
	 nmp_warning("<NmpModMds> Can't find mds:'%s' in container, io timeout?", notify_info.mds_id);
    }
    else
   {
        mds = (NmpMds *)mds_base;
        mds->mds_state = STAT_MDS_ONLINE;
        nmp_mods_container_put_guest(self->container, mds_base);

         nmp_print(
             "<NmpModMds> mds:%s register ok",
             req_info->mds_id
         );

        strncpy(res_info.domain_id, nmp_get_local_domain_id(), DOMAIN_ID_LEN - 1);

        nmp_check_keepalive_time(&res_info.keep_alive_time);
        nmp_net_io_set_ttd(io, res_info.keep_alive_time*1000*TIMEOUT_N_PERIODS);
        notify_info.new_status = 1;
        nmp_mod_mds_change_mds_online_status(app_obj, notify_info);
    }

    SET_CODE(&res_info, -ret);
    MSG_SET_RESPONSE(msg);
    nmp_sysmsg_set_private_2(msg, &res_info, sizeof(res_info));
    return MFR_DELIVER_BACK;
}