Exemple #1
0
int config_create_backup_listener(int *listener)
{
    int retval, port = DEF_BACKUP_PORT;
    struct sockaddr_in sockaddr;

    if (SOCKET_ERROR == (*listener = socket(AF_INET, SOCK_STREAM, 0)))
    {
        show_warn("socket error.\n");
        return SOCKET_ERROR;
    }
    else
        show_info("Create socket[%d] succ ...\n", *listener);

    do
    {
        /* set sockaddr_in */
        sockaddr.sin_family = AF_INET;
        sockaddr.sin_port   = htons(port); //将一个无符号短整型数值转换为网络字节序,即大端模式(big-endian)
        sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
        bzero(&(sockaddr.sin_zero), sizeof(sockaddr.sin_zero));

        retval = bind(*listener, (struct sockaddr*)&sockaddr, sizeof(struct sockaddr));
        if (SOCKET_ERROR == retval)
        {
            show_warn("bind error.\n");
            if (65535 <= ++port)
            {
                close(*listener);
                return SOCKET_ERROR;
            }
        }
        else
        {
            show_info("Bind sockfd succ ...\n");
            break;
        }
    }while (1);

    if (SOCKET_ERROR == listen(*listener, 1))
    {
        show_warn("listen error.\n");
        close(*listener);
        return SOCKET_ERROR;
    }
    else
    {
        show_info("[backup]Server listening [listener: %d]...\n", *listener);

        retval = fcntl(*listener, F_GETFL);
        if ((0 > retval) || 
            (0 > fcntl(*listener, F_SETFL, retval | O_NONBLOCK)))   //非阻塞
        {
            show_warn("fcntl");
            close(*listener);
            return SOCKET_ERROR;
        }
    }

    return port;
}
Exemple #2
0
static __inline__ void dah_login(dah_service_t *dah_srv)
{
    char addr[MAX_IP_LEN];
    int state, error = 0;
    int user_id = DAH_LOGOUT;
    proxy_sdk_t sdk_info;

    NMP_ASSERT(dah_srv);

    if (proxy_get_device_private(dah_srv->owner, DEV_PRI_PRX_SDK, &sdk_info))
    {
        BUG();
    }

    memset(addr, 0, sizeof(addr));
    if (proxy_resolve_host_immediate((const char*)sdk_info.dev_host, addr, sizeof(addr)))
    {
        user_id = CLIENT_Login(addr, sdk_info.dev_port, 
                    sdk_info.username, sdk_info.password, 
                    &dah_srv->dah_info, &error);
    }
    else
        show_warn("Device host '%s' unsolved.\n", sdk_info.dev_host);

    if (DAH_LOGOUT != user_id)
    {
        CLIENT_StartListen(user_id);

        state = DAH_LOGIN;
        error = 0;
        show_debug("dah_login() successful, user_id: %d\n", user_id);
    }
    else
    {
        state = DAH_LOGOUT;
        //error = ;

        if (strlen(addr))
        {
            show_warn("dah_login(deviceID:%d) failure[%s:%s @ %s:%d]. Error: %d\n", 
                dah_srv->owner->fastenings.dev_id, 
                sdk_info.username, sdk_info.password, 
                addr, sdk_info.dev_port, error);
        }
    }

    dah_set_user_id(dah_srv, user_id);
    dah_set_state(dah_srv, (DAH_STATE_E)state, error);

    return ;
}
Exemple #3
0
static __inline__ void bsm_login(bsm_service_t *bsm_srv)
{
    char addr[MAX_IP_LEN];
    int state, error = 0;
    int user_id = BSM_LOGOUT;
    proxy_sdk_t sdk_info;

    NMP_ASSERT(bsm_srv);

    if (proxy_get_device_private(bsm_srv->owner, DEV_PRI_PRX_SDK, &sdk_info))
    {
        BUG();
    }

    memset(addr, 0, sizeof(addr));
    if (proxy_resolve_host_immediate((const char*)sdk_info.dev_host, addr, sizeof(addr)))
    {
        error = HI_NET_DEV_Login((HI_U32*)&user_id, 
            sdk_info.username, sdk_info.password, 
            addr, sdk_info.dev_port);
    }
    else
        show_warn("Device host '%s' unsolved.\n", sdk_info.dev_host);

    if (BSM_LOGOUT != user_id)
    {
        state = BSM_LOGIN;
        error = 0;
        show_debug("bsm_login() successful, user_id: %d\n", user_id);
    }
    else
    {
        state = BSM_LOGOUT;
        //error = ;

        if (strlen(addr))
        {
            show_warn("bsm_login(deviceID:%d) failure[%s:%s @ %s:%d]. Error: %d\n", 
                bsm_srv->owner->fastenings.dev_id, 
                sdk_info.username, sdk_info.password, 
                addr, sdk_info.dev_port, error);
        }
    }

    bsm_set_user_id(bsm_srv, user_id);
    bsm_set_state(bsm_srv, (BSM_STATE_E)state, error);

    return ;
}
Exemple #4
0
static int 
hie_stream_ctrl(void *owner, int channel, int level, int cmd, void *value)
{
    int ret = -1;
    hie_service_t *hie_srv;
    NMP_ASSERT(owner);

    hie_srv = (hie_service_t*)owner;

    if (HIE_INVALID_HANDLE == hie_get_user_id(&hie_srv->parm))
    {
        show_warn("hie device is disconnected.\n");
    }
    else
    {
        switch (cmd)
        {
            case DEF_STOP_ALL_STREAM_CMD:
                hie_cleanup_stream_info(&hie_srv->rtsp);
                ret = 0;
                break;

            default:
                break;
        }
    }

    return ret;
}
Exemple #5
0
//brief  强制删除已登录用户回调
static int 
hie_del_user_force_cb(HUSER user_id, DWORD user_data)
{
    proxy_device_t *prx_dev;
    hie_service_t *hie_srv;
    hie_service_basic_t *hie_basic;
    show_warn("hie_del_user_force_cb() user_id: %p!!!\n", user_id);

    hie_basic = (hie_service_basic_t*)user_data;

    prx_dev = proxy_find_device_by_user_id((int)user_id, 
                hie_basic->tm.service_name);
    if (prx_dev)
    {
        hie_srv = (hie_service_t*)prx_dev->sdk_srv;
        if (hie_srv)
        {
            hie_set_user_id(hie_srv, HIE_INVALID_HANDLE);
            hie_set_state(hie_srv, HIE_LOGOUT, 0);
        }
        proxy_device_ref(prx_dev);
    }

    return 0;
}
Exemple #6
0
static int 
hie_stream_open(void *owner, stream_info_t *strm_info)
{
    int ret = -1;
    hie_service_t *hie_srv;
    NMP_ASSERT(owner && strm_info);

    hie_srv = (hie_service_t*)owner;

    if (HIE_INVALID_HANDLE == hie_get_user_id(&hie_srv->parm))
    {
         show_warn("hie device is disconnected..\n");
    }
    else
    {
        nmp_mutex_lock(hie_srv->rtsp.lock);
        switch (strm_info->type)
        {
            case STREAM_REAL:               // 播放实时流
                ret = hie_open_real_stream(hie_srv, strm_info);
                break;
            case STREAM_VOD:                // 点播录像文件
            case STREAM_DOWNLOAD:           // 下载录像文件
                //ret = hie_open_record_stream(hie_srv, strm_info);
                break;

            default:
                break;
        }
        nmp_mutex_unlock(hie_srv->rtsp.lock);
    }

    return ret;
}
Exemple #7
0
static int 
hie_stream_init(void *owner, stream_info_t *strm_info)
{
    int ret = -1;
    hie_service_t *hie_srv;
    NMP_ASSERT(owner && strm_info);

    hie_srv = (hie_service_t*)owner;
    if (HIE_INVALID_HANDLE == hie_get_user_id(&hie_srv->parm))
    {
        show_warn("hie device is disconnected.\n");
    }
    else
    {
        switch (strm_info->type)
        {
            case STREAM_REAL://0 播放实时流
                ret = hie_init_real_stream(hie_srv, strm_info);
                strm_info->length = 0;
                break;
            case STREAM_VOD:      //2点播录像文件
            case STREAM_DOWNLOAD: //3下载录像文件
                ret = hie_init_record_stream(hie_srv, strm_info);
                strm_info->length = 0;
                break;

            default:
                break;
        }
    }

    return ret;
}
Exemple #8
0
static int hbn_talk_recv(struct service *srv, talk_info_t *talk, char *data, int len, media_info_t *info)
{
    int ret = -1;
    hbn_service_t *hbn_srv;
    unsigned int in_data_len = 0;
    frame_t *frm = NULL;

    NMP_ASSERT(srv && talk && data);

    frm = (talk_frame_hdr_t*)data;
    if(ntohl(frm->magic) != TALK_MAGIC)
    {
        show_warn("magic[0x%x] error", ntohl(frm->magic));
        return -1;
    }
    in_data_len = ntohl(frm->frame_length);
printf("====================hbn_talk_recv len = %d\n", in_data_len);
    hbn_srv = (hbn_service_t*)srv;	
	ret = HB_NET_VoiceComSendData(talk->talk_handle, (char *)frm->frame_data, in_data_len);
	if(ret == FALSE)
	{
		show_debug("HB_NET_VoiceComSendData!, error = %d, user_id = %d\n", 
		        (int)HB_NET_GetLastError(), (int )hbn_get_user_id(&hbn_srv->parm));
		return -1;
	}

    return 0;
}
Exemple #9
0
bool handler__reset(globals_t * vars, char **argv, unsigned argc)
{
    USEPARAMS();

    if (vars->matches) { free(vars->matches); vars->matches = NULL; vars->num_matches = 0; }

    /* refresh list of regions */
    l_destroy(vars->regions);

    /* create a new linked list of regions */
    if ((vars->regions = l_init()) == NULL) {
        show_error("sorry, there was a problem allocating memory.\n");
        return false;
    }

    /* read in maps if a pid is known */
    if (vars->target && readmaps(vars->target, vars->regions) != true) {
        show_error("sorry, there was a problem getting a list of regions to search.\n");
        show_warn("the pid may be invalid, or you don't have permission.\n");
        vars->target = 0;
        return false;
    }

    return true;
}
Exemple #10
0
INT main(INT argcc, CHAR * argvc[])
{    
	CHAR * argv[] = {
		"xoc.exe",
		"..\\..\\test\\test_ansic.c",
	    "-dump","cfe.tmp",
	};
	INT argc = sizeof(argv)/sizeof(argv[0]);
#else
INT main(INT argc, CHAR * argv[])
{
#endif
	if (!process_cmd(argc, argv)) return 1;
	init_parser();
	g_fe_sym_tab = new SYM_TAB(64); 
	fe_process();

	//Show you all info that generated by CfrontEnd.
	dump_scope(get_global_scope(), 0xFFFFFFFF);	
	show_err();
	show_warn();
	fprintf(stdout, "\n%s - (%d) error(s), (%d) warnging(s)\n",
					g_source_file_name, 
					g_err_msg_list.get_elem_count(),
					g_warn_msg_list.get_elem_count());
	fini_parser();
	finidump();
	return 0;
}
Exemple #11
0
static __inline__ void 
xmt_make_key_frame(LONG user_id, int channel, int level)
{
    if (0 == level)
    {
        if (FALSE == H264_DVR_MakeKeyFrame(user_id, channel, 0))  // 强制关键帧只有在播数据才有效
        {
            show_warn("H264_DVR_MakeKeyFrame failed.\n");
        }
    }
    else if (0 < level)
    {
        if (FALSE == H264_DVR_MakeKeyFrame(user_id, channel, 1))
        { 
            show_warn("H264_DVR_MakeKeyFrame failed.\n");
        }
    }
}
Exemple #12
0
static __inline__ void 
hie_make_key_frame(HUSER user_id, int channel, int level)
{// 强制关键帧只有在播数据才有效
    int err;

    err = HieClient_ForceIFrame(user_id, channel);
    if (err)
    { 
        show_warn("HB_NET_MakeKeyFrame failed, err: %d.\n", err);
    }
}
Exemple #13
0
static int hik_talk_recv(struct service *srv, struct talk_info *talk, char *data, 
							int len, media_info_t *info)
{
	int ret = -1;
	struct hik_service *hik_srv;
	unsigned char out_buffer[MAX_ENCODE_BUFFER_LEN];
	unsigned int in_data_len = 0;
	frame_t *frm = NULL;

	unsigned int itype;
	BOOL flag;
	NMP_ASSERT(srv && talk && data);
	
	frm = (talk_frame_hdr_t *)data;
	if(ntohl(frm->magic) != TALK_MAGIC)
	{
		show_warn("magic[0x%x] error", ntohl(frm->magic));
		return -1;
	}

	in_data_len = ntohl(frm->frame_length);

	if(info->attr.encode_type == 1)
	{
		//g711a_Decode2(in_buffer, pcm_data, (int)in_data_len, &out_pcm_data_len);
		itype = 1;
	}
	else if(info->attr.encode_type == 2)
	{
		//g711u_Decode(in_buffer, pcm_data, (int)in_data_len, &out_pcm_data_len);
		itype = 0;
	}

	hik_srv = (hik_service_t *)srv;

	flag = NET_DVR_EncodeG722Frame(talk->init_g722_encoder, frm->frame_data, out_buffer);
	if(flag == FALSE)
	{
		show_error("-------NET_DVR_EncodeG722Frame error[%d]\n", NET_DVR_GetLastError());
		
		return -1;	
	}

	ret = NET_DVR_VoiceComSendData(talk->talk_handle, (char *)out_buffer, G722FRAMEDATALEN);
	if(ret == FALSE)
	{
		show_error("----------NET_DVR_VoiceComSendData error[%d]\n", NET_DVR_GetLastError());
		return -1;
	}
	//usleep(10*1000);

	return ret;
}
Exemple #14
0
struct service *
create_new_service(void *init, int type, const char *name)
{
    struct service_template *tm;
    NMP_ASSERT(init && name);

    if ((tm = find_service_template_by_name((const char*)name)))
    {
        return (*tm->create_service)(tm, init);
    }
    else
        show_warn("service_template[%s] NULL!\n", (char*)name);

    return NULL;
}
Exemple #15
0
int config_start_backup_listen_thread(int listener)
{
    pthread_t thread;

    if (pthread_create(&thread, NULL, (void*)config_backup_thread_proxy, 
            (void*)listener))
    {
        show_warn("Create send pthread error!\n");
        close(listener);
        set_backup_left_size(&g_cfg_bkp, 0);
        set_backup_state(&g_cfg_bkp, NORMAL);
        return -1;
    }

    return 0;
}
Exemple #16
0
static int 
config_revert_handle(void *init_data, msg_t *msg, int parm_id)
{
    int ret = -1;
    int port, listener;
    prx_backup *backup;
    config_backup_t *cfg_bkp;
    config_service_t *cfg_srv;

    NMP_ASSERT(init_data && msg);

    BUG_ON(UPLOAD_DATA_REQUEST_ID != MSG_ID(msg));

    cfg_srv = (config_service_t*)init_data;
    backup  = (prx_backup*)MSG_DATA(msg);
    cfg_bkp = get_config_backup();

    if (NORMAL != try_change_backup_state(cfg_bkp, REVERT))
    {
        if (0 < backup->size)
        {
            port = config_create_backup_listener(&listener);
            if (port > 0)
                ret = 0;
        }

        if (!ret)
        {
            nmp_mutex_lock(cfg_bkp->lock);
            cfg_bkp->state= REVERT;
            cfg_bkp->left = backup->size;
            nmp_mutex_unlock(cfg_bkp->lock);

            backup->magic = DEF_REVERT_MAGIC;
            backup->port  = port;

            config_start_backup_listen_thread(listener);
        }
    }
    else
        show_warn("Somebody backing up!!!\n");

    backup->result = ret;
    set_msg_id(msg, UPLOAD_DATA_RESPONSE_ID);

    return RET_BACK;
}
Exemple #17
0
static int 
config_backup_handle(void *init_data, msg_t *msg, int parm_id)
{
    int len, ret = -1;
    int port, listener;
    prx_backup *backup;
    config_backup_t *cfg_bkp;
    config_service_t *cfg_srv;

    NMP_ASSERT(init_data && msg);

    BUG_ON(DOWNLOAD_DATA_REQUEST_ID != MSG_ID(msg));

    cfg_srv = (config_service_t*)init_data;
    backup  = (prx_backup*)MSG_DATA(msg);
    cfg_bkp = get_config_backup();

    if (NORMAL != try_change_backup_state(cfg_bkp, BACKUP))
    {
        len = config_figure_up_file_len(cfg_bkp);
        if (len)
        {
            backup->size = len;
            port = config_create_backup_listener(&listener);
            if (port > 0)
            {
                ret = 0;
                backup->magic = DEF_BACKUP_MAGIC;
                backup->port  = port;

                config_start_backup_listen_thread(listener);
            }
        }
    }
    else
        show_warn("Somebody backing up!!!\n");

    backup->result = ret;
    set_msg_id(msg, DOWNLOAD_DATA_RESPONSE_ID);

    return RET_BACK;
}
Exemple #18
0
static int bsm_init(service_template_t *self)
{
    int ret = 0;
    bsm_service_basic_t *bsm_basic;

    NMP_ASSERT(self);

    bsm_basic = (bsm_service_basic_t*)self;

    if (HI_SUCCESS != HI_NET_DEV_Init())
    {
        ret = -1;
        show_warn("HI_NET_DEV_Init() failure!\n");
    }
    else
    {
    }

    return ret;
}
void main()
{
	char ch;
	while(1)
	{
		printf(" a.main_file();\n b.testLineStruct();\n");
		printf(" c.sort_main();\n d.Common\n");
		printf("--->");
		while ((ch = getchar())=='\r');
		flushall();//Çå¿ÕÊäÈ뻺³åÇø
		switch(ch)
		{
			case 'a':
			case 'A':
				main_file();
				break;
			case 'b':
			case 'B':
				testLineStruct();
				break;
			case 'C':
			case 'c':
				sort_main();
				break;
			case 'D':
			case 'd':
				Common_main_test();
				break;
			default:
				show_warn("ÊäÈëÓÐÎó~");
		}
		if(!isContinue())
		{
			system("pause");
			exit(0);
		}
	}
}
Exemple #20
0
static int 
hie_init(service_template_t *self)
{
    int ret = 0, err;
    hie_service_basic_t *hie_basic;

    NMP_ASSERT(self);

    hie_basic = (hie_service_basic_t*)self;

    if ((err = HieClient_Start()))
    {
        ret = -1;
        show_warn("HieClient_Start() failure, err: %d!\n", err);
    }
    else
    {
        HieClient_DeleteUserForceCB(hie_del_user_force_cb, (DWORD)hie_basic);
        
    }

    return ret;
}
Exemple #21
0
/* XXX: handle multiple deletes, eg delete !1 2 3 4 5 6 */
bool handler__delete(globals_t * vars, char **argv, unsigned argc)
{
    unsigned id;
    char *end = NULL;
    match_location loc;

    if (argc != 2) {
        show_error("was expecting one argument, see `help delete`.\n");
        return false;
    }

    /* parse argument */
    id = strtoul(argv[1], &end, 0x00);

    /* check that strtoul() worked */
    if (argv[1][0] == '\0' || *end != '\0') {
        show_error("sorry, couldnt parse `%s`, try `help delete`\n", argv[1]);
        return false;
    }
    
    loc = nth_match(vars->matches, id);
    
    if (loc.swath)
    {
        /* It is not convenient to check whether anything else relies on this,
           so just mark it as not a REAL match */
        zero_match_flags(&loc.swath->data[loc.index].match_info);
        return true;
    }
    else
    {
        /* I guess this is not a valid match-id */
        show_warn("you specified a non-existant match `%u`.\n", id);
        show_info("use \"list\" to list matches, or \"help\" for other commands.\n");
        return false;
    }
}
Exemple #22
0
static int dah_init(service_template_t *self)
{
    int ret = 0;
    dah_conn_t *conn_info;
    dah_service_basic_t *dah_basic;

    NMP_ASSERT(self);

    dah_basic = (dah_service_basic_t*)self;
    conn_info = &dah_basic->conn_info;

    if (!CLIENT_Init(conn_info->dis_conn, (DWORD)dah_basic))
    {
        ret = -1;
        show_warn("NET_DVR_Init() failure!\n");
    }
    else
    {
        CLIENT_SetConnectTime(conn_info->conn_wait_time, conn_info->conn_try_times);
        CLIENT_SetDVRMessCallBack(dah_message_call_back, (LDWORD)dah_basic);
    }

    return ret;
}
Exemple #23
0
static int 
hie_stream_seek(void *owner, stream_info_t *strm_info)
{
    int type, ret = -1;
    hie_service_t *hie_srv;
    NMP_ASSERT(owner && strm_info);

    hie_srv = (hie_service_t*)owner;

    if (HIE_INVALID_HANDLE == hie_get_user_id(&hie_srv->parm))
    {
         show_warn("hie device is disconnected..\n");
    }
    else
    {
        nmp_mutex_lock(hie_srv->rtsp.lock);
        type = strm_info->type;
        nmp_mutex_unlock(hie_srv->rtsp.lock);

        //ret = hie_process_stream(hie_srv, strm_info, CMD_STREAM_SEEK, type);
    }

    return ret;
}
Exemple #24
0
static void *config_backup_thread_proxy(void *data)
{
    fd_set fd_st;
    config_backup_t *cfg_bkp;
    int err, magic;
    int listener, client_fd = 0;
    struct timeval timeout = {DEF_BACKUP_KEEP_LIVE, 0};

    pthread_detach(pthread_self());

    listener = (int)data;
    cfg_bkp = get_config_backup();

    // initialize file descriptor set
    FD_ZERO(&fd_st);
    FD_SET(listener, &fd_st);

    show_info("=========== Backup Selecting...[listener: %d] =========== \n", listener);
    err = select(listener+1, &fd_st, NULL, NULL, &timeout);
    if (-1 == err)
    {
        show_info("Select error.\n");
    }
    else if (0 == err)
    {
        show_info("Select timeout.\n\n");
    }
    else
    {
        client_fd = accept(listener, NULL, NULL);
        if (INVALID_SOCKET != client_fd)
        {show_info("===========>> accept: %d \n", client_fd);
            setsockopt(client_fd, SOL_SOCKET, SO_RCVTIMEO | SO_SNDTIMEO, 
                &timeout, sizeof(timeout));
            switch (get_backup_state(cfg_bkp))
            {
                case BACKUP:
                    recv(client_fd, &magic, sizeof(magic), 0);
                    printf("MAGIC: 0x%x, 0x%x, 0x%x\n", magic, DEF_BACKUP_MAGIC, ntohl(magic));
                    if (DEF_BACKUP_MAGIC != ntohl(magic))
                    {
                        show_warn("magic incorrect!!!!!!!!!!\n");
                        break;
                    }

                    config_download_data(client_fd, cfg_bkp);
                    break;
                case REVERT:
                    recv(client_fd, &magic, sizeof(magic), 0);
                    printf("MAGIC: 0x%x, 0x%x\n", magic, DEF_REVERT_MAGIC);
                    if (DEF_REVERT_MAGIC != ntohl(magic))
                    {
                        show_warn("magic incorrect!!!!!!!!!!\n");
                        break;
                    }

                    config_upload_data(client_fd, cfg_bkp);
                    break;
            }
            show_info("===========>> close: %d \n", client_fd);
            close(client_fd);
        }
    }

    set_backup_left_size(cfg_bkp, 0);
    set_backup_state(cfg_bkp, NORMAL);
    close(listener);
    return NULL;
}
Exemple #25
0
static __inline__ void jny_login(jny_service *jny_srv)
{
    char addr[MAX_IP_LEN];
    int ret, state, error;
    int user_id = JNY_LOGOUT;
    proxy_sdk_t sdk_info;
	ST_DeviceInfo stDeviceInfo;

    NMP_ASSERT(jny_srv);

    if (proxy_get_device_private(jny_srv->owner, DEV_PRI_PRX_SDK, &sdk_info))
    {
        BUG();
    }

    memset(addr, 0, sizeof(addr));
    if (proxy_resolve_host_immediate((const char*)sdk_info.dev_host, addr, sizeof(addr)))
    {
    	memset(&stDeviceInfo, 0, sizeof(ST_DeviceInfo));
		stDeviceInfo.nDeviceType = IPCAMERA;
		memcpy(stDeviceInfo.stInetAddr.szHostIP, 
				addr, strlen(addr));
		stDeviceInfo.stInetAddr.nPORT = sdk_info.dev_port;
		stDeviceInfo.stInetAddr.nIPProtoVer = IPPROTO_V4;
		memcpy(stDeviceInfo.szPassword, sdk_info.password, strlen(sdk_info.password));
		memcpy(stDeviceInfo.szUserID, sdk_info.username, strlen(sdk_info.username));
		
		ret = Remote_Nvd_Init((long *)&user_id, &stDeviceInfo, TCP);
		if(ret != SN_SUCCESS)
		{
			jny_print_error(ret);
			user_id = JNY_LOGOUT;
		}
    }
    else
    {
        show_warn("Device host '%s' unsolved.\n", sdk_info.dev_host);
    }

	if (JNY_LOGOUT != user_id)
    {
        state = JNY_LOGIN;
        error = 0;
        show_debug("jny_login() successful, user_id: %d\n", user_id);
    }
    else
    {
        state = JNY_LOGOUT;
        error = ret;

        if (strlen(addr))
        {
            show_warn("jny_login(deviceID:%d) failure[%s:%s @ %s:%d]. Error: %d\n", 
                jny_srv->owner->fastenings.dev_id, 
                sdk_info.username, sdk_info.password, 
                addr, sdk_info.dev_port, ret);
        }
    }

    jny_set_user_id(jny_srv, user_id);
    jny_set_state(jny_srv, (JNY_STATE_E)state, error);

    return ;
}
Exemple #26
0
static int 
hie_get_device_config(struct service *srv, int parm_id, void *parm)
{
    int ret = -1;
    HUSER user_id;

    JDevCap *dev_cap;
//    get_store_t *get_store;

    hie_service_t *hie_srv;

    NMP_ASSERT(srv && parm);

    hie_srv = (hie_service_t*)srv;
    user_id = hie_get_user_id(&hie_srv->parm);

    if (HIE_INVALID_HANDLE == user_id)
    {
        show_debug("Proxy device logout!!!!!!!!!!!!!!\n");
        return -1;
    }

    switch (parm_id)
    {
        case GET_DEVICE_CONFIG:
            goto GET_CFG;
        case GET_SERIAL_CONFIG:
            goto GET_CFG;
        case GET_DEVICE_TIME:
            goto GET_CFG;
        case GET_NTP_CONFIG:
            goto GET_CFG;
        case GET_NETWORK_CONFIG:
            goto GET_CFG;
        case GET_PPPOE_CONFIG:
            goto GET_CFG;
        case GET_FTP_CONFIG:
            goto GET_CFG;
        case GET_SMTP_CONFIG:
            goto GET_CFG;
        case GET_DDNS_CONFIG:
            goto GET_CFG;
        case GET_UPNP_CONFIG:
            goto GET_CFG;
        case GET_DISK_LIST:
            goto GET_CFG;

        case GET_ENCODE_CONFIG:
            goto GET_CFG;
        case GET_DISPLAY_CONFIG:
            goto GET_CFG;
        case GET_OSD_CONFIG:
            goto GET_CFG;
        case GET_PTZ_CONFIG:
            goto GET_CFG;
        case GET_RECORD_CONFIG:
            goto GET_CFG;
        case GET_HIDE_CONFIG:
            goto GET_CFG;
        case GET_MOTION_CONFIG:
            goto GET_CFG;
        case GET_VIDEO_LOST_CONFIG:
            goto GET_CFG;
        case GET_HIDE_ALARM_CONFIG:
            goto GET_CFG;
        case GET_IO_ALARM_CONFIG:
            goto GET_CFG;

        case GET_STORE_LOG:
            /*get_store = (get_store_t*)parm;
            ret = hie_find_record_file(user_id, get_store->channel, 
                    (JStoreLog*)get_store->buffer);*/
            break;

        case GET_CRUISE_CONFIG:
            break;

        case GET_CAPABILITY_SET:
            dev_cap = (JDevCap*)parm;
            dev_cap->cap0 = DEV_CAP_VIDEO_IN | DEV_CAP_AUDIO | DEV_CAP_IRIS | DEV_CAP_PTZ | 
                DEV_CAP_ALARM_IN | DEV_CAP_ALARM_OUT | DEV_CAP_STORAGE | DEV_CAP_WEB | DEV_CAP_PLATFORM | 
                DEV_CAP_INTELLIGENT_ANALYSIS | DEV_CAP_UPDATE | DEV_CAP_VIDEO_OUT;// | DEV_CAP_IR;
            dev_cap->ftp_enable = 0;
            dev_cap->upnp_enable = 0;
            dev_cap->chn_cap.size = sizeof(JChnCap);
            dev_cap->chn_cap.encode = VIDEO_ENCODE_H264_E | VIDEO_ENCODE_MJPEG_E | 
                VIDEO_ENCODE_JPEG_E | VIDEO_ENCODE_MPEG4_E;
            dev_cap->chn_cap.supp_mask = 1;
            dev_cap->chn_cap.mask_count = 1;
            dev_cap->chn_cap.supp_hide_alarm = 1;
            dev_cap->chn_cap.hide_alarm_count = 1;
            dev_cap->chn_cap.supp_move_alarm = 1;
            dev_cap->chn_cap.move_alarm_count = 1;
            dev_cap->chn_cap.supp_video_lost_alarm = 1;
            dev_cap->chn_cap.osd_count = 1;
            dev_cap->chn_cap.stream_count = 2;
        dev_cap->chn_cap.stream_supp_resolution[0] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
            CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_720P | CAP_VIDEO_1080P;
        dev_cap->chn_cap.stream_supp_resolution[1] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
            CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_720P | CAP_VIDEO_1080P;
        dev_cap->chn_cap.stream_supp_resolution[2] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
            CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_720P | CAP_VIDEO_1080P;
        dev_cap->chn_cap.stream_supp_resolution[3] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
            CAP_VIDEO_HD1 | CAP_VIDEO_D1 | CAP_VIDEO_720P | CAP_VIDEO_1080P;
            dev_cap->chn_cap.stream_max_frate_rate[0] = 30;
            dev_cap->chn_cap.img_cap = IMA_BRIGHTNESS | IMA_CONTRAST | IMA_SATURATION | IMA_HUE;
            ret = 0;
            break;

        default:
            ret = -1;
            show_warn("parm_id Invalid!!!!!\n");
            break;
    }

    return ret;

GET_CFG:
    ret = HieClient_GetConfigV2(user_id, (ConfigInformationV2*)parm);
    show_debug("HieClient_GetConfigV2: %s<-------------------------------\n", 
        !ret ? "Success" : "Failure");
    if (!ret)
        return 0;
    else
    {
        show_debug("ERROR: %d<-------------------------------\n", ret);
        return -1;
    }
}
Exemple #27
0
static __inline__ void 
hie_login(hie_service_t *hie_srv)
{
    char addr[MAX_IP_LEN];
    int state, error = 0;
    HUSER user_id = HIE_INVALID_HANDLE;

    proxy_sdk_t sdk_info;
    UserLoginPara login_para;

    NMP_ASSERT(hie_srv);

    memset(&sdk_info, 0, sizeof(proxy_sdk_t));
    memset(&login_para, 0, sizeof(UserLoginPara));

    if (proxy_get_device_private(hie_srv->owner, DEV_PRI_PRX_SDK, &sdk_info))
    {
        BUG();
    }

    memset(addr, 0, sizeof(addr));
    if (proxy_resolve_host_immediate((const char*)sdk_info.dev_host, addr, sizeof(addr)))
    {
        login_para.dwCommandPort = sdk_info.dev_port;
        strncpy(login_para.sServerIP, sdk_info.dev_host, MAX_ADDRESS_LEN);
        strncpy(login_para.sUName,    sdk_info.username, USERNAME_LEN);
        strncpy(login_para.sUPass,    sdk_info.password, USERPASS_LEN);

        error = HieClient_UserLogin(&user_id, &login_para);

        switch(error)
        {
            case eErrorConnectFailed:
            {
                show_debug("eErrorConnectFailed\n");
                break;
            }
            case eErrorServerReject:
            {
                show_debug("eErrorServerReject\n");
                break;
            }
            case eErrorUserName:
            {
                show_debug("eErrorUserName\n");
                break;
            }
            case eErrorUserPass:
            {
                show_debug("eErrorUserPass\n");
                break;
            }
            case eErrorUserNumOverflow:
            {
                show_debug("eErrorUserNumOverflow\n");
                break;
            }
            default:
            {
                break;
            }
        }
    }
    else
        show_warn("Device host '%s' unsolved.\n", sdk_info.dev_host);

    if (HIE_INVALID_HANDLE != user_id)
    {
        state = HIE_LOGIN;
        error = 0;
        show_debug("hie_login() successful, user_id: %p\n", user_id);
    }
    else
    {
        state = HIE_LOGOUT;

        if (strlen(addr))
        {
            show_warn("hie_login(deviceID:%d) failure[%s:%s @ %s:%d]. Error: %d\n", 
                hie_srv->owner->fastenings.dev_id, 
                sdk_info.username, sdk_info.password, 
                addr, sdk_info.dev_port, error);
        }
    }

    hie_set_user_id(hie_srv, user_id);
    hie_set_state(hie_srv, (HIE_STATE_E)state, error);

    return ;
}
Exemple #28
0
static int 
dah_talk_open(struct service *srv, talk_info_t *talk, 
        talk_handle_t *hdl, media_info_t *info)
{
    int ret = -1;
    dah_service_t *dah_srv;

    DH_AUDIO_FORMAT aft;
    DHDEV_TALKDECODE_INFO cur_talk_mode;

    NMP_ASSERT(srv && talk);

    memset(&aft, 0, sizeof(DH_AUDIO_FORMAT));
    memset(&cur_talk_mode, 0, sizeof(DHDEV_TALKDECODE_INFO));

    aft.byFormatTag = 0;
    aft.nChannels = 1;
    aft.nSamplesPerSec = 8000;
    aft.wBitsPerSample = 16;

    dah_srv = (dah_service_t*)srv;
    talk->handle = dah_get_user_id(&dah_srv->parm);
    if(talk->frm)
    {
        nmp_dealloc(talk->frm, sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN);
        talk->frm = NULL;
    }

    talk->frm = (frame_t *)nmp_alloc0(sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN);
    if(!talk->frm)
    {
        return -1;
    }
	
    if (DAH_LOGOUT == dah_get_user_id(&dah_srv->parm))
    {
        show_warn("dah device is disconnected.\n");
    }
    else
    {
        ret = CLIENT_InitAudioEncode(aft);
        if(ret != 0)
        {
            show_error("CLIENT_InitAudioEncode error ret = %d\n", ret);
            if(talk->frm)
            {
                nmp_dealloc(talk->frm, sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN);
                talk->frm = NULL;
            }
            return -1;
        }

        //查询设备支持的语音对讲列表
        DHDEV_TALKFORMAT_LIST lstTalkEncode = {0};
        int nRetlen = 0;
        BOOL bSuccess = CLIENT_QueryDevState(dah_get_user_id(&dah_srv->parm), DH_DEVSTATE_TALK_ECTYPE, 
                (char*)&lstTalkEncode, sizeof(DHDEV_TALKFORMAT_LIST), &nRetlen, 2000);
        if (!(bSuccess&&nRetlen == sizeof(DHDEV_TALKFORMAT_LIST)))
        {
            show_error("query talk format failed, error = 0x%x\n", CLIENT_GetLastError());
            if(talk->frm)
            {
                nmp_dealloc(talk->frm, sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN);
                talk->frm = NULL;
            }
            return -1;
        }

        ret = set_audio_attr(info, &cur_talk_mode);
        if(ret != 0)
        {
            if(talk->frm)
            {
                nmp_dealloc(talk->frm, sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN);
                talk->frm = NULL;
            }
            return -1;
        }
        // 设置服务器模式语音对讲模式
        bSuccess = CLIENT_SetDeviceMode(dah_get_user_id(&dah_srv->parm), DH_TALK_ENCODE_TYPE, &cur_talk_mode);
        bSuccess = CLIENT_SetDeviceMode(dah_get_user_id(&dah_srv->parm), DH_TALK_SERVER_MODE, NULL);

        //  开始对讲
        talk->talk_handle = CLIENT_StartTalkEx(dah_get_user_id(&dah_srv->parm), 
            				(pfAudioDataCallBack)dah_audio_data_callback, (LDWORD)talk);
        if(0 != talk->talk_handle)
        {
            show_info("Start talk success! talk_handle = %d\n", (int)talk->talk_handle);
        }
        else
        {
            show_error("Start talk failed!, error = 0x%x, user_id = %d\n", 
                CLIENT_GetLastError(), dah_get_user_id(&dah_srv->parm));
            if(talk->frm)
            {
                nmp_dealloc(talk->frm, sizeof(frame_t) + MAX_ENCODE_BUFFER_LEN);
                talk->frm = NULL;
            }
            return -1;
        }
    }

    return 0; 
}
Exemple #29
0
static int dah_talk_recv(struct service *srv, talk_info_t *talk, char *data, int len, media_info_t *info)
{
    int ret = -1;
    dah_service_t *dah_srv;
    int send_count = 0;
    unsigned char out_buffer[MAX_ENCODE_BUFFER_LEN];
    unsigned char in_buffer[MAX_ENCODE_LEN];
    unsigned int out_buffer_len = MAX_ENCODE_BUFFER_LEN;
    char pcm_data[MAX_ENCODE_BUFFER_LEN];
    int out_pcm_data_len = 0;
    unsigned int in_data_len = 0;
    frame_t *frm = NULL;

    NMP_ASSERT(srv && talk && data);

    frm = (talk_frame_hdr_t*)data;
    if(ntohl(frm->magic) != TALK_MAGIC)
    {
        show_warn("magic[0x%x] error", ntohl(frm->magic));
        return -1;
    }
    in_data_len = ntohl(frm->frame_length);
    memcpy(in_buffer, frm->frame_data, in_data_len);
    //memset(pcm_data, 0, MAX_ENCODE_BUFFER_LEN);

    if(info->attr.encode_type == 0)
    {
        memcpy(pcm_data, in_buffer, in_data_len);
        out_pcm_data_len = in_data_len;
    }
    else if(info->attr.encode_type == 1)
    {
        g711a_Decode2(in_buffer, pcm_data, (int)in_data_len, &out_pcm_data_len);
    }
    else if(info->attr.encode_type == 2)
    {
        g711u_Decode(in_buffer, pcm_data, (int)in_data_len, &out_pcm_data_len);
    }

    dah_srv = (dah_service_t*)srv;
    if( in_data_len <= MAX_ENCODE_LEN)
    {
        //memset(out_buffer, 0, MAX_ENCODE_BUFFER_LEN);
        ret = CLIENT_AudioEncode(0, (unsigned char*)pcm_data, 
                (unsigned int*)&out_pcm_data_len, out_buffer, &out_buffer_len);
        if(ret != 0)
        {
            show_warn("CLIENT_AudioEncode error ret = 0x%x in_data_len = %d out_buffer_len = %d\n",
                ret, in_data_len, out_buffer_len);
            return -1;  
        }
        send_count = CLIENT_TalkSendData(talk->talk_handle, (char*)out_buffer, out_buffer_len);
        if(send_count < 0)          
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }

    return ret;
}
Exemple #30
0
static int 
bsm_get_device_config(struct service *srv, int parm_id, void *parm)
{
    int ret = HI_FAILURE;
    int user_id;

    JDevCap *dev_cap;
    bsm_config_t *config;
    bsm_service_t*bsm_srv;

    NMP_ASSERT(srv && parm);

    bsm_srv = (bsm_service_t*)srv;
    user_id = bsm_get_user_id(&bsm_srv->parm);

    if (BSM_LOGOUT == user_id)
    {
        show_debug("Proxy device logout!!!!!!!!!!!!!!\n");
        return -1;
    }

    switch (parm_id)
    {
        case GET_DEVICE_CONFIG:
            goto GET_CFG;
        case GET_NETWORK_CONFIG:
            goto GET_CFG;
        case GET_FTP_CONFIG:
            goto GET_CFG;
        case GET_SMTP_CONFIG:
            goto GET_CFG;
        case GET_DDNS_CONFIG:
            goto GET_CFG;
        case GET_DISK_LIST:
            goto GET_CFG;
        case GET_ENCODE_CONFIG:
            goto GET_CFG;
        case GET_DISPLAY_CONFIG:
            goto GET_CFG;
        case GET_OSD_CONFIG:
            goto GET_CFG;
        case GET_PTZ_CONFIG:
            goto GET_CFG;
        case GET_MOTION_CONFIG:
            goto GET_CFG;

        case GET_CAPABILITY_SET:
            dev_cap = (JDevCap*)parm;
            dev_cap->cap0 = DEV_CAP_VIDEO_IN | DEV_CAP_AUDIO | DEV_CAP_IRIS | DEV_CAP_PTZ | 
                DEV_CAP_ALARM_IN | DEV_CAP_ALARM_OUT | DEV_CAP_STORAGE | DEV_CAP_WEB | DEV_CAP_PLATFORM | 
                DEV_CAP_INTELLIGENT_ANALYSIS | DEV_CAP_UPDATE | DEV_CAP_VIDEO_OUT;// | DEV_CAP_IR;
            dev_cap->ftp_enable = 1;
            dev_cap->upnp_enable = 0;
            dev_cap->chn_cap.size = sizeof(JChnCap);
            dev_cap->chn_cap.encode = VIDEO_ENCODE_H264_E | VIDEO_ENCODE_MJPEG_E | 
                VIDEO_ENCODE_JPEG_E | VIDEO_ENCODE_MPEG4_E;
            dev_cap->chn_cap.supp_mask = 1;
            dev_cap->chn_cap.mask_count = 4;
            dev_cap->chn_cap.supp_hide_alarm = 1;
            dev_cap->chn_cap.hide_alarm_count = 1;
            dev_cap->chn_cap.supp_move_alarm = 1;
            dev_cap->chn_cap.move_alarm_count = 1;
            dev_cap->chn_cap.supp_video_lost_alarm = 1;
            dev_cap->chn_cap.osd_count = 1;
            dev_cap->chn_cap.stream_count = 2;
            dev_cap->chn_cap.stream_supp_resolution[0] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
                CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_720P;
            dev_cap->chn_cap.stream_supp_resolution[1] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
                CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_720P;
            dev_cap->chn_cap.stream_supp_resolution[2] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
                CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_720P;
            dev_cap->chn_cap.stream_supp_resolution[3] = CAP_VIDEO_QCIF | CAP_VIDEO_CIF | 
                CAP_VIDEO_D1 | CAP_VIDEO_QQVGA | CAP_VIDEO_QVGA | CAP_VIDEO_VGA | CAP_VIDEO_720P;
            dev_cap->chn_cap.stream_max_frate_rate[0] = 25;
            dev_cap->chn_cap.img_cap = IMA_BRIGHTNESS | IMA_CONTRAST | IMA_SATURATION | IMA_HUE;
            ret = HI_SUCCESS;
            break;

        default:
            ret = HI_FAILURE;
            show_warn("parm_id Invalid!!!!!\n");
            break;
    }

    if (HI_SUCCESS == ret)
        return 0;
    else
        return -1;

GET_CFG:
    config = (bsm_config_t*)parm;
    ret = HI_NET_DEV_GetConfig(
            (HI_U32)  user_id, 
            (HI_U32)  config->command, 
            (HI_VOID*)config->buffer, 
            (HI_U32)  config->b_size);
    show_debug("HI_NET_DEV_GetConfig: %s<-------------------------------\n", 
        (ret == HI_SUCCESS) ? "Success" : "Failure");
    if (HI_SUCCESS == ret)
        return 0;
    else
        return -1;
}