Exemple #1
0
static struct connection* connection_new(const char *evdev_path,
					 const char *host_and_port)
{
  struct connection* self;

  /* Allocate the new server object */
  self = malloc(sizeof(struct connection));
  assert(self != NULL);
  memset(self, 0, sizeof(struct connection));

  if (evdev_init(&self->evdev, evdev_path) < 0) {
    connection_delete(self);
    return NULL;
  }
  connection_set_status_led(self, 0);

  connection_message(self, "Connecting to '%s'...", host_and_port);
  self->server = server_new(host_and_port);
  if (!self->server) {
    connection_delete(self);
    return NULL;
  }

  /* Tell the server about our device */
  if (evdev_send_metadata(&self->evdev, self->server)) {
    connection_delete(self);
    return NULL;
  }

  connection_list_append(self);
  connection_message(self, "Connected");
  connection_set_status_led(self, 1);

  return self;
}
Exemple #2
0
int __init input_init(void)
#endif
{
#ifndef MODULE
#ifdef CONFIG_INPUT_KEYBDEV
	keybdev_init();
#endif
#ifdef CONFIG_INPUT_MOUSEDEV
	mousedev_init();
#endif
#ifdef CONFIG_INPUT_JOYDEV
	joydev_init();
#endif
#ifdef CONFIG_INPUT_EVDEV
	evdev_init();
#endif
#endif
	return 0;
}
Exemple #3
0
int
main (int argc, char **argv)
{
  int ret;
  int c;

  FILE *pidfile;
  struct utsname sysinfo;

  machine_type machine;

  while ((c = getopt(argc, argv, "fdv")) != -1)
    {
      switch (c)
	{
	  case 'f':
	    console = 1;
	    break;

	  case 'd':
	    debug = 1;
	    console = 1;
	    break;

	  case 'v':
	    printf("pommed v" M_VERSION " Apple laptops hotkeys handler\n");
	    printf("Copyright (C) 2006-2011 Julien BLACHE <*****@*****.**>\n");

	    exit(0);
	    break;

	  default:
	    usage();

	    exit(1);
	    break;
	}
    }

  if (geteuid() != 0)
    {
      logmsg(LOG_ERR, "pommed needs root privileges to operate");

      exit(1);
    }

  if (!console)
    {
      openlog("pommed", LOG_PID, LOG_DAEMON);
    }

  logmsg(LOG_INFO, "pommed v" M_VERSION " Apple laptops hotkeys handler");
  logmsg(LOG_INFO, "Copyright (C) 2006-2011 Julien BLACHE <*****@*****.**>");

  /* Load our configuration */
  ret = config_load();
  if (ret < 0)
    {
      exit(1);
    }

  /* Identify the machine we're running on */
  machine = check_machine();
  switch (machine)
    {
      case MACHINE_MAC_UNKNOWN:
	logmsg(LOG_ERR, "Unknown Apple machine");

	exit(1);
	break;

      case MACHINE_UNKNOWN:
	logmsg(LOG_ERR, "Unknown non-Apple machine");

	exit(1);
	break;

      case MACHINE_ERROR:
	exit(1);
	break;

      default:
	if (machine < MACHINE_LAST)
	  {
#ifdef __powerpc__
	    mops = &pb_mops[machine];
#else
	    mops = &mb_mops[machine];
#endif /* __powerpc__ */
	  }
	break;
    }

  /* Runtime sanity check: catch errors in the mb_mops and pb_mops arrays */
  if (mops->type != machine)
    {
      logmsg(LOG_ERR, "machine_ops mismatch: expected %d, found %d", machine, mops->type);

      exit(1);
    }

  if (debug)
    {
      ret = uname(&sysinfo);

      if (ret < 0)
	logmsg(LOG_ERR, "uname() failed: %s", strerror(errno));
      else
	logdebug("System: %s %s %s\n", sysinfo.sysname, sysinfo.release, sysinfo.machine);
    }

  ret = evloop_init();
  if (ret < 0)
    {
      logmsg(LOG_ERR, "Event loop initialization failed");
      exit (1);
    }

  ret = mops->lcd_backlight_probe();
  if (ret < 0)
    {
      logmsg(LOG_ERR, "LCD backlight probe failed, check debug output");

      exit(1);
    }

  ret = evdev_init();
  if (ret < 1)
    {
      logmsg(LOG_ERR, "No suitable event devices found");

      exit(1);
    }

  kbd_backlight_init();

  ret = audio_init();
  if (ret < 0)
    {
      logmsg(LOG_WARNING, "Audio initialization failed, audio support disabled");
    }

  ret = mbpdbus_init();
  if (ret < 0)
    {
      logmsg(LOG_WARNING, "Could not connect to DBus system bus");
    }

  power_init();

  if (!console)
    {
      /*
       * Detach from the console
       */
      if (daemon(0, 0) != 0)
	{
	  logmsg(LOG_ERR, "daemon() failed: %s", strerror(errno));

	  evdev_cleanup();

	  exit(1);
	}
    }

  pidfile = fopen(PIDFILE, "w");
  if (pidfile == NULL)
    {
      logmsg(LOG_WARNING, "Could not open pidfile %s: %s", PIDFILE, strerror(errno));

      evdev_cleanup();

      exit(1);
    }
  fprintf(pidfile, "%d\n", getpid());
  fclose(pidfile);

  /* Spawn the beep thread */
  beep_init();

  signal(SIGINT, sig_int_term_handler);
  signal(SIGTERM, sig_int_term_handler);


  do
    {
      ret = evloop_iteration();
    }
  while (ret >= 0);

  evdev_cleanup();

  beep_cleanup();

  mbpdbus_cleanup();

  kbd_backlight_cleanup();

  power_cleanup();

  evloop_cleanup();

  config_cleanup();

  logmsg(LOG_INFO, "Exiting");

  if (!console)
    closelog();

  unlink(PIDFILE);

  return 0;
}
Exemple #4
0
int main(int argc, char* argv[]) {
  CONFIGURATION config;
  config_parse(argc, argv, &config);

  if (config.action == NULL || strcmp("help", config.action) == 0)
    help();
  
  enum platform system = platform_check(config.platform);
  if (system == 0) {
    fprintf(stderr, "Platform '%s' not found\n", config.platform);
    exit(-1);
  }
  
  if (strcmp("map", config.action) == 0) {
    if (config.address == NULL) {
      perror("No filename for mapping");
      exit(-1);
    }
    udev_init(!inputAdded, config.mapping);
    for (int i=0;i<config.inputsCount;i++)
      evdev_create(config.inputs[i].path, config.inputs[i].mapping);
    
    evdev_map(config.address);
    exit(0);
  }

  if (config.address == NULL) {
    config.address = malloc(MAX_ADDRESS_SIZE);
    if (config.address == NULL) {
      perror("Not enough memory");
      exit(-1);
    }
    config.address[0] = 0;
    gs_discover_server(config.address);
    if (config.address[0] == 0) {
      fprintf(stderr, "Autodiscovery failed. Specify an IP address next time.\n");
      exit(-1);
    }
  }
  
  char host_config_file[128];
  sprintf(host_config_file, "hosts/%s.conf", config.address);
  config_file_parse(host_config_file, &config);

  SERVER_DATA server;
  server.address = config.address;
  int ret;
  if ((ret = gs_init(&server, config.key_dir)) == GS_OUT_OF_MEMORY) {
    fprintf(stderr, "Not enough memory\n");
    exit(-1);
  } else if (ret == GS_INVALID) {
    fprintf(stderr, "Invalid data received from server: %s\n", config.address, gs_error);
    exit(-1);
  } else if (ret != GS_OK) {
    fprintf(stderr, "Can't connect to server %s\n", config.address);
    exit(-1);
  }

  if (strcmp("list", config.action) == 0) {
    pair_check(&server);
    applist(&server);
  } else if (strcmp("stream", config.action) == 0) {
    pair_check(&server);
    if (IS_EMBEDDED(system)) {
      for (int i=0;i<config.inputsCount;i++)
        evdev_create(config.inputs[i].path, config.inputs[i].mapping);

      udev_init(!inputAdded, config.mapping);
      evdev_init();
      #ifdef HAVE_LIBCEC
      cec_init();
      #endif /* HAVE_LIBCEC */
    }
    #ifdef HAVE_SDL
    else if (system == SDL)
      sdl_init(config.stream.width, config.stream.height);
    #endif

    stream(&server, &config, system);
  } else if (strcmp("pair", config.action) == 0) {
    char pin[5];
    sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10);
    printf("Please enter the following PIN on the target PC: %s\n", pin);
    if (gs_pair(&server, &pin[0]) != GS_OK) {
      fprintf(stderr, "Failed to pair to server: %s\n", gs_error);
    } else {
      printf("Succesfully paired\n");
    }
  } else if (strcmp("quit", config.action) == 0) {
    pair_check(&server);
    gs_quit_app(&server);
  } else
    fprintf(stderr, "%s is not a valid action\n", config.action);
}
Exemple #5
0
int main(int argc, char* argv[]) {
  printf("Moonlight Embedded %d.%d.%d (%s)\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, COMPILE_OPTIONS);

  CONFIGURATION config;
  config_parse(argc, argv, &config);

  if (config.action == NULL || strcmp("help", config.action) == 0)
    help();
  
  enum platform system = platform_check(config.platform);
  if (system == 0) {
    fprintf(stderr, "Platform '%s' not found\n", config.platform);
    exit(-1);
  }
  config.stream.supportsHevc = config.stream.supportsHevc || platform_supports_hevc(system);
  
  if (strcmp("map", config.action) == 0) {
    if (config.address == NULL) {
      perror("No filename for mapping");
      exit(-1);
    }
    udev_init(!inputAdded, config.mapping);
    for (int i=0;i<config.inputsCount;i++)
      evdev_create(config.inputs[i].path, config.inputs[i].mapping);
    
    evdev_map(config.address);
    exit(0);
  }

  if (config.address == NULL) {
    config.address = malloc(MAX_ADDRESS_SIZE);
    if (config.address == NULL) {
      perror("Not enough memory");
      exit(-1);
    }
    config.address[0] = 0;
    printf("Searching for server...\n");
    gs_discover_server(config.address);
    if (config.address[0] == 0) {
      fprintf(stderr, "Autodiscovery failed. Specify an IP address next time.\n");
      exit(-1);
    }
  }
  
  char host_config_file[128];
  sprintf(host_config_file, "hosts/%s.conf", config.address);
  if (access(host_config_file, R_OK) != -1)
    config_file_parse(host_config_file, &config);

  SERVER_DATA server;
  server.address = config.address;
  printf("Connect to %s...\n", server.address);

  int ret;
  if ((ret = gs_init(&server, config.key_dir)) == GS_OUT_OF_MEMORY) {
    fprintf(stderr, "Not enough memory\n");
    exit(-1);
  } else if (ret == GS_INVALID) {
    fprintf(stderr, "Invalid data received from server: %s\n", config.address, gs_error);
    exit(-1);
  } else if (ret == GS_UNSUPPORTED_VERSION) {
    if (!config.unsupported_version) {
      fprintf(stderr, "Unsupported version: %s\n", gs_error);
      exit(-1);
    }
  } else if (ret != GS_OK) {
    fprintf(stderr, "Can't connect to server %s\n", config.address);
    exit(-1);
  }

  printf("NVIDIA %s, GFE %s (protocol version %d)\n", server.gpuType, server.gfeVersion, server.serverMajorVersion);

  if (strcmp("list", config.action) == 0) {
    pair_check(&server);
    applist(&server);
  } else if (strcmp("stream", config.action) == 0) {
    pair_check(&server);
    if (IS_EMBEDDED(system)) {
      for (int i=0;i<config.inputsCount;i++) {
        printf("Add input %s (mapping %s)...\n", config.inputs[i].path, config.inputs[i].mapping);
        evdev_create(config.inputs[i].path, config.inputs[i].mapping);
      }

      udev_init(!inputAdded, config.mapping);
      evdev_init();
      #ifdef HAVE_LIBCEC
      cec_init();
      #endif /* HAVE_LIBCEC */
    }
    #ifdef HAVE_SDL
    else if (system == SDL)
      sdl_init(config.stream.width, config.stream.height, config.fullscreen);
    #endif

    stream(&server, &config, system);
  } else if (strcmp("pair", config.action) == 0) {
    char pin[5];
    sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10);
    printf("Please enter the following PIN on the target PC: %s\n", pin);
    if (gs_pair(&server, &pin[0]) != GS_OK) {
      fprintf(stderr, "Failed to pair to server: %s\n", gs_error);
    } else {
      printf("Succesfully paired\n");
    }
  } else if (strcmp("unpair", config.action) == 0) {
    if (gs_unpair(&server) != GS_OK) {
      fprintf(stderr, "Failed to unpair to server: %s\n", gs_error);
    } else {
      printf("Succesfully unpaired\n");
    }
  } else if (strcmp("quit", config.action) == 0) {
    pair_check(&server);
    gs_quit_app(&server);
  } else
    fprintf(stderr, "%s is not a valid action\n", config.action);
}