Example #1
0
/*
 系统初始化和Initialize.xml更新时需要刷新注册,但Initialize.xml由push系统自己注册。
 regist_flag
 	0 means unregist
 	1 means resgist
*/
static int parse_progs()
{
	int ret = -1;
	int i = 0;
	PUSH_XML_FLAG_E push_flag = PUSH_XML_FLAG_UNDEFINED;
	RECEIVETYPE_E recv_type = -1;
	int product_id = -1;
	char sqlite_cmd[1024];
	int (*sqlite_callback)(char **, int, int, void *, unsigned int) = parse_progs_cb;
	int resgist_action = 0;
	
	s_mom_progs_p = (MOM_PROG_S *)malloc(sizeof(MOM_PROG_S) * MOM_PROG_NUM);
	if(NULL==s_mom_progs_p){
		DEBUG("can not malloc %d*%d memery to save mother progs\n", sizeof(MOM_PROG_S),MOM_PROG_NUM);
		ret = -1;
	}
	else{
		sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT ReceiveType,DescURI,productID FROM ProductDesc;");
		ret = sqlite_read(sqlite_cmd, (void *)(&resgist_action), sizeof(resgist_action), sqlite_callback);
		DEBUG("ret=%d\n", ret);
		
		for(i=0;i<MOM_PROG_NUM;i++)
		{
			if(strlen(s_mom_progs_p[i].DescURI)>0){
				s_receive_status = RECEIVESTATUS_FINISH;
				recv_type = atoi(s_mom_progs_p[i].ReceiveType);
				
				if(RECEIVETYPE_PUBLICATION==recv_type || RECEIVETYPE_PREVIEW==recv_type){
					push_flag = PUBLICATION_XML;
				}
				else if(RECEIVETYPE_COLUMN==recv_type){
					push_flag = COLUMN_XML;
				}
				else if(RECEIVETYPE_SPRODUCT==recv_type){
					push_flag = SPRODUCT_XML;
				}
				else{
					DEBUG("%d(%s) can not be distinguish\n", recv_type, s_mom_progs_p[i].DescURI);
					push_flag = PUSH_XML_FLAG_UNDEFINED;
				}
		
				if(PUSH_XML_FLAG_UNDEFINED!=push_flag){
					product_id = atoi(s_mom_progs_p[i].productID);
					s_receive_status = RECEIVESTATUS_FINISH;
		
					// 确保在解析Publications.xml之前,明确得到s_receive_status,因为在解析入库时需要判断
					if(0==parse_xml(s_mom_progs_p[i].DescURI, push_flag, NULL)){
						DEBUG("parse %s success\n", s_mom_progs_p[i].DescURI);
					}
					else{
						DEBUG("parse %s failed\n", s_mom_progs_p[i].DescURI);
					}
				}
			}
		}
	
	}
	
	return ret;
}
Example #2
0
/*
 初始化及反初始化demux过滤器
 act_flag:	1——初始化demux过滤器
 			0——反初始化demux过滤器
*/
int pid_init(int act_flag)
{
	char sqlite_cmd[256+128];
	int (*sqlite_callback)(char **, int, int, void *, unsigned int) = allpid_sqlite_cb;

	sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT pid,pidtype,FreshFlag FROM Channel;");
	// 1 means alloc filter
	int filter_act = act_flag;
	return sqlite_read(sqlite_cmd, &filter_act, sizeof(filter_act), sqlite_callback);
}
Example #3
0
void *thread_handler(struct socket_data *data) //看多线程是不是可以用同一个handler函数。
{
    struct socket_data client_data;
    int len = 0;

    client_data = *data;
    pthread_mutex_unlock(&mutex);

    memset(client_data.buff,0,sizeof(client_data.buff));
    len = read(client_data.socket, client_data.buff, 1);

    printf("this is table :%d\n", client_data.buff[0]);

    memset(client_data.buff,0,sizeof(client_data.buff));

    len = read(client_data.socket, client_data.buff, BUFFER_SIZE);
    //while((len = read(client_data.socket, client_data.buff, BUFFER_SIZE)) > 0)
    //{
        switch(client_data.buff[0])
        {
            case 0:
                break;
                debug("this is the meal list \n");
            case 1:
                break;
                debug("meal ok\n");
            case 2:
                debug("requist server\n");
                break;
            default:
                break;
        }
        //printf("receive client %d :%s\n",client_data.socket, client_data.buff);
        //write(client_data.socket, client_data.buff, len);
        //memset(client_data.buff, 0, len);
   //} while

    printf("the socket is:%d\n", client_data.socket);
    sqlite_read(&client_data);

    debug("this client exit\n");
    close(client_data.socket);

    // 每个线程的handler一样,但传进来的参数不一样。数据结构不一样,每一个线程都有自己的数据结构。
    // 每个线程创建时同时创建它的数据结构,以其线程号为后缀,以参数形式传个handler。
    //每个线程应该做的事。
    //read_data_bass() // 读数据库。
    //sendmsg() //发送菜单。
    //while(readmsg() > 0) //一直等待client的消息。
    //{
        //switch()  //对消息进行解析,看是点好的菜单,还是呼唤服务员
        //{
        //}
        //}
}
Example #4
0
int softwareVersion_get(char *version, unsigned int len)
{
	if(NULL==version || 0==len)
		return -1;

	char sqlite_cmd[SQLITECMDLEN];	
	int (*sqlite_callback)(char **, int, int, void *) = setting_sqlite_callback;

	memset(sqlite_cmd, 0, sizeof(sqlite_cmd));
	snprintf(sqlite_cmd,sizeof(sqlite_cmd),"SELECT value FROM global WHERE name='version';");
	INSTRUCTION_RESULT_E ret = sqlite_read(sqlite_cmd, version, sqlite_callback);
	if(ret<=RESULT_OK){
		DEBUG("read 'version' from table 'global' failed, read from ini\n");
		strncpy(version, s_version, len);
	}
	
	return 0;
}
Example #5
0
int smartpower_server_port_get(void)
{
	char server_port[16];
	char sqlite_cmd[SQLITECMDLEN];	
	int (*sqlite_callback)(char **, int, int, void *) = setting_sqlite_callback;

	memset(server_port, 0, sizeof(server_port));
	memset(sqlite_cmd, 0, sizeof(sqlite_cmd));
	snprintf(sqlite_cmd,sizeof(sqlite_cmd),"SELECT value FROM global WHERE name='port';");
	INSTRUCTION_RESULT_E ret = sqlite_read(sqlite_cmd, server_port, sqlite_callback);
	if(ret<=RESULT_OK || 0>=atoi(server_port)){
		DEBUG("read 'port' from table 'global' failed, read from ini\n");
		return s_server_port;
	}
	else{
		return atoi(server_port);
	}
}
Example #6
0
int smartpower_server_ip_get(char *server_ip, unsigned int len)
{
	if(NULL==server_ip || 0==len)
		return -1;

	char sqlite_cmd[SQLITECMDLEN];	
	int (*sqlite_callback)(char **, int, int, void *) = setting_sqlite_callback;

	memset(sqlite_cmd, 0, sizeof(sqlite_cmd));
	snprintf(sqlite_cmd,sizeof(sqlite_cmd),"SELECT value FROM global WHERE name='serverIP';");
	INSTRUCTION_RESULT_E ret = sqlite_read(sqlite_cmd, server_ip, sqlite_callback);
	if(ret<=RESULT_OK){
		DEBUG("read 'serverIP' from table 'global' failed, read from ini\n");
		strncpy(server_ip, s_server_ip, len);
	}
	
	return 0;
}
Example #7
0
int main(int argc, const char *argv[])
{
    sqlite3 *db;
    char buff[256] = {0};
    char name[100] = {0};
    char info[256] = {0};
    int *len = NULL;

    struct socket_data sock_data;
    char *ptr = sock_data.buff;

    db = sqlite_init();

    sqlite_read(db, &sock_data);

    printf("id = %d\n",*((int *)ptr));
    ptr+=4;

    len = (int *)ptr;
    //printf("len of name is :%d \n", *len);
    ptr+=4;

    strncpy(name, ptr, *len);
    printf("name is :%s\n",name);
    ptr+=*len;

    printf("price = %d\n",*((int *)ptr));
    ptr+=4;

    len = (int *)ptr;
    //printf("len of info is :%d \n", *len);
    ptr+=4;

    strncpy(info, ptr, *len);
    printf("info is :%s\n",info);


    sqlite_close(db);
    
    return 0;
}
Example #8
0
/*
功能:	将数据库中的设备列表读出,存入内存中。开机、插入设备、更新设备、删除设备后均调用此函数。
返回:	0——成功;-1——失败
*/
int equipment_refresh(void)
{
	char sqlite_cmd[SQLITECMDLEN];
	int (*sqlite_callback)(char **, int, int, void *) = equipment_sqlite_callback;
	
	sem_wait(&s_sem_equipment);
	int i = 0;
	for(i=0;i<EQUIPMENT_NUM;i++)
		g_equipments[i].type_id = -1;
	sem_post(&s_sem_equipment);
	
	memset(sqlite_cmd, 0, sizeof(sqlite_cmd));
	sprintf(sqlite_cmd,"SELECT typeID,locationID,iconID,operID,socketID,roomName,devName,elecData FROM devlist;");
	INSTRUCTION_RESULT_E ret = sqlite_read(sqlite_cmd, NULL, sqlite_callback);
	if(ret<RESULT_OK)
		ret = -1;
	else
		ret = 0;

	return ret;
}
Example #9
0
int serialNum_get(char *sn, unsigned int len)
{
	if(NULL==sn || 0==len)
		return -1;
	
//	if(strlen(s_serial_num)>10){
//		strncpy(sn, s_serial_num, len);
//		return 0;
//	}
		
	char sqlite_cmd[SQLITECMDLEN];	
	int (*sqlite_callback)(char **, int, int, void *) = setting_sqlite_callback;

	memset(sqlite_cmd, 0, sizeof(sqlite_cmd));
	snprintf(sqlite_cmd,sizeof(sqlite_cmd),"SELECT value FROM global WHERE name='serialNUM';");
	INSTRUCTION_RESULT_E ret = sqlite_read(sqlite_cmd, sn, sqlite_callback);
	if(ret<=RESULT_OK){
		DEBUG("read 'sn' from table 'global' failed, read from ini\n");
		strncpy(sn, s_serial_num, len);
	}
	
	return 0;
}