void CDbtestAppUi::success(CBase* source)
{ 
	TBuf<30> msg;
	msg.Format(_L("success %d"), current_state);
	if (current_state==CONNECTING) {
		//ftp->Retrieve(_L("README"));
		//ftp->Store(_L("s.txt"));
		//TInt size=40000;
		//CAknNumberQueryDialog* d=CAknNumberQueryDialog::NewL(size);
		//d->ExecuteLD(R_DBTEST_INPUT);
		//wap->Store(_L("s.txt"));
		current_state=RETRIEVING;
	} else if (current_state==RETRIEVING) {
		current_state=CLOSING;
		//ftp->Close();
		//wap->Close();
	}
	status_change(msg); 
}
void CContextLocaAppUi::HandleCommandL(TInt aCommand)
{
	CALLSTACKITEM_N(_CL("CContextLocaAppUi"), _CL("HandleCommandL"));

	SetInHandlableEvent(ETrue);
#ifdef __WINS__
	TInt err;
	TBreakItem b(GetContext(), err);
#endif
	if (BaseHandleCommandL(aCommand)) return;

	switch ( aCommand )
	{
	case Econtext_logCmdAppPauseLog:
		Settings().WriteSettingL(SETTING_LOGGING_ENABLE, EFalse);
		break;
	case Econtext_logCmdAppUnPauseLog:
		Settings().WriteSettingL(SETTING_LOGGING_ENABLE, ETrue);
		break;
	case Econtext_logCmdCancelSend:
		// do nothing
		break;
	case Econtext_logCmdAppSettings:
		ActivateLocalViewL(KSettingsViewId);
		break;
	case Econtext_logCmdDumpCommDb:
		{
		CCommDbDump* dump=CCommDbDump::NewL();
		dump->DumpDBtoFileL(_L("c:\\commdb.txt"));
		delete dump;
		}
		break;
	case Econtext_logCmdCreateAp:
		{
		CreateAPL(_L("cingular"),
			_L("WAP.CINGULAR"),
			_L("*****@*****.**"),
			_L("CINGULAR1"));
		}
		break;
	case Econtext_logCmdStartSensors:
		{
			if  (!iSensorRunner)
				iSensorRunner=CSensorRunner::NewL(
					AppContext(), smsh, EFalse, *this);
		}
		break;

	case Econtext_logCmdAppTest:
		{
		//loc->test();
		//recorder->test();
		DialogTest();
		}
		break;
	case Econtext_logCmdAppImsi:
		{
			/*if (loc) status_change(loc->GetImsi());
			else */{
#ifndef __WINS__
				TBuf<20> machineId;
				GetImeiL(machineId);
				status_change(machineId);
#else
				// Return a fake IMEI when working on emulator
				_LIT(KEmulatorImsi, "244050000000000");
				status_change(KEmulatorImsi);
#endif
			}
		}
			
		break;
	default:
		if (aCommand>Econtext_logCmdSendAppUi || aCommand==Econtext_logCmdSendFtp) {
			
			if (aCommand==Econtext_logCmdSendFtp) {
				//iPeriodicTransfer->Transfer(false);
				//iPeriodicTransfer->Transfer(true);
			} else {
				status_change(_L("trying transfer"));

				/*
				cellid_name_file.Close();
				*/
				
				TFileName transfer_cellid_filen, cellid_filen;
				transfer_cellid_filen.Format(_L("%S%S"), &AppDir(), &transfer_cellid_file);
				cellid_filen.Format(_L("%S%S"), &DataDir(), &cellid_file);

				TInt ferr=BaflUtils::CopyFile(Fs(), cellid_filen, transfer_cellid_filen);
				if (ferr!=KErrNone) {
					TBuf<30> errmsg;
					errmsg.Format(_L("copy: %d"), ferr);
					error(errmsg);
					return;
				}
				/*
				ferr=cellid_name_file.Open(Fs(), cellid_filen, 
					EFileShareAny | EFileStreamText | EFileRead | EFileWrite);
				if (ferr!=KErrNone) {
					TBuf<30> errmsg;
					errmsg.Format(_L("reopen: %d, RESTART NOW"), ferr);
					error(errmsg);
					return;
				}
				*/
				iLog->switch_file();

				transferer->transfer_files(aCommand);
			}
			
		}
		break;
	}
}
Example #3
0
void work(void) {
    fd_set fds;
    int sigfd;
    static char log_ident[256];

    snprintf(log_ident, sizeof(log_ident), "ifplugd");

    daemon_log_ident = log_ident;

    daemon_log(LOG_INFO, "ifplugd "VERSION" initializing, using NETLINK device monitoring");

    if (daemon_pid_file_create() < 0) {
        daemon_log(LOG_ERR, "Could not create PID file %s.", daemon_pid_file_proc());
        goto finish;
    }

    if (daemon_signal_init(SIGINT, SIGTERM, SIGQUIT, SIGHUP, SIGCHLD, SIGUSR1, SIGUSR2, -1) < 0) {
        daemon_log(LOG_ERR, "Could not register signal handler: %s", strerror(errno));
        goto finish;
    }

    if ((netlink = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
        daemon_log(LOG_ERR, "socket(): %s", strerror(errno));
        goto finish;
    }

    rbus = rbus_init("unix!/tmp/ifplugd.9p");
    rbus->rbus.childs = &root_children[0];

    discover(netlink);

    if (nlapi_open(RTMGRP_LINK) < 0)
        goto finish;

    if (ifmonitor_init(ifmonitor_cb) < 0)
        goto finish;

    FD_ZERO(&fds);
    sigfd = daemon_signal_fd();
    FD_SET(sigfd, &fds);

    FD_SET(nlapi_fd, &fds);


    for (;;) {
        struct interface_state *iface;

        fd_set qfds = fds;
        struct timeval tv;

        IxpConn *c;
        for(c = rbus->srv->conn; c; c = c->next) {
            if(c->read) {
                FD_SET(c->fd, &qfds);
            }
        }

        tv.tv_sec = polltime;
        tv.tv_usec = 0;
        
        if (select(FD_SETSIZE, &qfds, NULL, NULL, &tv) < 0) {
            if (errno == EINTR)
                continue;

            daemon_log(LOG_ERR, "select(): %s", strerror(errno));
            goto finish;
        }

        //daemon_log(LOG_INFO, "select()");
        
        for(c = rbus->srv->conn; c; c = c->next) {
            if(c->read && FD_ISSET(c->fd, &qfds)) {
                c->read(c);
            }
        }
        
        if (FD_ISSET(nlapi_fd, &qfds)) {
            if (nlapi_work(0) < 0)
                goto finish;
        }

        for(iface = interface; iface; iface=iface->next) {

            if(! is_iface_available(netlink, iface->name)) {
                drop_interface(iface);
                continue;
            }

            detect_beat(netlink, iface);
            status_change(iface); 
        }

        if (FD_ISSET(sigfd, &qfds)) {
            int sig;

            if ((sig = daemon_signal_next()) < 0) {
                daemon_log(LOG_ERR, "daemon_signal_next(): %s", strerror(errno));
                goto finish;
            }

            switch (sig) {

                case SIGINT:
                case SIGTERM:
                    goto cleanup;
                    
                case SIGQUIT:
                    goto finish;
                    
                case SIGCHLD:
                    break;

                case SIGHUP:
                    break;
                    
                default:
                    daemon_log(LOG_INFO, "Ignoring unknown signal %s", strsignal(sig));
                    break;
            }
        }

    }

cleanup:
 
finish:

    if (netlink >= 0)
        close(netlink);

    nlapi_close();
    
    daemon_pid_file_remove();
    daemon_signal_done();
    
    daemon_log(LOG_INFO, "Exiting.");
}
Example #4
0
	void server_base::handle_message(send_function send_fn, 
		boost::function<void(client_info&)> close_fn, 
		boost::function<socket_info&(void)> socket_info_fn,
		int session_id, 
		const variant& msg)
	{
		const std::string& type = msg["type"].as_string();

		if(session_id == -1) {
			if(type == "create_game") {
				game_info_ptr g(new game_info(msg));
				if(!g->game_state) {
					std::cerr << "COULD NOT CREATE GAME TYPE: " << msg["game_type"].as_string() << "\n";
					send_fn(json::parse("{ \"type\": \"create_game_failed\" }"));
					return;
				}

				std::vector<variant> users = msg["users"].as_list();
				for(int i = 0; i != users.size(); ++i) {
					const std::string user = users[i]["user"].as_string();
					const int session_id = users[i]["session_id"].as_int();

					if(clients_.count(session_id) && session_id != -1) {
						std::cerr << "ERROR: REUSED SESSION ID WHEN CREATING GAME: " << session_id << "\n";
						send_fn(json::parse("{ \"type\": \"create_game_failed\" }"));
						return;
					}

					client_info& cli_info = clients_[session_id];
					cli_info.user = user;
					cli_info.game = g;
					cli_info.nplayer = i;
					cli_info.last_contact = nheartbeat_;
					cli_info.session_id = session_id;

					if(users[i]["bot"].as_bool(false) == false) {
						g->game_state->add_player(user);
					} else {
						g->game_state->add_ai_player(user, users[i]);
					}

					g->clients.push_back(session_id);
				}

				const game_context context(g->game_state.get());
				g->game_state->setup_game();

				games_.push_back(g);
				send_fn(json::parse(formatter() << "{ \"type\": \"game_created\", \"game_id\": " << g->game_state->game_id() << " }"));
			
				status_change();
				return;
			} else if(type == "observe_game") {
				const int id = msg["game_id"].as_int();
				const std::string user = msg["user"].as_string();
				const int session_id = msg["session_id"].as_int();

				game_info_ptr g;
				foreach(const game_info_ptr& gm, games_) {
					if(gm->game_state->game_id() == id) {
						g = gm;
						break;
					}
				}

				if(!g) {
					send_fn(json::parse("{ \"type\": \"unknown_game\" }"));
					return;
				}

				if(clients_.count(session_id)) {
					send_fn(json::parse("{ \"type\": \"reuse_session_id\" }"));
					return;
				}

				client_info& cli_info = clients_[session_id];
				cli_info.user = user;
				cli_info.game = g;
				cli_info.nplayer = -1;
				cli_info.last_contact = nheartbeat_;
				cli_info.session_id = session_id;

				g->clients.push_back(session_id);

				send_fn(json::parse(formatter() << "{ \"type\": \"observing_game\" }"));

				return;
			} else if(type == "get_status") {
				const int last_status = msg["last_seen"].as_int();
				if(last_status == status_id_) {
					status_fns_.push_back(send_fn);
				} else {
					send_fn(create_lobby_msg());
				}
				return;
			} else if(type == "get_server_info") {
				send_fn(get_server_info());
				return;
			} else {
				send_fn(json::parse("{ \"type\": \"unknown_message\" }"));
				return;
			}
		}
// ----------------------------------------------------
// CDbtestAppUi::HandleCommandL(TInt aCommand)
// ?implementation_description
// ----------------------------------------------------
//
void CDbtestAppUi::HandleCommandL(TInt aCommand)
{
	switch ( aCommand )
        {
        case EAknSoftkeyBack:
        case EEikCmdExit:
		{
			Exit();
			break;
		}
	case EdbtestCmdAppOBEX:
		//bt->transfer_logs();
		break;
        case EdbtestCmdAppTest:
		{
#if 0
			if (!is_open) {
				User::LeaveIfError(sockserv.Connect());
				User::LeaveIfError(sock.Open(sockserv, KAfInet, KSockStream, KUndefinedProtocol));
				TInetAddr a(INET_ADDR(128, 214, 48, 81) , 80);

				TRequestStatus s;
				sock.Connect(a, s);
				User::WaitForRequest(s);
				status_change(_L("opened"));
				is_open=true;
			} else {
				sock.CancelAll();
				sock.Close();
				sockserv.Close();
				status_change(_L("closed"));
				is_open=false;
			}
#else
#  if 0
			//transferer->log_gps();
			/*
			TInetAddr a(INET_ADDR(128, 214, 48, 81) , 21);
			ftp->Connect(a, _L8("tkt_cntx"), _L8("dKFJmqBi"));
			current_state=CONNECTING;
			*/
			/*
			run(this);
			*/
#  else
			//wap->Connect(1, _L("http://db.cs.helsinki.fi/~mraento/cgi-bin/put.pl"));
#  endif

#endif

		}
		break;
		
	case EdbtestCmdAppCommDb:
		{
			CCommDbDump* dump=CCommDbDump::NewL();
			CleanupStack::PushL(dump);
			dump->DumpDBtoFileL(_L("c:\\commdb.txt"));
			CleanupStack::PopAndDestroy();
		}
		break;
	case EdbtestCmdAppCert:
		{
			auto_ptr<CCertInstaller> i(CCertInstaller::NewL(AppContext()));
			i->InstallCertL(_L("c:\\hy.der"));
		}
	case EdbtestCmdAppDiscover:
		//discoverer->search();
		break;
	case EdbtestCmdAppCtmGSM:
		{
		TBuf<40> s;
		RDevRecharger c;
		TInt ret=0;
		TInt u=0;
		bool done=false;
		while (!done) {
			ret=c.Open(u);
			if (ret==KErrNone) {
				done=true;
			} else {
				++u;
				if (u==KNullUnit) done=true;
			}
		}
		if (ret!=KErrNone) {
			s.Format(_L("Open: %d"), ret);
		} else {
			TChargeInfoV1 i;
			i.iRawTemperature=i.iSmoothedTemperature=0;
			i.iChargeType=EChargeNone;
			TChargeInfoV1Buf b(i);
			c.ChargeInfo(b);
			s.Format(_L("%d r %d s %d t %d"), u, i.iRawTemperature, i.iSmoothedTemperature, i.iChargeType)	;
		}
		status_change(s);
		}
		break;

	case EdbtestCmdAppVibra:
		CFLDRingingTonePlayer* p;
		p=CFLDRingingTonePlayer::NewL(ETrue);
		p->SetVibra(ETrue);
		p->SetRingingType(0); 
		//((MFLDFileProcessor*)p)->ProcessFileL(_L("c:\\nokia\\sounds\\simple\\silent.rng"));
		((MFLDFileProcessor*)p)->ProcessFileL(_L("c:\\system\\apps\\context_log\\silent.rng"));
		break;
        default:
		break;      
        }
}
Example #6
0
	void server_base::handle_message(send_function send_fn, 
		boost::function<void(client_info&)> close_fn, 
		boost::function<socket_info&(void)> socket_info_fn,
		int session_id, 
		const variant& msg)
	{
		const std::string& type = msg["type"].as_string();

		if(session_id == -1) {
			if(type == "create_game") {

				game_info_ptr g(create_game(msg));

				if(!g) {
					send_fn(json::parse("{ \"type\": \"create_game_failed\" }"));
					return;
				}

				send_fn(json::parse(formatter() << "{ \"type\": \"game_created\", \"game_id\": " << g->game_state->game_id() << " }"));
			
				status_change();

				return;
			} else if(type == "get_status") {
				const int last_status = msg["last_seen"].as_int();
				if(last_status == status_id_) {
					status_fns_.push_back(send_fn);
				} else {
					send_fn(create_lobby_msg());
				}
				return;
			} else if(type == "get_server_info") {
				send_fn(get_server_info());
				return;
			} else {
				std::map<variant,variant> m;
				m[variant("type")] = variant("unknown_message");
				m[variant("msg_type")] = variant(type);
				send_fn(variant(&m));
				return;
			}
		}

		if(type == "observe_game") {
			fprintf(stderr, "ZZZ: RECEIVE observe_game\n");
			const int id = msg["game_id"].as_int(-1);
			const std::string user = msg["user"].as_string();

			game_info_ptr g;
			foreach(const game_info_ptr& gm, games_) {
				if(id == -1 || gm->game_state->game_id() == id) {
					g = gm;
					break;
				}
			}

			if(!g) {
				fprintf(stderr, "ZZZ: SEND unknown_game\n");
				send_fn(json::parse("{ \"type\": \"unknown_game\" }"));
				return;
			}

			if(clients_.count(session_id)) {
				fprintf(stderr, "ZZZ: SEND reuse_ssoin_id\n");
				send_fn(json::parse("{ \"type\": \"reuse_session_id\" }"));
				return;
			}

			client_info& cli_info = clients_[session_id];
			cli_info.user = user;
			cli_info.game = g;
			cli_info.nplayer = -1;
			cli_info.last_contact = nheartbeat_;
			cli_info.session_id = session_id;

			g->clients.push_back(session_id);

			send_fn(json::parse(formatter() << "{ \"type\": \"observing_game\" }"));
			fprintf(stderr, "ZZZ: RESPONDED TO observe_game\n");

			return;
		}