Beispiel #1
0
static int
backend_config_checkpoint(config_object_t *config)
{
	char val[4096];
	char inp[4096];
	int done = 0;

	printf("\n");
	printf("The checkpoint backend module is designed for use in clusters\n"
	       "running corosync, openais, and CMAN.  It utilizes the SAF \n"
	       "checkpoint API to store virtual machine states and CPG to \n"
	       "route fencing requests, finally utilizing libvirt to perform\n"
	       "fencing actions.\n\n");

	if (sc_get(config, "backends/checkpoint/@uri", val,
		   sizeof(val))) {
		strncpy(val, DEFAULT_HYPERVISOR_URI, sizeof(val));
	}

	text_input("Libvirt URI", val, inp, sizeof(inp));

	sc_set(config, "backends/checkpoint/@uri", inp);

	printf("\n");
	printf("The name mode is how the checkpoint plugin stores and \n"
	       "references virtual machines.  Since virtual machine names\n"
	       "are not guaranteed to be unique cluster-wide, use of UUIDs\n"
	       "is strongly recommended.  However, for compatibility with \n"
	       "fence_xvmd, the use of 'name' mode is also supported.\n\n");

	if (sc_get(config, "backends/checkpoint/@name_mode", val,
		   sizeof(val))) {
		strncpy(val, "uuid", sizeof(val));
	}

	do {
		text_input("VM naming/tracking mode (name or uuid)",
			   val, inp, sizeof(inp));
		if (!strcasecmp(inp, "uuid")) {
			done = 1;
		} else if (!strcasecmp(inp, "name")) {
			done = 0;
			printf("This can be dangerous if you do not take care to"
			       "ensure that\n"
			       "virtual machine names are unique "
			       "cluster-wide.\n");
			if (yesno("Use name mode anyway", 1) == 1)
				done = 1;
		}
	} while (!done);

	sc_set(config, "backends/checkpoint/@name_mode", inp);

	return 0;
}
Beispiel #2
0
static int
listener_configure(config_object_t *config)
{
    char val[4096];
    char inp[4096];
    int done = 0;

    printf("\n");
    printf("Listener modules are responsible for accepting requests\n"
           "from fencing clients.\n\n");

    /* Default backend plugin */
    if (sc_get(config, "fence_virtd/@listener", val,
               sizeof(val))) {
        strncpy(val, "multicast", sizeof(val));
    }

    do {
        text_input("Listener module", val, inp, sizeof(inp));
        if (plugin_find_listener(inp) == NULL) {
            printf("No listener module named %s found!\n", inp);
            if (yesno("Use this value anyway", 0) == 1)
                done = 1;
        } else {
            done = 1;
        }
    } while (!done);

    sc_set(config, "fence_virtd/@listener", inp);
    if (!strcmp(inp, "multicast"))
        listener_config_multicast(config);
    else if (!strcmp(inp, "tcp"))
        listener_config_tcp(config);
    else if (!strcmp(inp, "serial"))
        listener_config_serial(config);
    else
        printf("I don't know how to configure '%s' :(\n",
               inp);

    return 0;
}
Beispiel #3
0
static int
backend_configure(config_object_t *config)
{
    char val[4096];
    char inp[4096];
    int done = 0;

    printf("\n");
    printf("Backend modules are responsible for routing requests to\n"
           "the appropriate hypervisor or management layer.\n\n");

    /* Default backend plugin */
    if (sc_get(config, "fence_virtd/@backend", val,
               sizeof(val))) {
        strncpy(val, "libvirt", sizeof(val));
    }

    do {
        text_input("Backend module", val, inp, sizeof(inp));
        if (plugin_find_backend(inp) == NULL) {
            printf("No backend module named %s found!\n", inp);
            if (yesno("Use this value anyway", 0) == 1)
                done = 1;
        } else {
            done = 1;
        }
    } while (!done);

    sc_set(config, "fence_virtd/@backend", inp);

#if 0
    if (!strcmp(inp, "libvirt")) {
        backend_config_libvirt(config);
    } else if (!strcmp(inp, "checkpoint")) {
        backend_config_checkpoint(config);
    }
#endif

    return 0;
}
Beispiel #4
0
static int
plugin_path_configure(config_object_t *config)
{
#ifdef _MODULE
	char val[4096];
	char inp[4096];
	int done = 0;

	if (sc_get(config, "fence_virtd/@module_path", val,
	   	   sizeof(val))) {
#ifdef MODULE_PATH
		snprintf(val, sizeof(val), MODULE_PATH);
#else
		printf("Failed to determine module search path.\n");
#endif
	}

	do {
		text_input("Module search path", val, inp, sizeof(inp));

		printf("\n");
		done = plugin_search(inp);
		if (done > 0) {
			plugin_dump();
			done = 1;
		} else {
			done = 0;
			printf("No modules found in %s!\n", inp);
			if (yesno("Use this value anyway", 0) == 1)
				done = 1;
		}
	} while (!done);

	sc_set(config, "fence_virtd/@module_path", inp);

#endif
	return 0;
}
Beispiel #5
0
static int
backend_config_libvirt(config_object_t *config)
{
	char val[4096];
	char inp[4096];

	printf("\n");
	printf("The libvirt backend module is designed for single desktops or\n"
	       "servers.  Do not use in environments where virtual machines\n"
	       "may be migrated between hosts.\n\n");

	/* Default backend plugin */
	if (sc_get(config, "backends/libvirt/@uri", val,
		   sizeof(val))) {
		strncpy(val, DEFAULT_HYPERVISOR_URI, sizeof(val));
	}

	text_input("Libvirt URI", val, inp, sizeof(inp));

	sc_set(config, "backends/libvirt/@uri", inp);

	return 0;
}
Beispiel #6
0
void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
{
    wxTextCtrl& textCtrl = * GetTextCtrl();

    textCtrl.Clear();
    textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n");

    textCtrl.WriteText( _T("Writing to ofstream and wxFileOutputStream:\n") );

    wxSTD ofstream std_file_output( "test_std.dat" );
    wxFileOutputStream file_output( file_name );
    wxBufferedOutputStream buf_output( file_output );
    wxTextOutputStream text_output( buf_output );

    wxString tmp;
    signed int si = 0xFFFFFFFF;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );
    text_output << si << _T("\n");
    std_file_output << si << "\n";

    unsigned int ui = 0xFFFFFFFF;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );
    text_output << ui << _T("\n");
    std_file_output << ui << "\n";

    double d = 2.01234567890123456789;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );
    text_output << d << _T("\n");
    std_file_output << d << "\n";

    float f = (float)0.00001;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );
    text_output << f << _T("\n");
    std_file_output << f << "\n";

    wxString str( _T("Hello!") );
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
    text_output << str << _T("\n");
    std_file_output << str.ToAscii() << "\n";

    textCtrl.WriteText( _T("\nReading from ifstream:\n") );

    wxSTD ifstream std_file_input( "test_std.dat" );

    std_file_input >> si;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );

    std_file_input >> ui;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );

    std_file_input >> d;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    std_file_input >> f;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );

    char std_buf[200];
    std_file_input >> std_buf;
    str = wxString::FromAscii(std_buf);
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );

    textCtrl.WriteText( _T("\nReading from wxFileInputStream:\n") );

    buf_output.Sync();

    wxFileInputStream file_input( file_name );
    wxBufferedInputStream buf_input( file_input );
    wxTextInputStream text_input( file_input );

    text_input >> si;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );

    text_input >> ui;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );

    text_input >> d;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    text_input >> f;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );

    text_input >> str;
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );



    textCtrl << _T("\nTest for wxDataStream:\n\n");

    textCtrl.WriteText( _T("Writing to wxDataOutputStream:\n") );

    file_output.SeekO( 0 );
    wxDataOutputStream data_output( buf_output );

    wxInt16 i16 = (unsigned short)0xFFFF;
    tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
    textCtrl.WriteText( tmp );
    data_output.Write16( i16 );

    wxUint16 ui16 = 0xFFFF;
    tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
    textCtrl.WriteText( tmp );
    data_output.Write16( ui16 );

    d = 2.01234567890123456789;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );
    data_output.WriteDouble( d );

    str = _T("Hello!");
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
    data_output.WriteString( str );

    buf_output.Sync();

    textCtrl.WriteText( _T("\nReading from wxDataInputStream:\n") );

    file_input.SeekI( 0 );
    wxDataInputStream data_input( buf_input );

    i16 = data_input.Read16();
    tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
    textCtrl.WriteText( tmp );

    ui16 = data_input.Read16();
    tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
    textCtrl.WriteText( tmp );

    d = data_input.ReadDouble();
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    str = data_input.ReadString();
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
}
Beispiel #7
0
static int
listener_config_serial(config_object_t *config)
{
	char val[4096];
	char inp[4096];

	printf("\n");
	printf("The serial plugin allows fence_virtd to communicate with\n"
	       "guests using serial or guest-forwarding VMChannel instead\n"
	       "of using TCP/IP networking.\n\n");
	printf("Special configuration of virtual machines is required. See\n"
	       "fence_virt.conf(5) for more details.\n\n");

	if (sc_get(config, "listeners/serial/@uri",
		   val, sizeof(val)-1)) {
		strncpy(val, DEFAULT_HYPERVISOR_URI, sizeof(val));
	}

	text_input("Libvirt URI", val, inp, sizeof(inp));
	
	printf("\nSetting a socket path prevents fence_virtd from taking\n"
	       "hold of all Unix domain sockets created when the guest\n"
	       "is started.  A value like /var/run/cluster/fence might\n"
	       "be a good value.  Don't forget to create the directory!\n\n");

	if (sc_get(config, "listeners/serial/@path",
		   val, sizeof(val)-1)) {
		strncpy(val, "none", sizeof(val));
	}

	text_input("Socket directory", val, inp, sizeof(inp));
	if (!strcasecmp(inp, "none")) {
		sc_set(config, "listeners/serial/@path", NULL);
	} else {
		sc_set(config, "listeners/serial/@path", inp);
	}

	printf("\nThe serial plugin allows two types of guest to host\n"
	       "configurations.  One is via a serial port; the other is\n"
	       "utilizing the newer VMChannel.\n\n");

	if (sc_get(config, "listeners/serial/@mode",
		   val, sizeof(val)-1)) {
		strncpy(val, "serial", sizeof(val));
	}

	if (!strcasecmp(inp, "none")) {
		sc_set(config, "listeners/serial/@path", NULL);
	} else {
		sc_set(config, "listeners/serial/@path", inp);
	}

	do { 
		text_input("Mode (serial or vmchannel)", val, inp,
			   sizeof(inp));

		if (strcasecmp(inp, "serial") &&
		    strcasecmp(inp, "vmchannel")) {
			printf("Invalid mode: %s\n", inp);
			if (yesno("Use anyway", 1) == 1)
				break;
			continue;
		}
	} while(0);
	sc_set(config, "listeners/serial/@mode", inp);

	return 0;
}
Beispiel #8
0
static int
listener_config_multicast(config_object_t *config)
{
	char val[4096];
	char inp[4096];
	const char *family;
	struct in_addr sin;
	struct in6_addr sin6;
	int done = 0;

	printf("\n");
	printf("The multicast listener module is designed for use environments\n"
	       "where the guests and hosts may communicate over a network using\n"
	       "multicast.\n\n");


	/* MULTICAST IP ADDRESS/FAMILY */
	printf("The multicast address is the address that a client will use to\n"
	       "send fencing requests to fence_virtd.\n\n");

	if (sc_get(config, "listeners/multicast/@address",
		   val, sizeof(val)-1)) {
		strncpy(val, IPV4_MCAST_DEFAULT, sizeof(val));
	}

	do {
		text_input("Multicast IP Address", val, inp, sizeof(inp));

		if (inet_pton(AF_INET, inp, &sin) == 1) {
			printf("\nUsing ipv4 as family.\n\n");
			family = "ipv4";
		} else if (inet_pton(AF_INET6, inp, &sin6) == 1) {
			printf("\nUsing ipv6 as family.\n\n");
			family = "ipv6";
		} else {
			printf("'%s' is not a valid IP address!\n", inp);
			continue;
		}

	} while (0);
	sc_set(config, "listeners/multicast/@family", family);
	sc_set(config, "listeners/multicast/@address", inp);


	/* MULTICAST IP PORT */
	if (sc_get(config, "listeners/multicast/@port",
		   val, sizeof(val)-1)) {
		snprintf(val, sizeof(val), "%d", DEFAULT_MCAST_PORT);
	}

	do {
		text_input("Multicast IP Port", val, inp, sizeof(inp));

		done = atoi(inp);
		if (done <= 0 || done > 65534) {
			printf("Port value '%s' is out of range\n", val);
			continue;
		}

	} while (0);
	sc_set(config, "listeners/multicast/@port", inp);


	/* MULTICAST INTERFACE */
	printf("\nSetting a preferred interface causes fence_virtd to listen only\n"
	       "on that interface.  Normally, it listens on all interfaces.\n"
	       "In environments where the virtual machines are using the host\n"
	       "machine as a gateway, this *must* be set (typically to virbr0).\n"
	       "Set to 'none' for no interface.\n\n"
	      );

	if (sc_get(config, "listeners/multicast/@interface",
		   val, sizeof(val)-1)) {
		strncpy(val, "none", sizeof(val));
	}

	do { 
		text_input("Interface", val, inp, sizeof(inp));

		if (!strcasecmp(inp, "none")) {
			break;
		}

		if (strlen(inp) > 0) {
			done = if_nametoindex(inp);
			if (done < 0) {
				printf("Invalid interface: %s\n", inp);
				if (yesno("Use anyway", 1) == 1)
					break;
				continue;
			}
			break;
		}
	} while(0);

	if (!strcasecmp(inp, "none")) {
		sc_set(config, "listeners/multicast/@interface", NULL);
	} else {
		sc_set(config, "listeners/multicast/@interface", inp);
	}


	/* KEY FILE */
	printf("\nThe key file is the shared key information which is used to\n"
	       "authenticate fencing requests.  The contents of this file must\n"
	       "be distributed to each physical host and virtual machine within\n"
	       "a cluster.\n\n");

	if (sc_get(config, "listeners/multicast/@key_file",
		   val, sizeof(val)-1)) {
		strncpy(val, DEFAULT_KEY_FILE, sizeof(val));
	}

	do { 
		text_input("Key File", val, inp, sizeof(inp));

		if (!strcasecmp(inp, "none")) {
			break;
		}

		if (strlen(inp) > 0) {
			if (inp[0] != '/') {
				printf("Invalid key file: %s\n", inp);
				if (yesno("Use anyway", 1) == 1)
					break;
				continue;
			}
			break;
		}
	} while(0);
	if (!strcasecmp(inp, "none")) {
		sc_set(config, "listeners/multicast/@key_file", NULL);
	} else {
		sc_set(config, "listeners/multicast/@key_file", inp);
	}

	return 0;
}
Beispiel #9
0
static int setup_create_user(const char *host, const char *user,
   const char *pass, const char *name)
{
   int ret, major, minor, patch;
   char root[256], user_buf[512], pass_buf[512], name_buf[512];
   char *p1, *p2, *p3;
   DB_RESULT result;
   DB_ROW row;

   printf("Setup will attempt to add this user to your database.\n\n");
   printf("This will only work if your bot resides on the same\n");
   printf("machines as your MySQL server.\n\n");
   printf("This involves connecting to your MySQL as root.\n\n");
   printf("Hit Ctrl-C if you wish to abort, or enter to confirm.\n");

   getchar();

   setup_err = 0;

   /* try to connect as root */
   ret = db_connect(0, host, "root", NULL, "mysql", setup_error);

   if(ret != 0)
   {
      printf("Your MySQL server has a root password set.\n");
      printf("Setup will use this to add a user to your database.\n\n");
      printf("Leave blank to abort.\n\n");

      system("stty -echo");
      text_input("Enter your MySQL root password", root, 256, NULL);
      system("stty echo");

      if(root[0] == 0)
         return -1;

      if(db_connect(0, host, "root", root, "mysql", setup_error) != 0)
      {
         printf("Setup could not connect to your database.\n\n");
         printf("Check in your config file that your database\n");
         printf("settings are correct.  Also try manually\n");
         printf("adding a MySQL user.\n");
         return -1;
      }
   }

   result = db_query(0, "SELECT VERSION()");
   row = db_fetch(result);

   p1 = strtok(row[0], ".-");
   p2 = strtok(NULL, ".-");
   p3 = strtok(NULL, ".-");

   if((p1 == NULL) || (p2 == NULL) || (p3 == NULL))
   {
      printf("Could not determine MySQL version.\n");
      return -1;
   }

   major = p1 ? atoi(p1) : 0;
   minor = p2 ? atoi(p2) : 0;
   patch = p3 ? atoi(p3) : 0;

   db_escape(user_buf, user, 256);
   db_escape(pass_buf, pass, 256);
   db_escape(name_buf, name, 256);

   if(((major >= 3) && (minor >= 23)) || (major > 3))
   {
      db_query(0, "GRANT ALL PRIVILEGES ON %s.* TO %s@localhost "
         "IDENTIFIED BY '%s' WITH GRANT OPTION", name_buf, user_buf,
         pass_buf);
   }
   else if((major >= 3) && (minor == 22) && (patch >= 11))
   {
      db_query(0, "INSERT INTO user (host, user, password) VALUES("
         "'localhost', '%s', PASSWORD('%s'))", user_buf, pass_buf);
      db_query(0, "INSERT INTO db VALUES('%%', '%s', '%s', 'Y', 'Y', "
         "'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y')", name_buf, user_buf);
      db_query(0, "FLUSH PRIVILEGES");
   }
   else
   {
      printf("Setup doesn't know how to deal with MySQL %d.%d.%d.\n\n",
         major, minor, patch);
      printf("You're on your own.\n");
      return -1;
   }

   db_disconnect(0);

   if(setup_err)
   {
      printf("Could not create a user.  You'll have to do it manually\n");
      return -1;
   }

   printf("Created user `%s' on `%s'.\n", user, host);

   return 0;
}
Beispiel #10
0
void main_loop(void)
{
    int neo_emu_done = 0;
    int overclk=CF_VAL(cf_get_item_by_name("overclock"));

    Uint32 cpu_68k_timeslice = (overclk==0?200000:200000+(overclk*200000/100.0));
    Uint32 cpu_68k_timeslice_scanline = cpu_68k_timeslice/262.0;
//    Uint32 cpu_z80_timeslice = 100000;
    Uint32 cpu_z80_timeslice = 73333;
    Uint32 tm_cycle=0;

    /*    Uint32 cpu_z80_timeslice=66666; // is it 4Mhz or 6Mhz ???? 4 seems to work fine....
       UPDATE: it's clear now that it's 6Mhz -> kof96 presentation */

    Uint32 cpu_z80_timeslice_interlace = cpu_z80_timeslice / (float) nb_interlace;
    char ksym_code[5];
    SDL_Event event;
    Uint16 scancode, i, a;
    char input_buf[20];
    Uint8 show_keysym=0;
    CONF_ITEM* item = cf_get_item_by_name("invertjoy");
    int invert_joy = 0;
    if (item)
    	invert_joy=CF_BOOL(item);

    reset_frame_skip();
    my_timer();
    //printf("Cpuspeed: %d\n",cpu_68k_timeslice);
/*
    printf("%s\n",&memory.cpu[0x100]);
    printf("NGH = %04x\n",READ_WORD(&memory.cpu[0x108]));
    printf("SSN = %04x\n",READ_WORD(&memory.cpu[0x114]));
*/

    while (!neo_emu_done) {
	if (conf.test_switch == 1)
	    conf.test_switch = 0;


	while (SDL_PollEvent(&event)) {
	    switch (event.type) {
	    case SDL_JOYAXISMOTION:
		joy_axe[event.jaxis.which][event.jaxis.axis] = event.jaxis.value;
		if (show_keysym) {
		    sprintf(ksym_code, "%d", event.jaxis.axis);
		    draw_message(ksym_code);
		}
		break;

	    case SDL_JOYHATMOTION:
		    switch (event.jhat.value) {
		    case SDL_HAT_CENTERED:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_UP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    break;
			    
		    case SDL_HAT_DOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    break;
			    
		    case SDL_HAT_LEFT:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_RIGHT:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_RIGHTUP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    break;
			    
		    case SDL_HAT_RIGHTDOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    break;
			    
		    case SDL_HAT_LEFTUP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    break;
			    
		    case SDL_HAT_LEFTDOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    break;
			    
		    }
		    
		    if (show_keysym) {
			    sprintf(ksym_code, "%d", event.jhat.hat);
			    draw_message(ksym_code);
		    }
		    break;


	    case SDL_JOYBUTTONDOWN:
		joy_button[event.jbutton.which][event.jbutton.button] = 1;
		
		if (show_keysym) {
		    sprintf(ksym_code, "%d", event.jbutton.button);
		    draw_message(ksym_code);
		}
		break;
	    case SDL_JOYBUTTONUP:
		joy_button[event.jbutton.which][event.jbutton.button] = 0;
		break;

	    case SDL_KEYUP:
		if (player)
		{
			switch(event.key.keysym.sym)
			{
			case 273:
				key[264] = 0;
				break;
			case 275:
				key[274] = 0;
				break;
			case 274:
				key[261] = 0;
				break;
			case 276:
				key[260] = 0;
				break;
			case 122:
				key[108] = 0;
				break;
			case 120:
				key[59] = 0;
				break;
			case 97:
				key[111] = 0;
				break;
			case 115:
				key[112] = 0;
				break;
			case 49:
				key[50] = 0;
				break;
			case 51:
				key[52] = 0;
				break;
			default:
				key[event.key.keysym.sym] = 0;
				break;
			}
		}
		else
			key[event.key.keysym.sym] = 0;
		break;
	    case SDL_KEYDOWN:
		scancode = event.key.keysym.sym;
		if (show_keysym) {
		    sprintf(ksym_code, "%d", scancode);
		    draw_message(ksym_code);
		}
		if (player)
		{
			switch(scancode)
			{
			case 273:
				key[264] = 1;
				break;
			case 275:
				key[274] = 1;
				break;
			case 274:
				key[261] = 1;
				break;
			case 276:
				key[260] = 1;
				break;
			case 122:
				key[108] = 1;
				break;
			case 120:
				key[59] = 1;
				break;
			case 97:
				key[111] = 1;
				break;
			case 115:
				key[112] = 1;
				break;
			case 49:
				key[50] = 1;
				break;
			case 51:
				key[52] = 1;
				break;
			default:
				key[scancode] = 1;
				break;
			}
		}
		else
			key[scancode] = 1;

		switch (scancode) {
		case SDLK_ESCAPE:
		    neo_emu_done = 1;
#ifdef __QNXNTO__
		    shutdown = 1;
#endif
		    break;	// ESC
/*
		case SDLK_TAB:
		    main_gngeo_gui();
		    break;
*/
		case SDLK_F1:
		    draw_message("Reset");
		    //neogeo_init();
		    cpu_68k_reset();
		    break;
		case SDLK_F2:
		    take_screenshot();
		    draw_message("Screenshot saved");
		    break;
		case SDLK_F3:
		    draw_message("Test Switch ON");
		    conf.test_switch = 1;
		    break;
		case SDLK_F5:
		    show_fps ^= SDL_TRUE;
		    break;
		case SDLK_F4:
		    show_keysym = 1 - show_keysym;
		    if (show_keysym)
			draw_message("Show keysym code : ON");
		    else
			draw_message("Show keysym code : OFF");
		    break;
		case SDLK_F6:
		    slow_motion = 1 - slow_motion;
		    if (slow_motion)
			draw_message("SlowMotion : ON");
		    else {
			draw_message("SlowMotion : OFF");
			reset_frame_skip();
		    }
		    break;
		case SDLK_F7:
		    //screen_set_effect("scanline");
		    if (conf.debug) {
			dbg_step = 1;
		    }
		    break;
		case SDLK_F8: 
		{
		    int val;
		    char *endptr;
		    text_input("Save to slot [0-999]? ",16,227,input_buf,3);
		    val=strtol(input_buf,&endptr,10);
		    if (input_buf != endptr) {
			pending_save_state=val+1;
		    }
		}
		break;
		case SDLK_F9:
		{
		    int val;
		    char *endptr;
		    text_input("Load from slot [0-999]? ",16,227,input_buf,3);
		    val=strtol(input_buf,&endptr,10);
		    if (input_buf != endptr) {
			pending_load_state=val+1;
		    }
		}
		break; 
		case SDLK_F10:
		    autoframeskip ^= SDL_TRUE;
		    if (autoframeskip) {
			reset_frame_skip();
			draw_message("AutoFrameSkip : ON");
		    } else
			draw_message("AutoFrameSkip : OFF");
		    break;
		case SDLK_F11:
		    sleep_idle ^= SDL_TRUE;
		    if (sleep_idle)
			draw_message("Sleep idle : ON");
		    else
			draw_message("Sleep idle : OFF");
		    break;
		case SDLK_F12:
		    screen_fullscreen();
		    break;
#ifdef __QNXNTO__
		case SDLK_F13:
			neo_emu_done = 1;
			break;
		case SDLK_F14:
			if (player)
			{
				key[52] = 0;
				key[50] = 0;
				key[112] = 0;
				key[111] = 0;
				key[59] = 0;
				key[108] = 0;
				key[260] = 0;
				key[261] = 0;
				key[274] = 0;
				key[264] = 0;
			}
			player = !player;
			break;
#endif
		}
		break;
	    case SDL_VIDEORESIZE:
		conf.res_x=event.resize.w;
		conf.res_y=event.resize.h;
		screen_resize(event.resize.w, event.resize.h);
		break;
		case SDL_ACTIVEEVENT:
			if (event.active.state & SDL_APPINPUTFOCUS)
			{
				if (!event.active.gain)
				{
					int J;
					SDL_PauseAudio(1);
					while (1)
					{
						usleep(10000);
						if (SDL_PollEvent(&event))
						{
							if (event.type == SDL_ACTIVEEVENT)
							{
								if (event.active.state & SDL_APPINPUTFOCUS)
								{
									if (event.active.gain)
										break;
								}
							}
							else if (event.type == SDL_QUIT)
							{
								neo_emu_done = 1;
								break;
							}
						}
					}
					SDL_PauseAudio(0);
				    reset_frame_skip();
				}
			}
			break;
		case SDL_USEREVENT:
			reset_frame_skip();
			break;
	    case SDL_QUIT:
		neo_emu_done = 1;
#ifdef __QNXNTO__
		shutdown = 1;
#endif
		break;
	    default:
		break;
	    }
	}

	/* update the internal representation of keyslot */
	update_p1_key();
	update_p2_key();
	update_start();
	update_coin();

	if (slow_motion)
	    SDL_Delay(100);

	if (conf.sound) {
	    PROFILER_START(PROF_Z80);
	    for (i = 0; i < nb_interlace; i++) {
		cpu_z80_run(cpu_z80_timeslice_interlace);
		my_timer();
	    }
	    PROFILER_STOP(PROF_Z80);
	} /*
	    else
	    my_timer();*/

	if (!conf.debug) {
	    if (conf.raster) {
		for (i = 0; i < 261; i++) {
		    tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
		    if (update_scanline())
			cpu_68k_interrupt(2);
		}
		tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
		state_handling(pending_save_state,pending_load_state);
		
		update_screen();
		cpu_68k_interrupt(1);
	    } else {
		PROFILER_START(PROF_68K);
		tm_cycle=cpu_68k_run(cpu_68k_timeslice-tm_cycle);
		PROFILER_STOP(PROF_68K);
		a = neo_interrupt();
		
		/* state handling (we save/load before interrupt) */
		state_handling(pending_save_state,pending_load_state);
		
		if (a) {
		    cpu_68k_interrupt(a);
		}
	    }
	} else {
	    /* we arre in debug mode -> we are just here for event handling */
	    neo_emu_done=1;
	}
#ifdef ENABLE_PROFILER
	profiler_show_stat();
#endif
	PROFILER_START(PROF_ALL);
    }
}
Beispiel #11
0
static int
listener_config_tcp(config_object_t *config)
{
	char val[4096];
	char inp[4096];
	const char *family = "ipv4";
	struct in_addr sin;
	struct in6_addr sin6;
	int done = 0;

	printf("\n");
	printf("The TCP listener module is designed for use in environments\n"
	       "where the guests and hosts communicate over viosproxy.\n\n");

	/* IP ADDRESS/FAMILY */
	printf("The IP address is the address that a client will use to\n"
	       "send fencing requests to fence_virtd.\n\n");

	if (sc_get(config, "listeners/tcp/@address",
		   val, sizeof(val)-1)) {
		strncpy(val, IPV4_MCAST_DEFAULT, sizeof(val));
	}

	done = 0;
	do {
		text_input("TCP Listen IP Address", val, inp, sizeof(inp));

		if (inet_pton(AF_INET, inp, &sin) == 1) {
			printf("\nUsing ipv4 as family.\n\n");
			family = "ipv4";
			done = 1;
		} else if (inet_pton(AF_INET6, inp, &sin6) == 1) {
			printf("\nUsing ipv6 as family.\n\n");
			family = "ipv6";
			done = 1;
		} else {
			printf("'%s' is not a valid IP address!\n", inp);
			continue;
		}
	} while (!done);

	sc_set(config, "listeners/tcp/@family", family);
	sc_set(config, "listeners/tcp/@address", inp);

	/* MULTICAST IP PORT */
	if (sc_get(config, "listeners/tcp/@port",
		   val, sizeof(val)-1)) {
		snprintf(val, sizeof(val), "%d", DEFAULT_MCAST_PORT);
	}

	done = 0;
	do {
		text_input("TCP Listen Port", val, inp, sizeof(inp));
		char *p;
		int ret;

		ret = strtol(inp, &p, 0);
		if (*p != '\0' || ret <= 0 || ret >= 65536) {
			printf("Port value '%s' is out of range\n", val);
			continue;
		}
		done = 1;
	} while (!done);
	sc_set(config, "listeners/tcp/@port", inp);

	/* KEY FILE */
	printf("\nThe key file is the shared key information which is used to\n"
	       "authenticate fencing requests.  The contents of this file must\n"
	       "be distributed to each physical host and virtual machine within\n"
	       "a cluster.\n\n");

	if (sc_get(config, "listeners/tcp/@key_file",
		   val, sizeof(val)-1)) {
		strncpy(val, DEFAULT_KEY_FILE, sizeof(val));
	}

	done = 0;
	do { 
		text_input("Key File", val, inp, sizeof(inp));

		if (!strcasecmp(inp, "none")) {
			break;
		}

		if (strlen(inp) > 0) {
			if (inp[0] != '/') {
				printf("Invalid key file: %s\n", inp);
				if (yesno("Use anyway", 1) == 1)
					done = 1;
			} else
				done = 1;
		} else
			printf("No key file given\n");
	} while (!done);

	if (!strcasecmp(inp, "none")) {
		sc_set(config, "listeners/tcp/@key_file", NULL);
	} else {
		sc_set(config, "listeners/tcp/@key_file", inp);
	}

	return 0;
}