Пример #1
0
/**
 *	Get the edges emanating from this edge.
 *	Get a list of laths which represent the edges which share a vertex with
 *	the edge this lath represents.
 *
 *	@return	Pointer to an array of lath pointers.
 */
void CqLath::Qee(std::vector<const CqLath*>& Result) const
{
	Result.clear();
	std::vector<const CqLath*> ResQve1;
	Qve(ResQve1);
	std::vector<const CqLath*> ResQve2;
	ccf()->Qve(ResQve2);

	// The laths representing the edges radiating from the two vertices of the edge this lath represents
	// can be implemented by taking the union of Qve for this and cf() and removing the duplicate cf() if
	// it exists.
	Result.swap(ResQve1);
	//Result.insert(Result.end(), ResQve1.begin(), ResQve1.end());

	std::vector<const CqLath*>::iterator iLath;
	TqInt len2 = 0;
	for(iLath = ResQve2.begin(); iLath!=ResQve2.end(); iLath++)
	{
		if(ec() != (*iLath) && this != (*iLath))
			len2++;
	}

	TqInt index = Result.size();
	Result.resize( Result.size() + len2 );
	for(iLath = ResQve2.begin(); iLath!=ResQve2.end(); iLath++)
	{
		if(ec() != (*iLath) && this != (*iLath))
			Result[index++] = (*iLath);
	}
}
Пример #2
0
int main(int argc, const char* argv[]) {
    Options opt;
    if (!opt.read_options(argc, argv)) {
        std::cerr << "Error parsing command line options!" << std::endl;
        exit(EXIT_FAILURE);
    }


    xmppsc::Daemon daemon("I3Cclient", opt.foreground ? "" : opt.pid_file);
    // only seed if foreground option is not set
    if (opt.foreground) {
#ifdef DEBUG
        std::cout << "Running in foreground mode." << std::endl;
#endif
    }
    else if (!daemon.seed()) {
        std::cerr << "Daemon could not be stated (already running or insufficient permissions)!" << std::endl;
        daemon.message(LOG_EMERG, "Daemon could not be stated (already running or insufficient permissions)!");	
        exit(EXIT_FAILURE);
    }

    xmppsc::I2CEndpointBroker*  broker = new xmppsc::I2CEndpointBroker();

    //xmppsc::I2CEndpoint* ep = broker->endpoint(0x22);
    // Send a double beep
    //std::cout << std::hex << "0x" << ep->read_reg_16(0x95) << std::endl;

    gloox::Client* client=0;
    xmppsc::AccessFilter* af=0;
    try {
        xmppsc::ConfiguredClientFactory ccf(opt.config_file);
        client = ccf.newClient();
        af = ccf.newAccessFilter();
    } catch (xmppsc::ConfiguredClientFactoryException &ccfe) {
        std::ostringstream msg;
        msg << "ConfiguredClientFactoryException: " << ccfe.what();
	if (opt.foreground)
	  std::cerr << msg.str() << std::endl;
	else
	  daemon.message(LOG_EMERG, msg.str().c_str());
        return (-1);
    }

    xmppsc::MethodHandler* i2ch = new xmppsc::MethodHandler();

    i2ch->add_method(new xmppsc::I2CReadMethod(broker));
    i2ch->add_method(new xmppsc::I2CRead8Method(broker));
    i2ch->add_method(new xmppsc::I2CRead16Method(broker));
    i2ch->add_method(new xmppsc::I2CWriteMethod(broker));
    i2ch->add_method(new xmppsc::I2CWrite8Method(broker));
    i2ch->add_method(new xmppsc::I2CWrite16Method(broker));
    i2ch->add_method(new xmppsc::I3CCallMethod(broker));


    if (client) {
        // Use the "eco" variant
        xmppsc::set_eco_tcp_client(client);

        xmppsc::SpaceControlClient* scc = new xmppsc::SpaceControlClient(client, i2ch,
                new xmppsc::TextSpaceCommandSerializer(), af);

        while ( (scc->conn_error() != gloox::ConnUserDisconnected) &&
	        (!daemon.sighup()) ) {
            if (!client->connect(false)) {
		// print error message
		std::ostringstream msg;
		msg << "Could not connect: " << scc->conn_error();
		if (opt.foreground)
		  std::cerr << msg.str() << std::endl;
		else
		  daemon.message(LOG_ERR, msg.str().c_str());

		// wait 30 seconds
		if (opt.foreground)
		  std::cerr << "Waiting 30 seconds until next try." << std::endl;
		else
		  syslog(LOG_ERR, "Waiting 30 seconds until next try.");
		if (scc->conn_error() != gloox::ConnUserDisconnected)
		    std::this_thread::sleep_for(std::chrono::milliseconds(30*1000));
	    } else {  
		client->recv(500);
	    }
        }

        delete scc;
        delete client;
    }

    if (af)
        delete af;

    delete broker;

    return 0;
}