示例#1
0
unsigned char objPutCard::putCardProcess()
{
    qDebug()<<Q_FUNC_INFO;
    unsigned char ucResult = 0;
    unsigned char aucBuf[20];
    unsigned short usLength = 0;

    while(1)
    {
        ucResult = EventProcess(true, false, true);
        if(ucResult)
            break;

        if(getEventType() == Mag)
        {
            qDebug()<<"Mag is swiped";
            pxMagObj=GetPxMag();
            qDebug("\n+++++ SwipeCard [MAG EVENT] --------+++++++++++++++++\n");
            unsigned char length1 = pxMagObj->xxdata[0];
            unsigned char length2 = pxMagObj->xxdata[length1+2];
            if((length1==0)&&(length2==0))
                return(ERR_MAG_TRACKDATA);
            else
            {
                if(GetTrackInfo((unsigned char*)pxMagObj) != 0)
                    return(ERR_NOTPROC);
            }
            break;
        }
        else if(getEventType() == Untouch)
        {
            memset(aucBuf, 0, sizeof(aucBuf));
            ucResult = MIFARE_readCardNo(GetMifare(), 254, aucBuf, &usLength);
            QString tmp=QString::fromAscii((const char*)aucBuf);
            qDebug()<<"tmp::"<<tmp<<tmp.size();
            if(tmp.size()<5)
                return ERR_MFCDRV;
            qDebug("card is %s", aucBuf);
            qDebug("card len is %d", usLength);
            if(ucResult)
                return ERR_MFCDRV;
            else
            {
                memset(G_NORMALTRANS_aucSourceAcc, 0, sizeof(G_NORMALTRANS_aucSourceAcc));
                memcpy(G_NORMALTRANS_aucSourceAcc, aucBuf, usLength);
                G_NORMALTRANS_ucMainAccountLen = usLength;
                break;
            }
        }
        else if(getEventType() == Key)
        {
            ucResult = KEYDrv_Process();

            if(ucResult==ERR_CANCEL)
            {
                break;
            }
            if(ucResult==ERR_CARDNOACT)
            {
                // 没有手动
                if(NormalTransData.transType==TransMode_CashAdvance && g_constantParam.advance.MANUAL_ENABLE==false)
                {
                     ucResult = 0;
                }
                if(NormalTransData.transType==TransMode_CashDeposit && g_constantParam.deposit.MANUAL_ENABLE==false)
                {
                     ucResult = 0;
                }
                if(NormalTransData.transType==TransMode_BalanceInquiry && g_constantParam.balance.MANUAL_ENABLE==false)
                {
                     ucResult = 0;
                }
                if(NormalTransData.transType==TransMode_CardTransfer && g_constantParam.p2p.MANUAL_ENABLE==false)
                {
                     ucResult = 0;
                }
                if(NormalTransData.transType==TransMode_AdvanceVoid && g_constantParam.transvoid.MANUAL_ENABLE==false)
                {
                     ucResult = 0;
                }
                if(NormalTransData.transType==TransMode_DepositVoid && g_constantParam.transvoid.MANUAL_ENABLE==false)
                {
                     ucResult = 0;
                }
                if(g_constantParam.adjust.MANUAL_ENABLE == false
                && (NormalTransData.transType == TransMode_AdvanceAdjust
                 || NormalTransData.transType == TransMode_DepositAdjust))
                {
                     ucResult = 0;
                }
                if(NormalTransData.transType==TransMode_PINChange && g_constantParam.pinchange.MANUAL_ENABLE==false)
                {
                     ucResult = 0;
                }


                // 进入手动
                if(NormalTransData.transType==TransMode_CashAdvance && g_constantParam.advance.MANUAL_ENABLE==true)
                {
                    break;
                }
                if(NormalTransData.transType==TransMode_CashDeposit && g_constantParam.deposit.MANUAL_ENABLE==true)
                {
                    break;
                }
                if(NormalTransData.transType==TransMode_BalanceInquiry && g_constantParam.balance.MANUAL_ENABLE==true)
                {
                    break;
                }
                if(NormalTransData.transType==TransMode_CardTransfer && g_constantParam.p2p.MANUAL_ENABLE==true)
                {
                    break;
                }
                if(NormalTransData.transType==TransMode_AdvanceVoid && g_constantParam.transvoid.MANUAL_ENABLE==true)
                {
                    break;
                }
                if(NormalTransData.transType==TransMode_DepositVoid && g_constantParam.transvoid.MANUAL_ENABLE==true)
                {
                    break;
                }
                if(g_constantParam.adjust.MANUAL_ENABLE == true
                && (NormalTransData.transType == TransMode_AdvanceAdjust
                 || NormalTransData.transType == TransMode_DepositAdjust))
                {
                    break;
                }
                if(NormalTransData.transType==TransMode_PINChange && g_constantParam.pinchange.MANUAL_ENABLE==true)
                {
                    break;
                }
            }
        }
        else
        {
            ucResult = ERR_UNKNOWNDRV;
            break;
        }
    }
    RemoveKeyEventBug();
    return ucResult;
}
示例#2
0
void LogManager::calcStatistic()
{
	int len = events.size();
	totaltime = GetTimeDifference(toSystemTime(events[0].timestamp),toSystemTime(events[len-1].timestamp));
	
	EventProcess p(events[0].processName); p.from = 0;
	vector<LogEvent> keys;
	bool hasPushCtrl = false;
	for(int i=0; i<len-1; i++)
	{
		//LogEvent e = events[i];
		
		events[i].duration = GetTimeDifference(toSystemTime(events[i].timestamp),toSystemTime(events[i+1].timestamp));
		if(events[i].isHasAcc) 
		{
			accui_events.push_back(i);

			string acc_name = events[i].acc.name;
			std::transform(acc_name.begin(), acc_name.end(), acc_name.begin(), ::tolower);
			int acc_index = acc_name.find("paste");
			if(acc_index>=0 && events[i].acc.type == "menu item")
			{
				PasteEvent pe;
				pe.timestamp = events[i].timestamp;
				pe.windowName = events[i].windowName;
				pe.processName = events[i].processName;
				pe.parentWindowName = events[i].parentWindowName;
				pe.method = "Menu -> Paste";
				paste_events.push_back(pe);
			}
		}

		if(events[i].isHasSrceenshot)
		{
			screenshot_events.push_back(i);
		}

		process_set.insert(events[i].processName);
		window_set.insert(events[i].windowName);
		//events_map[events[i].timestamp] = i;
		
		if(events[i].eventType == "keyinput")
		{
			if(hasPushCtrl)
			{
				keys.push_back(events[i]);
				if(events[i].name != "Ctrl" && events[i].name != "Shift" && events[i].name != "Alt")
				{
					hasPushCtrl = false;
					keyEvents.push_back(keys);

					string keystr = this->keysToString(keys);
					if(keystr == "Ctrl+V")
					{
						PasteEvent pe;
						pe.timestamp = keys[0].timestamp;
						pe.windowName = keys[0].windowName;
						pe.processName = keys[0].processName;
						pe.parentWindowName = keys[0].parentWindowName;
						pe.method = keystr;
						paste_events.push_back(pe);
					}
					keys = vector<LogEvent>();
				}
			}
			else
			{
				if(events[i].name == "Ctrl")
				{
					hasPushCtrl = true;
					keys.push_back(events[i]);
				}
				else if(events[i].name.size()>1 && events[i].name.substr(0,1) == "F")
				{
					keys.push_back(events[i]);
					keyEvents.push_back(keys);
					keys = vector<LogEvent>();
				}
				else
				{
					if(keys.size()>0)
					{
						keyEvents.push_back(keys);
						keys = vector<LogEvent>();
					}
				}
			}
			
		}

		if(i>0)
		{
			if(events[i].processName != p.name)
			{
				p.to = i - 1;

				if(process_stat.find(p.name) != process_stat.end())
				{
					process_stat[p.name] += calcDuration(p.from, p.to);
				}
				else
				{
					process_stat[p.name] = calcDuration(p.from, p.to);
				}

				processes.push_back(p);
				p = EventProcess(events[i].processName);
				p.from = i;
			}
			
		}
	}

	p.to = len - 1;
	processes.push_back(p);
}
示例#3
0
文件: server.cpp 项目: lygn128/Tinyfs
int server::listenAndserve() {
    char * sfdstr     = getenv("sfd");
    char * epollfdstr = getenv("epollfd");

    //return 0;
    if(sfdstr){
        sfd = atoi(sfdstr);
    }
    if(epollfdstr) {
        //epollfd = atoi(epollfdstr);
    }
    if(sfd == 0) {
        sfd = socket(AF_INET,SOCK_STREAM,0);
        int flag = fcntl(sfd,F_GETFL,0);
        int result = fcntl(sfd,F_SETFL,flag | O_NONBLOCK);
        if(sfd < 0) {
            printf("create socket error\n");
            exit(-1);
            //closeProc();
        }
        struct sockaddr_in addr;
        bzero(&addr,sizeof(addr));
        addr.sin_family      = AF_INET;
        addr.sin_addr.s_addr = htonl(INADDR_ANY);
        addr.sin_port        = htons(10001);
        printf("port is %d\n",addr.sin_port);


        int on;
        on = 1;
        setsockopt(sfd,SOL_SOCKET,SO_REUSEADDR,&on, sizeof(on));

        int bid = bind(sfd,(struct sockaddr*)&addr,sizeof(struct sockaddr));
        if(bid < 0) {

            printf("bind err\n");
            printError(errno,__LINE__);
            exit(-1);
            //closeProc();
        }

        int lister = listen(sfd,10);
        if(lister < 0){
            printError(errno,__LINE__);
            exit(-1);
            //closeProc();
        }else {
            printf("listen sucess\n");
        }

    }

    if(epollfd == 0) {
        epollfd = epoll_create1(0);
        printf("epofd = %d\n",epollfd);

    }
    {
        Connection * sfdConnect = new Connection(sfd,NULL);
        int add = EventProcess(epollfd,sfd,EPOLL_CTL_ADD,EPOLLET|EPOLLIN|EPOLLOUT,sfdConnect);
        if(add < 0) {
            printError(errno,__LINE__);
            exit(-1);
            //closeProc();
        }
    }
    printf("------------------\n");
    logger->Loginfo("sfd = %d sfd = %d",sfd,epollfd);


    {
        int x = pipe(loopSwitch);
        if(x < 0) {
            printf("create pipe err\n");
        }
        //loopSwitch = open("./loopSwitch",O_CREAT|O_RDWR,0644);
        Connection * sfdConnect = new Connection(loopSwitch[0],NULL);
        int add = EventProcess(epollfd,loopSwitch[0],EPOLL_CTL_ADD,EPOLLET|EPOLLIN|EPOLLOUT,sfdConnect);
//        if(add < 0) {
//            printf("add looperr errno  %d\n",errno);
//        }
        if(add < 0) {
            printError(errno,__LINE__);
            exit(-1);
            //closeProc();
        }
    }

    int subfd = 0;
    struct sockaddr_in remoteaddr;
    socklen_t len;
    struct epoll_event *eventArry = (struct epoll_event*)malloc(sizeof(struct epoll_event) * MAXEVENTS);
    int num = 0,index = 0;
    while(true) {
        bzero(eventArry,sizeof(struct epoll_event) * MAXEVENTS);
        struct sigaction act;
        int sig = SIGSEGV;
        sigemptyset(&act.sa_mask);
        sigaddset(&act.sa_mask,SIGUSR1);
        sigaddset(&act.sa_mask,SIGUSR2);
        num = epoll_pwait(epollfd,eventArry,MAXEVENTS,-1,NULL);
        //printf("wait success num = %d  err  %d pid = %d\n",num,errno,getpid());
        int xx = errno;
        if(num == -1) {
            switch(xx) {
                case EBADF:{
                    break;
                }
                case EFAULT:{
                    break;
                }
                case EINTR:{
                    break;
                }
                case EINVAL:{
                    break;
                }
            }
            continue;
        }

//        EBADF  epfd is not a valid file descriptor.
//
//        EFAULT The memory area pointed to by events is not  accessible  with  write  permis‐
//        sions.
//
//        EINTR  The  call  was  interrupted  by a signal handler before either (1) any of the
//        requested events occurred or (2) the timeout expired; see signal(7).
//
//        EINVAL epfd is not an epoll file descriptor, or maxevents is less than or  equal  to
//        zero.
        for(index = 0;index < num; index++) {
            Connection * context = (Connection*)eventArry[index].data.ptr;
            int aFd   = context->fd;
            int subfd = -1;
            if(aFd == sfd) {
                if(accepton) {
                    while((subfd = accept(sfd,(struct sockaddr*)&remoteaddr,&len)) > 0){

                        Connection * connection = new Connection(subfd,&remoteaddr);
                        //printf("172 addr %x\n",connection);
                        EventProcess(epollfd,subfd,EPOLL_CTL_ADD,EPOLLET|EPOLLIN ,connection);
                        //handleConnect(connection);
                        connection->readHandler = &readHandler;
                    }
                }
            }else if( aFd == loopSwitch[0] ||aFd == loopSwitch[1]){
                printf("pipe closed\n");
                return 0;
            } else {
                Connection * connection = (Connection*)eventArry[index].data.ptr;
                //printf("179 addr %x\n",connection);
                if(eventArry[index].events & EPOLLIN) {
                    if(connection->readHandler != NULL){
                        int x = connection->readHandler(connection);
                        if(x == 0) {
                            EventProcess(epollfd,aFd,EPOLL_CTL_DEL,0,NULL);
                            connection->Close();
                            delete(connection);
                        }
                    }

                }

            }
        }

       // subfd = accept(sfd,(struct sockaddr*)&remoteaddr,&len);
        //printf("remoate port %d\n",remoteaddr.sin_port);
        //close(subfd);
    }

}