コード例 #1
0
ファイル: 3ddesk.cpp プロジェクト: KrisLee/N900-3d-desktop
// returns 0 for server was found to be started
// returns -1 for error or server was not found to have started
static int
wait_for_server_to_start(void)
{
    key_t key = ftok("/bin/sh", 99);
    if (key < 0) {
        fprintf(stderr, "wait_for_server: ftok failed: %d: %s\n", errno, strerror(errno));
        return -1;
    }

    struct timeval tm;

    // poll the demon semaphore for a few seconds at most
#define SECONDS_TO_WAIT 5

    int i;
    for (i = 0; i < SECONDS_TO_WAIT * 100; i++) {
        if (server_running())
            break;
        
        tm.tv_sec = 0;
        tm.tv_usec = 10000;
        select (0, 0, 0, 0, &tm); // sleep 
    }

    if (i == SECONDS_TO_WAIT * 100) {
        printf("Server not found after waiting %d seconds.\n", SECONDS_TO_WAIT);
        return -1; // timeout for server
    } 

    return 0;
}
コード例 #2
0
ファイル: idarub.cpp プロジェクト: jduck/idarub
static void idaapi run(int arg)
{

	unsigned short loadfile = 0;
	unsigned int sport = 1234, eport = 1239;
	char ip[16] = "0.0.0.0";
	const char * filename;

	char foo[] =
		"STARTITEM 3\n" // shortcut to quickly load files, etc
		"IdaRub!\n"
		"Sucka Free!\n\n"
		"<Listen IP  :A:15:15::>\n"
		"<Start Port :D:5:5::>\n"
		"<End Port   :D:5:5::>\n"
		"<Start Server:R><Load File:R><Load Last File:R>>\n\n\n\n";
	
	// make sure ruby has been loaded...
	init_ruby();

	if(server_running()) {
		if(!AskUsingForm_c("IdaRub!\nStop Server\n\n"))
			return;

		stop_server();
		msg(LPREFIX "stopped the rub\n");
	}
	else {
		if(!AskUsingForm_c(foo, &ip, &sport, &eport, &loadfile))
			return;

		switch(loadfile) {
		case 2: // Load Last File
			run_ruby_file(NULL);
			break;
		case 1: // Load File
			filename = askfile_c(0, "*.rb", "Select Ruby script...");
			if(filename)
				run_ruby_file(filename);
			break;
		case 0: // Start Server
			start_server(ip, sport, eport);
			break;
		}
	}
}
コード例 #3
0
void ConsolidatedTests::TwoPlayersSimple()
{
    beginTest("Two Players Simple");
    initialize_field_manager(4);
    set_delay(0);
    startserver(65002);
    
    register_callbacks(join_game,
                       leave_game,
                       take_cell,
                       get_size,
                       get_cell_player,
                       is_there_a_winner);
    
    
    ScopedPointer<Client> frank = new Client();
    frank->setName("Frank");
    add_instruction(frank, "sleep", 10);
    add_instruction(frank, "join", "");
    
    NamedValueSet* instruction = add_instruction(frank, "take", "");
    instruction->set("x", 0);
    instruction->set("y", 1);
    instruction->set("name", "Frank");
    
    instruction = add_instruction(frank, "take", "");
    instruction->set("x", 0);
    instruction->set("y", 0);
    instruction->set("name", "Frank");
    
    instruction = add_instruction(frank, "take", "");
    instruction->set("x", 1);
    instruction->set("y", 0);
    instruction->set("name", "Frank");
    
    instruction = add_instruction(frank, "take", "");
    instruction->set("x", 1);
    instruction->set("y", 1);
    instruction->set("name", "Frank");
    
    instruction = add_instruction(frank, "status", "");
    instruction->set("x", 0);
    instruction->set("y", 1);
    
    add_instruction(frank, "sleep", 2);
    
    ScopedPointer<Client> susy = new Client();
    susy->setName("Susy");
    add_instruction(susy, "sleep", 5);
    add_instruction(susy, "join", "");
    
    instruction = add_instruction(susy, "take", "");
    instruction->set("x", 0);
    instruction->set("y", 1);
    instruction->set("name", "Susy");
    
    instruction = add_instruction(susy, "take", "");
    instruction->set("x", 0);
    instruction->set("y", 0);
    instruction->set("name", "Susy");
    
    instruction = add_instruction(susy, "take", "");
    instruction->set("x", 1);
    instruction->set("y", 0);
    instruction->set("name", "Susy");
    
    instruction = add_instruction(susy, "take", "");
    instruction->set("x", 1);
    instruction->set("y", 1);
    instruction->set("name", "Susy");
    
    add_instruction(susy, "sleep", 3);

    
    for(int i = 0; i < 4; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            instruction = add_instruction(susy, "take", "");
            instruction->set("x", i);
            instruction->set("y", j);
            instruction->set("name", "Susy");
        }
    }
    
    pool.addJob(frank, false);
    pool.addJob(susy, false);
    
    while(pool.getNumJobs() > 0 )
    {
        Thread::sleep(100);
    }
    
    stopserver();
    while( server_running() > 0)
    {
        Thread::sleep(100);
    }
    release_field_manager();
    Thread::sleep(1000);
    
}
コード例 #4
0
ファイル: idarub.cpp プロジェクト: jduck/idarub
static void idaapi term(void)
{
	if(server_running()) {
		stop_server();
	}
}
コード例 #5
0
ファイル: 3ddesk.cpp プロジェクト: KrisLee/N900-3d-desktop
int main(int argc, char **argv)
{

    MessageManager msgmgr;
    
    static struct option long_options[] = {
        {"nozoom", 0, 0, 0},
        {"goto", 1, 0, 0},
        {"gotoright", 0, 0, 0},
        {"gotoleft", 0, 0, 0},
        {"gotoup", 0, 0, 0},
        {"gotodown", 0, 0, 0},
        {"mode", 1, 0, 0},
        {"acquire", 2, 0, 0},
        {"acquirecurrent", 0, 0, 0},
        {"stop", 0, 0, 0},
        {"gotocolumn", 1, 0, 0},
        {"gotorow", 1, 0, 0},
        {"view", 1, 0, 0},
        {"zoom", 0, 0, 0},
        {"reload", 0, 0, 0},
        {"changespeed", 1, 0, 0},
        {"zoomspeed", 1, 0, 0},
        {"dontexit", 0, 0, 0},
	{"noautofun", 0, 0, 0},
	{"revmousewheel", 0, 0, 0},
	{"swapmousebuttons", 0, 0, 0},
	{"altmousebuttons", 0, 0, 0},
	{"justswitch", 0, 0, 0},
        {"version", 0, 0, 0},
        {0, 0, 0, 0}
    };

    float tmp;
    int c;
    int option_index;
    while (1) {

        c = getopt_long (argc, argv, "v",
                         long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
        case 0: // long option

            switch (option_index) {
            case 0: // 'nozoom'
                msgmgr.msg.zoom = 0;
                break;
            case 1: // 'goto'  ---- use is deprecated (in favor of gotocolumn)
                msgmgr.msg.goto_column = atoi (optarg);
                if (msgmgr.msg.goto_column < 1) 
                    usage_and_bye();
                break;
            case 2: // 'gotoright'
                msgmgr.msg.goto_column = GOTO_FACE_RIGHT;
                break;
            case 3: // 'gotoleft'
                msgmgr.msg.goto_column = GOTO_FACE_LEFT;
                break;
            case 4: // 'gotonext'
                msgmgr.msg.goto_row = GOTO_FACE_UP;
                break;
            case 5: // 'gotoprev'
                msgmgr.msg.goto_row = GOTO_FACE_DOWN;
                break;
            case 6: // 'mode'
                if (strcmp(optarg, "cylinder") == 0) {
                    msgmgr.msg.face_type = FACE_TYPE_CYLINDER;
                } else if (strcmp(optarg, "linear") == 0) {
                    msgmgr.msg.face_type = FACE_TYPE_LINEAR;
                } else if (strcmp(optarg, "viewmaster") == 0) {
                    msgmgr.msg.face_type = FACE_TYPE_VIEWMASTER;
                } else if (strcmp(optarg, "carousel") == 0) {
                    msgmgr.msg.face_type = FACE_TYPE_CAROUSEL;
                } else if (strcmp(optarg, "priceisright") == 0) {
                    msgmgr.msg.face_type = FACE_TYPE_PRICEISRIGHT;
                } else if (strcmp(optarg, "flip") == 0) {
                    msgmgr.msg.face_type = FACE_TYPE_FLIP;
                } else if (strcmp(optarg, "random") == 0) {
                    msgmgr.msg.face_type = FACE_TYPE_RANDOM;
                } else {
                    usage_and_bye();
                }
                break;
            case 7: // 'acquire'
                msgmgr.msg.mtype = MTYPE_ACQUIRE;
                if (optarg) {
                    int tmpint = atoi (optarg);
                    // must be between 10ms and 3sec for now
                    if (10 < tmpint && tmpint < 3000)
                        msgmgr.msg.acquire_sleep = tmpint;
                } else {
                    msgmgr.msg.acquire_sleep = 700;
                }
                break;
            case 8: // 'acquirecurrent'
                msgmgr.msg.mtype = MTYPE_ACQUIRE_CURRENT;
                break;
            case 9: // 'stop'
                msgmgr.msg.mtype = MTYPE_STOP;
                printf ("Stopping 3ddesktop daemon...\n");
                break;
            case 10: // 'gotocolumn'
                msgmgr.msg.goto_column = atoi (optarg);
                if (msgmgr.msg.goto_column < 1) 
                    usage_and_bye();
                break;
            case 11: // 'gotorow'
                msgmgr.msg.goto_row = atoi (optarg);
                if (msgmgr.msg.goto_row < 1) 
                    usage_and_bye();
                break;
            case 12: // 'view'
                strcpy(msgmgr.msg.view, optarg);
                break;
            case 13: // 'zoom'
                msgmgr.msg.zoom = 1;
                break;
            case 14: // 'reload'
                msgmgr.msg.reload = 1;
                break;
            case 15: // 'changespeed'
                tmp = atof(optarg);
                if (tmp >= 1.0 && tmp <= 300.0) {
                  msgmgr.msg.face_change_steps = tmp;
                }
                break;
            case 16: // 'zoomspeed'
                tmp = atof(optarg);
                if (tmp >= 1.0 && tmp <= 300.0) {
                  msgmgr.msg.zoom_steps = tmp;
                }
                break;
            case 17: // 'dontexit'
                msgmgr.msg.disable_exit_after_goto = 1;
                break;
	    case 18: // 'noautofun'
		msgmgr.msg.disable_random_fun = 1;
                break;
	    case 19: // 'revmousewheel'
		msgmgr.msg.reverse_mousewheel = 1;
                break;
	    case 20: // 'swapmousebuttons'
		msgmgr.msg.swap_mousebuttons = 1;
                break;
	    case 21: // 'altmousebuttons'
		msgmgr.msg.alt_mousebuttons = 1;
                break;
            case 22: // 'justswitch'
                msgmgr.msg.mtype = MTYPE_JUSTSWITCH;
                break;
            case 23: // 'version'
                printf("3ddesktop %s (3ddesk client)\nWritten by Brad Wasson.\n\nCopyright (C) 2002 - 2005 Brad Wasson.\n"
                       "This is free software; see the source for copying conditions.  There is NO\n"
                       "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
                       "This binary compiled %s %s.\n\n",
                       VERSION, __DATE__, __TIME__);
                exit(0);
                break;
            }
            break;
        case 'v':
            verbose = 1;
            break;
        default:
            usage_and_bye();
            break;
        }
    }


    if (msgmgr.open() < 0 || !server_running()) {
        if (msgmgr.msg.mtype == MTYPE_STOP) {
            // already stopped...
            fprintf(stderr, "Server not running.\n");
            exit (1);
        }

        fprintf(stderr, "Attempting to start 3ddesktop server.\n");
  
        if (start_daemon() < 0) {
            fprintf(stderr, "Could not start server.\n"
                    "Try starting manually (3ddeskd)\n\n");
            exit(1);
        }

        if (wait_for_server_to_start() == 0) {
            if (msgmgr.open() < 0) {
                fprintf(stderr, "Can't get message queue: %s\n", strerror(errno));
                fprintf(stderr, "Maybe 3ddeskd server not started?\n");
                exit (1);
            }
        } else {
            fprintf(stderr, "Could not find server.\n"
                    "Try starting manually (3ddeskd)\n\n");
            exit (1);
        }
    }

    if (msgmgr.send() < 0) {
        fprintf(stderr, "Failed to send server a message\n");
        exit (1);
    }

    return 0;
}