Esempio n. 1
0
Drone* DroneDBE::createDrone(){
	if (!mDll){
		throw("Drone class should never be instanciated without an associated DLL");
	}else{
		typedef Shmoulette::Drone* (__cdecl* DLLDroneCallback)();
		DLLDroneCallback dllFunc = (DLLDroneCallback)::GetProcAddress(mDll, "getInstance");
		Drone* d = dllFunc();
		d->init(this);
		if (mPythonCallback != ""){
			d->setPythonCallback(mPythonCallback);
		}
		return d;
	}
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    int exitCode = 0;
    dpdk_init(argc, argv);

    QCoreApplication app(argc, argv);
    Drone *drone = new Drone();
    OstProtocolManager = new ProtocolManager();

    app.setApplicationName(drone->objectName());

    // TODO: command line options
    // -v (--version)
    // -h (--help)
    // -p (--portnum)
    if (argc > 1)
        myport = atoi(argv[2]);

    if (!drone->init())
    {
        exitCode = -1;
        goto _exit;
    }

    qDebug("Version: %s", version);
    qDebug("Revision: %s", revision);

#ifdef Q_OS_UNIX
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = cleanup;
    if (sigaction(SIGTERM, &sa, NULL))
        qDebug("Failed to install SIGTERM handler. Cleanup may not happen!!!");
    if (sigaction(SIGINT, &sa, NULL))
        qDebug("Failed to install SIGINT handler. Cleanup may not happen!!!");
#endif

    exitCode = app.exec();

_exit:
    delete drone;
    delete OstProtocolManager;

    google::protobuf::ShutdownProtobufLibrary();

    return exitCode;
} 
Esempio n. 3
0
void *Drone_new(size_t size, Drone proto, int *id)
{
		// setup the default functions in case they aren't set
		if(!proto.init) proto.init = Drone_init;
		if(!proto.boot) proto.boot = Drone_boot;
		if(!proto.stand_by) proto.stand_by = Drone_stand_by;
		if(!proto.navigate) proto.navigate = Drone_navigate;
		if(!proto.pick_up) proto.pick_up = Drone_pick_up;
		if(!proto.lift_off) proto.lift_off = Drone_lift_off;
		if(!proto.deliver) proto.deliver= Drone_deliver;
		if(!proto.return_home) proto.return_home = Drone_return_home;
		if(!proto.land) proto.land = Drone_land;
		if(!proto.state) proto.state = Drone_state;

		// this seems weird, but we can make a struct of one size,
		// then point a different pointer at it to "cast" it
		Drone *el = calloc(1, size);
		*el = proto;

		// copy the id over

		el->id = *id;
		el->curr_state = 0;
		el->busy = 0;
		el->curr_x = 0;
		el->curr_y = 0;

		// initialize it with whatever init we were given
		if(!el->init(el)) {
				// looks like it didn't initialize properly
				el->destroy(el);
				return NULL;
		} else {
				// all done, we made an object of any type
				return el;
		}
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    int exitCode = 0;
    QCoreApplication app(argc, argv);
    Drone *drone;

    // TODO: command line options
    // -v (--version)
    // -h (--help)
    // -p (--portnum)
    if (argc > 1)
        myport = atoi(argv[1]);

    app.setApplicationName("Drone");
    app.setOrganizationName("Ostinato");

    /* (Portable Mode) If we have a .ini file in the same directory as the 
       executable, we use that instead of the platform specific location
       and format for the settings */
    QString portableIni = QCoreApplication::applicationDirPath() 
            + "/drone.ini";
    if (QFile::exists(portableIni))
        appSettings = new QSettings(portableIni, QSettings::IniFormat);
    else
        appSettings = new QSettings(QSettings::IniFormat, 
                                    QSettings::UserScope,
                                    app.organizationName(), 
                                    app.applicationName().toLower());

    drone = new Drone();
    OstProtocolManager = new ProtocolManager();

    if (!drone->init())
    {
        exitCode = -1;
        goto _exit;
    }

    qDebug("Version: %s", version);
    qDebug("Revision: %s", revision);

#ifdef Q_OS_UNIX
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = cleanup;
    if (sigaction(SIGTERM, &sa, NULL))
        qDebug("Failed to install SIGTERM handler. Cleanup may not happen!!!");
    if (sigaction(SIGINT, &sa, NULL))
        qDebug("Failed to install SIGINT handler. Cleanup may not happen!!!");
#endif

    exitCode = app.exec();

_exit:
    delete drone;
    delete OstProtocolManager;

    google::protobuf::ShutdownProtobufLibrary();

    return exitCode;
}