Example #1
0
/** Run testcase. */
static int irtestcase(int fd_io, int fd_cmd)
{
	int r;
	struct lirc_config* config;
	char code[64];
	char* c;

	if (opt_lircrc != NULL) {
		if (lirc_readconfig_only(opt_lircrc, &config, NULL) != 0) {
			fputs("Cannot initiate lircrc decoding\n", stderr);
			exit(2);
		}
	}
	while (nextcode(fd_io, code, sizeof(code)) == 1) {
		fputs(code, stdout);
		if (strstr(code, "__EOF") != NULL)
			exit(0);
		fputs(code, code_log);
		if (opt_lircrc != NULL) {
			r = lirc_code2char(config, code, &c);
			while (r == 0 && c != NULL) {
				printf("    %s\n", c);
				fprintf(app_log, "%s\n", c);
				r = lirc_code2char(config, code, &c);
			}
			fflush(app_log);
		}
		fflush(stdout);
		fflush(code_log);
	}
	return 0;
}
Example #2
0
int getnextlircinput(void)
{
		char *code;
		char *c;
		int ret;

		if (lirc_nextcode(&code) !=0)
				return LIRCE161_ERROR;
#ifdef DEBUG
		printf("Received lirc input %s\n", code);
#endif
		while((ret = lirc_code2char(lirc_config, code, &c)) == 0 && c != NULL){
#ifdef DEBUG
				printf("Received config %s\n", c);
#endif
				processstate(c);
				if (strncmp(c, "done", 4) == 0){
						free(code);
						return LIRCE161_DONE;
						}
		}

		free(code);
		return LIRCE161_OK;
}
Example #3
0
File: lirc.c Project: blinry/vlc
static void Process( intf_thread_t *p_intf )
{
    for( ;; )
    {
        char *code, *c;
        if( lirc_nextcode( &code ) )
            return;

        if( code == NULL )
            return;

        while( vlc_object_alive( p_intf )
                && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0)
                && (c != NULL) )
        {
            if( !strncmp( "key-", c, 4 ) )
            {
                vlc_action_t i_key = vlc_GetActionId( c );
                if( i_key )
                    var_SetInteger( p_intf->p_libvlc, "key-action", i_key );
                else
                    msg_Err( p_intf, "Unknown hotkey '%s'", c );
            }
            else
            {
                msg_Err( p_intf, "this doesn't appear to be a valid keycombo "
                                 "lirc sent us. Please look at the "
                                 "doc/lirc/example.lirc file in VLC" );
                break;
            }
        }
        free( code );
    }
}
Example #4
0
void lircCheckInput(void)
{
    struct pollfd lircpoll;
    lircpoll.fd = g_lircfd;
    lircpoll.events = POLLIN;

    if(poll(&lircpoll, 1, 0) > 0)
    {
        char *code;
        char *c;
        int ret;

        if(lirc_nextcode(&code) == 0 && code != NULL)
        {
            while((ret = lirc_code2char(g_config, code, &c)) == 0 && c!=NULL)
            {
                char *c_ind = c;
                while(*c_ind != '\0')
                {
                    *c_ind = toupper(*c_ind);
                    c_ind++;
                }
                DebugMessage(M64MSG_VERBOSE, "LIRC Execing command \"%s\"", c);

                if(strcmp(c, "SAVE") == 0)
                    main_state_save(1, NULL); /* save in mupen64plus format using current slot */
                else if(strcmp(c, "LOAD") == 0)
                    main_state_load(NULL); /* load using current slot */
                else if(strcmp(c, "QUIT") == 0)
                    main_stop();
                else if(strcmp(c, "FULLSCREEN") == 0)
                    gfx.changeWindow();
                else if(strcmp(c, "MUTE") == 0)
                    main_volume_mute();
                else if(strcmp(c, "VOL+") == 0)
                    main_volume_up();
                else if(strcmp(c, "VOL-") == 0)
                    main_volume_down();
                else if(strcmp(c, "SCREENSHOT") == 0)
                    main_take_next_screenshot();
                else if(strcmp(c, "SPEED+") == 0)
                    main_speedup(5);
                else if(strcmp(c, "SPEED-") == 0)
                    main_speeddown(5);
                else if(strcmp(c, "ADVANCE") == 0)
                    main_advance_one();
                else if(strcmp(c, "PAUSE") == 0)
                    main_toggle_pause();
                else
                {
                    int val = ((int)c[0])-((int) '0');
                    if (val >= 0 && val <= 9)
                        savestates_select_slot( val );
                }
            }
            free(code);
        }
    }
}
Example #5
0
static gboolean
totem_lirc_read_code (GIOChannel *source, GIOCondition condition, TotemLircPlugin *pi)
{
	char *code;
	char *str = NULL, *url = NULL;
	int ok;
	TotemRemoteCommand cmd;

	if (condition & (G_IO_ERR | G_IO_HUP)) {
		/* LIRC connection broken. */
		return FALSE;
	}

	/* this _could_ block, but it shouldn't */
	lirc_nextcode (&code);

	if (code == NULL) {
		/* the code was incomplete or something */
		return TRUE;
	}

	do {
		ok = lirc_code2char (pi->lirc_config, code, &str);

		if (ok != 0) {
			/* Couldn't convert lirc code to string. */
			break;
		}

		if (str == NULL) {
			/* there was no command associated with the code */
			break;
		}

		if (g_str_has_prefix (str, TOTEM_IR_SETTING) != FALSE) {
			TotemRemoteSetting setting;

			setting = totem_lirc_to_setting (str, &url);
			if (setting >= 0) {
				gboolean value;

				value = totem_action_remote_get_setting (pi->totem, setting);
				totem_action_remote_set_setting (pi->totem, setting, !value);
			}
		} else {
			cmd = totem_lirc_to_command (str, &url);
			totem_action_remote (pi->totem, cmd, url);
		}
		g_free (url);
	} while (TRUE);

	g_free (code);

	return TRUE;
}
Example #6
0
static void *thread_func(void *arg)
{
	struct lirc_config *config;
	int    sock, flags;

	if ((sock = lirc_init("gmu", 1)) != -1) {
		fcntl(sock, F_SETOWN, getpid());
		flags = fcntl(sock, F_GETFL, 0);
		if (flags != -1) fcntl(sock, F_SETFL, flags|O_NONBLOCK);
		if (lirc_readconfig(NULL, &config, NULL) == 0) {
			char *code, *c;
			int   ret = 0;

			while (run && lirc_nextcode(&code) == 0) {
				if (code != NULL) {
					if ((ret = lirc_code2char(config, code, &c)) == 0 && c != NULL) {
						wdprintf(V_DEBUG, "lirc_frontend", "Got button press.\n");
						if (strcmp(c, "play") == 0)
							gmu_core_play();					
						else if (strcmp(c, "pause") == 0)
							gmu_core_pause();
						else if (strcmp(c, "stop") == 0)
							gmu_core_stop();
						else if (strcmp(c, "toggle_pause") == 0)
							gmu_core_play_pause();
						else if (strcmp(c, "toggle_play_pause") == 0)
							gmu_core_play_pause();
						else if (strcmp(c, "next") == 0)
							gmu_core_next();				
						else if (strcmp(c, "prev") == 0)
							gmu_core_previous();
						else if (strcmp(c, "volume_up") == 0)
							gmu_core_set_volume(gmu_core_get_volume()+1);
						else if (strcmp(c, "volume_down") == 0)
							gmu_core_set_volume(gmu_core_get_volume()-1);
						else
							wdprintf(V_WARNING, "lirc_frontend", "Unknown command: %s\n", c);
						c = NULL;
					}
				}
				usleep(400);
				free(code);
				if (ret == -1) break;
			}
			wdprintf(V_INFO, "lirc_frontend", "Exitting.\n");
			lirc_freeconfig(config);
		}
		lirc_deinit();
	}
	return NULL;
}
Example #7
0
char *lirc_ir2char(const struct lirc_state *state,struct lirc_config *config,char *code)
{
	static int warning=1;
	char *string;
	
	if(warning)
	{
		fprintf(stderr,"%s: warning: lirc_ir2char() is obsolete\n",
			state->lirc_prog);
		warning=0;
	}
	if(lirc_code2char(state,config,code,&string)==-1) return(NULL);
	return(string);
}
Example #8
0
int mp_input_lirc_read(int fd,char* dest, int s) {
  int r,cl = 0;
  char *code = NULL,*c = NULL;

  // We have something in the buffer return it
  if(cmd_buf != NULL) {
    int l = strlen(cmd_buf), w = l > s ? s : l;
    memcpy(dest,cmd_buf,w);
    l -= w;
    if(l > 0)
      memmove(cmd_buf,&cmd_buf[w],l+1);
    else {
      free(cmd_buf);
      cmd_buf = NULL;
    }
    return w;
  }

  // Nothing in the buffer, poll the lirc fd
  if(lirc_nextcode(&code) != 0) {
    mp_msg(MSGT_LIRC,MSGL_ERR,"Lirc error :(\n");
    return MP_INPUT_DEAD;
  }

  if(!code) return MP_INPUT_NOTHING;

  // We put all cmds in a single buffer separated by \n
  while((r = lirc_code2char(lirc_config,code,&c))==0 && c!=NULL) {
    int l = strlen(c);
    if(l <= 0)
      continue;
    cmd_buf = realloc(cmd_buf,cl+l+2);
    memcpy(&cmd_buf[cl],c,l);
    cl += l+1;
    cmd_buf[cl-1] = '\n';
    cmd_buf[cl] = '\0';
  }

  free(code);

  if(r < 0)
    return MP_INPUT_DEAD;
  else if(cmd_buf) // return the first command in the buffer
    return mp_input_lirc_read(fd,dest,s);
  else
    return MP_INPUT_RETRY;

}
/**
 * Get key from the device.
 * \param drvthis  Pointer to driver structure.
 * \return         String representation of the key;
 *                 \c NULL if nothing available / unmapped key.
 */
MODULE_EXPORT const char *
lircin_get_key (Driver *drvthis)
{
        PrivateData * p = drvthis->private_data;

	char *code = NULL, *cmd = NULL;

	if ((lirc_nextcode(&code) == 0) && (code != NULL)) {
		if ((lirc_code2char(p->lircin_irconfig,code,&cmd)==0) && (cmd!=NULL)) {
			report(RPT_DEBUG, "%s: \"%s\"", drvthis->name, cmd);
		}
		free(code);
	}

	return cmd;
}
Example #10
0
/* Read a key code from lircd
*/
int read_lirc(void) {
    char *code;
    char *c;
    int key=0;

    if (lirc_nextcode(&code)==0) {
        if (code!=NULL) {
            while((lirc_code2char(lircconfig,code,&c)==0) && (c != NULL)) {
                key = (unsigned char)c[0];
            }
            free(code);
            return key;
        }
        return -1;
    }
    return 0;
}
Example #11
0
void LircClient::Process(void)
{
    char *code = 0;
    char *ir = 0;
    int ret;

    /* Process all events read */
    while (lirc_nextcode(&ir) == 0)
    {
        if (!ir)
            continue;
        while ((ret = lirc_code2char(lircConfig, ir, &code)) == 0 &&
               code != NULL)
        {
            QKeySequence a(code);

            int keycode = 0;

            // Send a dummy keycode if we couldn't convert the key sequence.
            // This is done so the main code can output a warning for bad
            // mappings.
            if (!a.count())
                QApplication::postEvent(mainWindow, new LircKeycodeEvent(code, 
                                        keycode, true));

            for (unsigned int i = 0; i < a.count(); i++)
            {
                keycode = a[i];

                QApplication::postEvent(mainWindow, new LircKeycodeEvent(code, 
                                        keycode, true));
                QApplication::postEvent(mainWindow, new LircKeycodeEvent(code, 
                                        keycode, false));

                SpawnApp();
            }
        }

        free(ir);
        if (ret == -1)
            break;
    }
}
Example #12
0
File: lirc.c Project: naguirre/enna
static Eina_Bool _lirc_code_received(void *data, Ecore_Fd_Handler * fd_handler)
{
    char *code, *event;
    int ret = -1;

    while (lirc_nextcode(&code) == 0 && code != NULL)
    {
        while ((ret = lirc_code2char(mod->lirc_config, code, &event)) == 0
                && event != NULL)
        {
            enna_input in;

            in = _get_input_from_event(event);
            if (in != ENNA_INPUT_UNKNOWN)
                enna_input_event_emit(in);
        }
    }
    return 1;
}
Example #13
0
int lirc_fbi_havedata(int* rc, char key[11])
{
    char *code,*cmd;
    int ret=-1;
    
    while (lirc_nextcode(&code) == 0  &&  code != NULL) {
	ret = 0;
	if (config) {
	    /* use ~/.lircrc */
	    while (lirc_code2char(config,code,&cmd)==0 && cmd != NULL) {
		memset(key,0,11);
		strncpy(key,cmd,10);
		*rc = strlen(cmd);
		if (debug)
		    fprintf(stderr,"lirc: cmd \"%s\"\n", cmd);
	    }
	}
	free(code);
    }
    return ret;
}
Example #14
0
File: lirc.cpp Project: 63n/bino
void lircclient::process_events()
{
    if (_initialized)
    {
        char *code;
        char *cmd;
        int e;

        if ((e = lirc_nextcode(&code)) != 0)
        {
            msg::err(_("Cannot get LIRC event; disabling LIRC support."));
            deinit();
            return;
        }
        if (!code)
        {
            /* No event currently available */
            return;
        }
        while ((e = lirc_code2char(_config, code, &cmd)) == 0 && cmd)
        {
            command c;
            if (!dispatch::parse_command(cmd, &c))
            {
                msg::err(str::asprintf(_("Received invalid command '%s' from LIRC."), str::sanitize(cmd).c_str()));
            }
            else
            {
                send_cmd(c);
            }
        }
        std::free(code);
        if (e != 0)
        {
            msg::wrn(_("Cannot get command for LIRC code."));
        }
    }
}
Example #15
0
/*****************************************************************************
 * Run: main loop
 *****************************************************************************/
static void Run( intf_thread_t *p_intf )
{
    char *code, *c;

    while( !p_intf->b_die )
    {
        /* Sleep a bit */
        msleep( INTF_IDLE_SLEEP );

        /* We poll the lircsocket */
        if( lirc_nextcode(&code) != 0 )
        {
            break;
        }

        if( code == NULL )
        {
            continue;
        }

        while( !p_intf->b_die
                && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
                && c != NULL )
        {
            vlc_value_t keyval;

            if( strncmp( "key-", c, 4 ) )
            {
                msg_Err( p_intf, "this doesn't appear to be a valid keycombo lirc sent us. Please look at the doc/lirc/example.lirc file in VLC" );
                break;
            }
            keyval.i_int = config_GetInt( p_intf, c );
            var_Set( p_intf->p_vlc, "key-pressed", keyval );
        }
        free( code );
    }
}
Example #16
0
static gboolean
rb_lirc_plugin_read_code (GIOChannel *source,
			  GIOCondition condition,
			  RBLircPlugin *plugin)
{
	char *code;
	char *str = NULL;	/* owned by lirc config, must not be freed */
	int ok;
	gboolean processed = FALSE;

	if (condition & (G_IO_ERR | G_IO_HUP)) {
		/* TODO: retry after a minute? */
		rb_debug ("LIRC connection broken.  sorry.");
		return FALSE;
	}

	lirc_nextcode (&code);
	if (code == NULL) {
		rb_debug ("Got incomplete lirc code");
		return TRUE;
	}

	do {
		ok = lirc_code2char (plugin->lirc_config, code, &str);

		if (ok != 0) {
			rb_debug ("couldn't convert lirc code \"%s\" to string", code);
		} else if (str == NULL) {
			if (processed == FALSE)
				rb_debug ("unknown LIRC code \"%s\"", code);
			break;
		} else if (strcmp (str, RB_IR_COMMAND_PLAY) == 0) {
			gboolean playing;
			rb_shell_player_get_playing (plugin->shell_player, &playing, NULL);
			if (playing == FALSE)
				rb_shell_player_playpause (plugin->shell_player, FALSE, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_PAUSE) == 0) {
			rb_shell_player_pause (plugin->shell_player, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_PLAYPAUSE) == 0) {
			rb_shell_player_playpause (plugin->shell_player, FALSE, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_STOP) == 0) {
			rb_shell_player_stop (plugin->shell_player);
		} else if (strcmp (str, RB_IR_COMMAND_SHUFFLE) == 0) {
			gboolean shuffle;
			gboolean repeat;
			if (rb_shell_player_get_playback_state (plugin->shell_player, &shuffle, &repeat)) {
				rb_shell_player_set_playback_state (plugin->shell_player, !shuffle, repeat);
			}
		} else if (strcmp (str, RB_IR_COMMAND_REPEAT) == 0) {
			gboolean shuffle;
			gboolean repeat;
			if (rb_shell_player_get_playback_state (plugin->shell_player, &shuffle, &repeat)) {
				rb_shell_player_set_playback_state (plugin->shell_player, shuffle, !repeat);
			}
		} else if (strcmp (str, RB_IR_COMMAND_NEXT) == 0) {
			rb_shell_player_do_next (plugin->shell_player, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_PREVIOUS) == 0) {
			rb_shell_player_do_previous (plugin->shell_player, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_SEEK_FORWARD) == 0) {
			rb_shell_player_seek (plugin->shell_player, FFWD_OFFSET, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_SEEK_BACKWARD) == 0) {
			rb_shell_player_seek (plugin->shell_player, -RWD_OFFSET, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_VOLUME_UP) == 0) {
			rb_shell_player_set_volume_relative (plugin->shell_player, 0.1, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_VOLUME_DOWN) == 0) {
			rb_shell_player_set_volume_relative (plugin->shell_player, -0.1, NULL);
		} else if (strcmp (str, RB_IR_COMMAND_MUTE) == 0) {
			gboolean mute;
			if (rb_shell_player_get_mute (plugin->shell_player, &mute, NULL)) {
				rb_shell_player_set_mute (plugin->shell_player, !mute, NULL);
			}
		} else if (strcmp (str,RB_IR_COMMAND_QUIT) == 0) {
			RBShell *shell;

			g_object_get (plugin, "object", &shell, NULL);
			rb_shell_quit (shell, NULL);
			g_object_unref (shell);
			/* the plugin will have been deactivated, so we can't continue the loop */
			break;
		}
		processed = TRUE;
	} while (ok == 0);
	g_free (code);

	return TRUE;
}
Example #17
0
int main(int argc, char *argv[])
{
	struct lirc_config *config;
	int daemonize=0;

	progname="irexec-" VERSION;
	while(1)
	{
		int c;
		static struct option long_options[] =
		{
			{"help",no_argument,NULL,'h'},
			{"version",no_argument,NULL,'v'},
#ifdef DAEMONIZE
			{"daemon",no_argument,NULL,'d'},
#endif
			{0, 0, 0, 0}
		};
		c = getopt_long(argc,argv,"hvd",long_options,NULL);
		if(c==-1)
			break;
		switch (c)
		{
		case 'h':
			printf("Usage: %s [options] [config_file]\n",argv[0]);
			printf("\t -h --help\t\tdisplay this message\n");
			printf("\t -v --version\t\tdisplay version\n");
#ifdef DAEMONIZE
			printf("\t -d --daemon\t\trun in background\n");
#endif
			return(EXIT_SUCCESS);
		case 'v':
			printf("%s\n",progname);
			return(EXIT_SUCCESS);
#ifdef DAEMONIZE
		case 'd':
			daemonize=1;
			break;
#endif
		default:
			printf("Usage: %s [options] [config_file]\n",argv[0]);
			return(EXIT_FAILURE);
		}
	}
	if (optind < argc-1)
	{
		fprintf(stderr,"%s: too many arguments\n",progname);
		return(EXIT_FAILURE);
	}
	
	if(lirc_init("irexec",daemonize ? 0:1)==-1) exit(EXIT_FAILURE);

	if(lirc_readconfig(optind!=argc ? argv[optind]:NULL,&config,NULL)==0)
	{
		char *code;
		char *c;
		int ret;

#ifdef DAEMONIZE
		if(daemonize)
		{
			if(daemon(0,0)==-1)
			{
				fprintf(stderr,"%s: can't daemonize\n",
					progname);
				perror(progname);
				lirc_freeconfig(config);
				lirc_deinit();
				exit(EXIT_FAILURE);
			}
		}
#endif
		while(lirc_nextcode(&code)==0)
		{
			if(code==NULL) continue;
			while((ret=lirc_code2char(config,code,&c))==0 &&
			      c!=NULL)
			{
#if defined(DAEMONIZE) && defined(DEBUG)
				if(!daemonize)
				{
					printf("Execing command \"%s\"\n",c);
				}
#endif
				system(c);
			}
			free(code);
			if(ret==-1) break;
		}
		lirc_freeconfig(config);
	}

	lirc_deinit();
	exit(EXIT_SUCCESS);
}
Example #18
0
static gboolean
mex_lirc_read_cb (GIOChannel         *source,
                  GIOCondition        condition,
                  struct lirc_config *config)
{
  gboolean success = TRUE;

  while (condition & (G_IO_PRI | G_IO_IN))
    {
      gint error_code;
      gchar *lirc_code, *lirc_char;

      while (((error_code = lirc_nextcode (&lirc_code)) == 0) && lirc_code)
        {
          while ((lirc_code2char (config, lirc_code, &lirc_char) == 0) &&
                 (lirc_char != NULL))
            {
              if (g_str_equal (lirc_char, "up"))
                mex_lirc_do_key_event (CLUTTER_KEY_Up);
              else if (g_str_equal (lirc_char, "down"))
                mex_lirc_do_key_event (CLUTTER_KEY_Down);
              else if (g_str_equal (lirc_char, "left"))
                mex_lirc_do_key_event (CLUTTER_KEY_Left);
              else if (g_str_equal (lirc_char, "right"))
                mex_lirc_do_key_event (CLUTTER_KEY_Right);
              else if (g_str_equal (lirc_char, "enter"))
                mex_lirc_do_key_event (MEX_KEY_OK);
              else if (g_str_equal (lirc_char, "back"))
                mex_lirc_do_key_event (MEX_KEY_BACK);
              else if (g_str_equal (lirc_char, "home"))
                mex_lirc_do_key_event (MEX_KEY_HOME);
            }

          g_free (lirc_code);
        }

      condition = g_io_channel_get_buffer_condition (source);

      if (error_code == -1)
        {
          g_warning (G_STRLOC ": Error reading from source");
          success = FALSE;
        }
    }

  if (condition & G_IO_HUP)
    {
      g_warning (G_STRLOC ": Unexpected hang-up");
      success = FALSE;
    }

  if (condition & (G_IO_ERR | G_IO_NVAL))
    {
      g_warning (G_STRLOC ": Error or invalid request");
      success = FALSE;
    }

  if (condition & ~(G_IO_PRI | G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL))
    {
      g_warning ("Unexpected IO condition");
      success = FALSE;
    }

  return success;
}
Example #19
0
int main(int argc, char* argv[])
{
	char keyname[128];
	int pointer_button, pointer_x, pointer_y;
	char windowname[64];
	struct lirc_config* config;
	char* config_file = NULL;
	int c;
	unsigned int WindowID;

	while ((c = getopt_long(argc, argv, "dhV", long_options, NULL)) != EOF) {
		switch (c) {
		case 'd':
			bDaemon = 1;
			continue;
		case 'h':
			printf("Usage: %s [option]... [config file]\n"
			       "       -d --daemon     fork and run in background\n"
			       "       -h --help       display usage summary\n"
			       "       -V --version    display version\n", prog);
			return EXIT_SUCCESS;
		case 'V':
			printf("%s %s\n", prog, VERSION);
			return EXIT_SUCCESS;
		case '?':
			fprintf(stderr, "unrecognized option: -%c\n", optopt);
			fprintf(stderr, "Try `%s --help' for more information.\n", prog);
			return EXIT_FAILURE;
		}
	}

	if (argc == optind + 1) {
		config_file = argv[optind];
	} else if (argc > optind + 1) {
		fprintf(stderr, "%s: incorrect number of arguments.\n", prog);
		fprintf(stderr, "Try `%s --help' for more information.\n", prog);
		return EXIT_FAILURE;
	}

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL) {
		fprintf(stderr, "Can't open DISPLAY.\n");
		exit(1);
	}
	root = RootWindow(dpy, DefaultScreen(dpy));

	// windows may get closed at wrong time. Override default error handler...
	XSetErrorHandler(errorHandler);

	if (lirc_init("irxevent", 1) == -1)
		exit(EXIT_FAILURE);

	if (lirc_readconfig(config_file, &config, check) == 0) {
		char* ir;
		char* c;
		int ret;

		if (bDaemon) {
			if (daemon(1, 0) < 0) {
				perror("Failed to run as daemon");
				exit(EXIT_FAILURE);
			}
		}

		while (lirc_nextcode(&ir) == 0) {
			if (ir == NULL)
				continue;
			while ((ret = lirc_code2char(config, ir, &c)) == 0 && c != NULL) {
				log_debug("Received code: %s Sending:\n", ir);
				bInError = 0;   // reset error state, want to see error msg

				*windowname = 0;
				if (2 == sscanf(c, "Key %s Focus WindowID %i", keyname, &WindowID) ||
				    4 == sscanf(c, "Button %d %d %d Focus WindowID %i", &pointer_button, &pointer_x,
						&pointer_y, &WindowID)
				    || 4 == sscanf(c, "xy_Key %d %d %s Focus WindowID %i", &pointer_x, &pointer_y,
						   keyname, &WindowID)
				    || 2 == sscanf(c, "Key %s Focus %s", keyname, windowname)
				    || 4 == sscanf(c, "Button %d %d %d Focus %s", &pointer_button, &pointer_x,
						   &pointer_y, windowname)
				    || 4 == sscanf(c, "xy_Key %d %d %s Focus %s", &pointer_x, &pointer_y, keyname,
						   windowname)) {
					log_debug("Focus\n");
					/* focussed ? */
					if (*windowname) {
						WindowID = find_window_focused(root, windowname);
						if (!WindowID) {
							log_debug("target window '%s' doesn't have focus\n",
								  windowname);
							continue;
						}
						log_debug("focused:  %s\n", windowname);
					} else {
						Window cur;
						int tmp;

						XGetInputFocus(dpy, &cur, &tmp);
						if (WindowID != cur) {
							log_debug("target window '0x%x' doesn't have focus\n",
								  WindowID);
							continue;
						}
						log_debug("focused:  0x%x\n", WindowID);
					}
				} else if (2 == sscanf(c, "Key %s WindowID %i", keyname, &WindowID) ||
					   4 == sscanf(c, "Button %d %d %d WindowID %i", &pointer_button, &pointer_x,
						       &pointer_y, &WindowID)
					   || 4 == sscanf(c, "xy_Key %d %d %s WindowID %i", &pointer_x, &pointer_y,
							  keyname, &WindowID)) {
					log_debug("WindowID:  0x%x\n", WindowID);
					/* WindowID passed */
				} else if (2 == sscanf(c, "Key %s %s", keyname, windowname) ||
					   4 == sscanf(c, "Button %d %d %d %s", &pointer_button, &pointer_x, &pointer_y,
						       windowname)
					   || 4 == sscanf(c, "xy_Key %d %d %s %s\n", &pointer_x, &pointer_y, keyname,
							  windowname)) {
					log_debug("name: %s\n", windowname);
					WindowID = find_window(root, windowname);
					if (WindowID == 0) {
						log_debug("target window '%s' not found\n", windowname);
						continue;
					}
				}

				switch (c[0]) {
				case 'K':       // Key
					log_debug("keyname: %s \t WindowID: 0x%x\n", keyname, WindowID);
					log_debug("%s\n", c);
					sendkey(keyname, 1, 1, (Window)WindowID, 0);
					break;

				case 'B':       // Button
				case 'x':       // xy_Key
					subw = find_sub_window(root, windowname, &pointer_x, &pointer_y);
					if (subw) {
						if (WindowID == subw)
							subw = 0;
						log_debug("%s\n", c);
						switch (c[0]) {
						case 'B':
							/* FIXME: pointer_button potentially uninititalzed. */
							sendbutton(pointer_button, pointer_x, pointer_y, WindowID,
								   subw);
							break;
						case 'x':
							sendkey(keyname, pointer_x, pointer_y, WindowID, subw);
							break;
						}
					}
					break;
				}
			}
			free(ir);
			if (ret == -1)
				break;
		}
		lirc_freeconfig(config);
	}

	lirc_deinit();

	exit(0);
}
Example #20
0
static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) {
    struct userdata *u = userdata;
    char *name = NULL, *code = NULL;

    pa_assert(io);
    pa_assert(u);

    if (events & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) {
        pa_log("Lost connection to LIRC daemon.");
        goto fail;
    }

    if (events & PA_IO_EVENT_INPUT) {
        char *c;

        if (lirc_nextcode(&code) != 0 || !code) {
            pa_log("lirc_nextcode() failed.");
            goto fail;
        }

        c = pa_xstrdup(code);
        c[strcspn(c, "\n\r")] = 0;
        pa_log_debug("Raw IR code '%s'", c);
        pa_xfree(c);

        while (lirc_code2char(u->config, code, &name) == 0 && name) {
            enum {
                INVALID,
                UP,
                DOWN,
                MUTE,
                RESET,
                MUTE_TOGGLE
            } volchange = INVALID;

            pa_log_info("Translated IR code '%s'", name);

            if (strcasecmp(name, "volume-up") == 0)
                volchange = UP;
            else if (strcasecmp(name, "volume-down") == 0)
                volchange = DOWN;
            else if (strcasecmp(name, "mute") == 0)
                volchange = MUTE;
            else if (strcasecmp(name, "mute-toggle") == 0)
                volchange = MUTE_TOGGLE;
            else if (strcasecmp(name, "reset") == 0)
                volchange = RESET;

            if (volchange == INVALID)
                pa_log_warn("Received unknown IR code '%s'", name);
            else {
                pa_sink *s;

                if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK)))
                    pa_log("Failed to get sink '%s'", u->sink_name);
                else {
                    pa_cvolume cv = *pa_sink_get_volume(s, FALSE);

                    switch (volchange) {
                        case UP:
                            pa_cvolume_inc_clamp(&cv, u->volume_step, u->volume_limit);
                            pa_sink_set_volume(s, &cv, TRUE, TRUE);
                            break;

                        case DOWN:
                            pa_cvolume_dec(&cv, u->volume_step);
                            pa_sink_set_volume(s, &cv, TRUE, TRUE);
                            break;

                        case MUTE:
                            pa_sink_set_mute(s, TRUE, TRUE);
                            break;

                        case RESET:
                            pa_sink_set_mute(s, FALSE, TRUE);
                            break;

                        case MUTE_TOGGLE:
                            pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE), TRUE);
                            break;

                        case INVALID:
                            pa_assert_not_reached();
                    }
                }
            }
        }
    }

    pa_xfree(code);

    return;

fail:
    u->module->core->mainloop->io_free(u->io);
    u->io = NULL;

    pa_module_unload_request(u->module, TRUE);

    pa_xfree(code);
}
Example #21
0
static void copy_loop(int ptym, int ignoreeof)
{
	pid_t child;
	int nread;
	char buf[BUFFSIZE];
	struct sigaction act;
	struct pollfd pfd[2] = {
		{lsock, POLLIN, 0},
		{STDIN_FILENO, POLLIN, 0}
                // fd, events, revents
	};;

	if ((child = fork()) < 0) {
		die("fork error");
	} else if (!child) {

		while (1) {
			poll(pfd, 2, 0);

			if (pfd[1].revents & POLLIN) { /* STDIN_FILENO */
				if ((nread = read(STDIN_FILENO, buf, BUFFSIZE)) < 0)
					die("read error from stdin");
				else if (!nread)
					break;
				if (write(ptym, buf, nread) != nread)
					die("writen error to master pty");
			}
			if (pfd[0].revents & POLLIN) {  /*lsock */
				char* ir;
				char* irchars;
				int ret;

				while ((ret = lirc_nextcode(&ir)) == 0) {
					if (ir == NULL)
						break;
					while ((ret = lirc_code2char(lconfig, ir, &irchars)) == 0 && irchars != NULL)
						if (write(ptym, irchars, strlen(irchars)) != (int) strlen(irchars))
							die("writen error to master pty");
					free(ir);
					if (ret == -1)
						break;
				}
				if (ret == -1)
					break;
			}
		}
		if (!ignoreeof)
			kill(getppid(), SIGTERM);
		lirc_freeconfig(lconfig);
		lirc_deinit();
		_exit(0);
	}

	act.sa_handler = sig_term;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;       /* we need EINTR */
	sigaction(SIGTERM, &act, NULL);

	while (1) {
		if ((nread = read(ptym, buf, BUFFSIZE)) <= 0)
			break;
		if (write(STDOUT_FILENO, buf, nread) != nread)
			die("writen error to stdout");
	}
	if (!sigcaught)
		kill(child, SIGTERM);
	lirc_freeconfig(lconfig);
	lirc_deinit();
}
Example #22
0
int main(int argc, char *argv[])
{
  char keyname[128];
  int pointer_button,pointer_x,pointer_y;
  char windowname[64];
  struct lirc_config *config;

  progname=argv[0];
  if(argc>2)  {
    fprintf(stderr,"Usage: %s <config file>\n",argv[0]);
    exit(1);
  };

  dpy=XOpenDisplay(NULL);
  if(dpy==NULL) {
    fprintf(stderr,"Can't open DISPLAY.\n");
    exit(1);
  }
  root=RootWindow(dpy,DefaultScreen(dpy));

  if(lirc_init("irxevent",1)==-1) exit(EXIT_FAILURE);

  if(lirc_readconfig(argc==2 ? argv[1]:NULL,&config,check)==0)
    {
      char *ir;
      char *c;
      int ret;
      
      while(lirc_nextcode(&ir)==0)
	{
	  if(ir==NULL) continue;
	  while((ret=lirc_code2char(config,ir,&c))==0 && c!=NULL)
	    {
	      debugprintf("Recieved code: %sSending event: ",ir);
	      if(2==sscanf(c,"Key %s %s\n",keyname,windowname))
		{
		  if((w=find_window(root,windowname)))
		    {
		      debugprintf("keyname: %s \t windowname: %s\n",keyname,windowname);
		      sendkey(keyname,1,1,w,0);
		    }
		  else
		    {
		      debugprintf("target window '%s' not found \n",windowname);
		    }
		}
	      else if(4==sscanf(c,"Button %d %d %d %s\n",
				&pointer_button,&pointer_x,
				&pointer_y,windowname))
		{
		  
		  if((w=find_window(root,windowname)) &&
		     (subw=find_sub_window(root,windowname,&pointer_x,&pointer_y)))
		    {
		      if (w==subw) subw=0;
		      debugprintf(" %s\n",c);
		      sendbutton(pointer_button,pointer_x,pointer_y,w,subw);
		    }
		  else
		    {
		      debugprintf("target window '%s' not found \n",windowname);
		    }
		}
	      else if(4==sscanf(c,"xy_Key %d %d %s %s\n",
				&pointer_x,&pointer_y,
				keyname,windowname))
		{
		  
		  if((w=find_window(root,windowname))&& (subw=find_sub_window(root,windowname,&pointer_x,&pointer_y)))
		    {
		      debugprintf(" %s\n",c);
		      if (w==subw) subw=0;
		      sendkey(keyname,pointer_x,pointer_y,w,subw);
		    }
		  else
		    {
		      debugprintf("target window '%s' not found \n",windowname);
		    }
		}
	    }
	  free(ir);
	  if(ret==-1) break;
	}
      lirc_freeconfig(config);
    }
  
  lirc_deinit();
  
  exit(0);
}
Example #23
0
/*****************************************************************************
 * Run: main loop
 *****************************************************************************/
static void Run( intf_thread_t *p_intf )
{
    intf_sys_t *p_sys = p_intf->p_sys;

    for( ;; )
    {
        /* Wait for data */
        struct pollfd ufd = { .fd = p_sys->i_fd, .events = POLLIN, .revents = 0 };
        if( poll( &ufd, 1, -1 ) == -1 )
        {
            if( errno == EINTR )
                continue;
            else
                break;
        }

        /* Process */
        int canc = vlc_savecancel();
        Process( p_intf );
        vlc_restorecancel(canc);
    }
}

static void Process( intf_thread_t *p_intf )
{
    for( ;; )
    {
        char *code, *c;
        if( lirc_nextcode( &code ) )
            return;

        if( code == NULL )
            return;

        while( vlc_object_alive( p_intf )
                && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0)
                && (c != NULL) )
        {
            if( !strncmp( "key-", c, 4 ) )
            {
                vlc_action_t i_key = vlc_GetActionId( c );
                if( i_key )
                    var_SetInteger( p_intf->p_libvlc, "key-action", i_key );
                else
                    msg_Err( p_intf, "Unknown hotkey '%s'", c );
            }
            else if( !strncmp( "menu ", c, 5)  )
            {
                if( !strncmp( c, "menu on", 7 ) ||
                    !strncmp( c, "menu show", 9 ))
                    osd_MenuShow( VLC_OBJECT(p_intf) );
                else if( !strncmp( c, "menu off", 8 ) ||
                         !strncmp( c, "menu hide", 9 ) )
                    osd_MenuHide( VLC_OBJECT(p_intf) );
                else if( !strncmp( c, "menu up", 7 ) )
                    osd_MenuUp( VLC_OBJECT(p_intf) );
                else if( !strncmp( c, "menu down", 9 ) )
                    osd_MenuDown( VLC_OBJECT(p_intf) );
                else if( !strncmp( c, "menu left", 9 ) )
                    osd_MenuPrev( VLC_OBJECT(p_intf) );
                else if( !strncmp( c, "menu right", 10 ) )
                    osd_MenuNext( VLC_OBJECT(p_intf) );
                else if( !strncmp( c, "menu select", 11 ) )
                    osd_MenuActivate( VLC_OBJECT(p_intf) );
                else
                {
                    msg_Err( p_intf, "Please provide one of the following parameters:" );
                    msg_Err( p_intf, "[on|off|up|down|left|right|select]" );
                    break;
                }
            }
            else
            {
                msg_Err( p_intf, "this doesn't appear to be a valid keycombo "
                                 "lirc sent us. Please look at the "
                                 "doc/lirc/example.lirc file in VLC" );
                break;
            }
        }
        free( code );
    }
}
Example #24
0
static gboolean lirc_input_callback(GIOChannel *source, GIOCondition condition,
                                    gpointer data)
{
    LayoutWindow *lw = data;
    gchar *ptr;
    gint ret;
    gint x = 0;
    gint y = 0;

    /* LIRC code and corresponding geeqie command (and parameters)*/
    gchar *code;
    gchar *cmd;

    /* parameters for geeqie command */
    gint i_parm;
    gfloat fl_parm;

    while ((ret = lirc_nextcode(&code)) == 0 && code)
    {
        while ((ret = lirc_code2char(config, code, &cmd)) == 0 && cmd)
        {
            if (g_ascii_strncasecmp("LEFT", cmd, 4) == 0)
            {
                ptr = cmd + 4;
                while (g_ascii_isspace(*ptr)) ptr++;
                i_parm = atoi(ptr);

                if (i_parm <= 0) i_parm = 1;
                x -= i_parm;
            }
            else if (g_ascii_strncasecmp("RIGHT", cmd, 5) == 0)
            {
                ptr = cmd + 5;
                while (g_ascii_isspace(*ptr)) ptr++;
                i_parm = atoi(ptr);

                if (i_parm <= 0) i_parm = 1;
                x += i_parm;
            }
            else if (g_ascii_strncasecmp("UP", cmd, 2) == 0)
            {
                ptr = cmd + 2;
                while (g_ascii_isspace(*ptr)) ptr++;
                i_parm = atoi(ptr);

                if (i_parm <= 0) i_parm = 1;
                y -= i_parm;
            }
            else if (g_ascii_strncasecmp("DOWN", cmd, 4) == 0)
            {
                ptr = cmd + 4;
                while (g_ascii_isspace(*ptr)) ptr++;
                i_parm = atoi(ptr);

                if (i_parm <= 0) i_parm = 1;
                y += i_parm;
            }
            else if (g_ascii_strcasecmp("PREV", cmd) == 0)
            {
                layout_image_prev(lw);
            }
            else if (g_ascii_strcasecmp("NEXT", cmd) == 0)
            {
                layout_image_next(lw);
            }
            else if (g_ascii_strncasecmp("ZOOM_IN", cmd, 7) == 0)
            {
                ptr = cmd + 7;
                while (g_ascii_isspace(*ptr)) ptr++;
                fl_parm = atoi(ptr) / 10.0;

                if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
                layout_image_zoom_adjust(lw, fl_parm, FALSE);
            }
            else if (g_ascii_strncasecmp("ZOOM_OUT", cmd, 8) == 0)
            {
                ptr = cmd + 8;
                while (g_ascii_isspace(*ptr)) ptr++;
                fl_parm = atoi(ptr) / 10.0;

                if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
                layout_image_zoom_adjust(lw, -fl_parm, FALSE);
            }
            else if (g_ascii_strcasecmp("ZOOM_MAX", cmd) == 0)
            {
                layout_image_zoom_set(lw, 0.0, FALSE);
            }
            else if (g_ascii_strcasecmp("FULL_SCREEN", cmd) == 0)
            {
                layout_image_full_screen_toggle(lw);
            }
            else if (g_ascii_strncasecmp("SET_ZOOM", cmd, 8) == 0)
            {
                ptr = cmd + 8;
                while (g_ascii_isspace(*ptr)) ptr++;
                i_parm = atoi(ptr);

                if (i_parm <= 0) i_parm = 1;
                layout_image_zoom_set(lw, 1.0, FALSE);
            }
            else if (g_ascii_strncasecmp("SET_INV_ZOOM", cmd, 12) == 0)
            {
                ptr = cmd + 12;
                while (g_ascii_isspace(*ptr)) ptr++;
                i_parm = atoi(ptr);

                if (i_parm <= 0) i_parm = 1;
                layout_image_zoom_set(lw, -i_parm, FALSE);
            }
            else if (g_ascii_strcasecmp("FIRST", cmd) == 0)
            {
                layout_image_first(lw);
            }
            else if (g_ascii_strcasecmp("LAST", cmd) == 0)
            {
                layout_image_last(lw);
            }
            else if (g_ascii_strcasecmp("PAUSE", cmd) == 0)
            {
                layout_image_slideshow_pause_toggle(lw);
            }
            else if (g_ascii_strcasecmp("ROTATE_90", cmd) == 0)
            {
                layout_image_alter_orientation(lw, ALTER_ROTATE_90);
            }
            else if (g_ascii_strcasecmp("ROTATE_90_CC", cmd) == 0)
            {
                layout_image_alter_orientation(lw, ALTER_ROTATE_90_CC);
            }
            else if (g_ascii_strcasecmp("INFO", cmd) == 0)
            {
                layout_image_overlay_toggle(lw);
            }
            else if (g_ascii_strcasecmp("EXIT", cmd) == 0)
            {
                exit_program();
            }
        }
        free(code);
        if (ret == -1) break;
    }
    if (x != 0 || y != 0)
    {
        layout_image_scroll(lw, x, y, FALSE);
    }

    if (ret == -1)
    {
        /* something went badly wrong */
        g_fprintf(stderr, _("disconnected from LIRC\n"));
        lirc_cleanup();
        return (gboolean)FALSE;
    }
    return (gboolean)TRUE;
}
Example #25
0
/*****************************************************************************
 * Run: main loop
 *****************************************************************************/
static void Run( intf_thread_t *p_intf )
{
    char *code, *c;
    playlist_t *p_playlist;
    input_thread_t *p_input;
    vout_thread_t *p_vout = NULL;

    while( !p_intf->b_die )
    {
        /* Sleep a bit */
        msleep( INTF_IDLE_SLEEP );

        /* Update the input */
        if( p_intf->p_sys->p_input == NULL )
        {
            p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                              FIND_ANYWHERE );
        }
        else if( p_intf->p_sys->p_input->b_dead )
        {
            vlc_object_release( p_intf->p_sys->p_input );
            p_intf->p_sys->p_input = NULL;
        }
        p_input = p_intf->p_sys->p_input;

        /* Update the vout */
        if( p_vout == NULL )
        {
            p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                      FIND_ANYWHERE );
            p_intf->p_sys->p_vout = p_vout;
        }
        else if( p_vout->b_die )
        {
            vlc_object_release( p_vout );
            p_vout = NULL;
            p_intf->p_sys->p_vout = NULL;
        }

        /* We poll the lircsocket */
        if( lirc_nextcode(&code) != 0 )
        {
            break;
        }

        if( code == NULL )
        {
            continue;
        }

        while( !p_intf->b_die
                && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
                && c != NULL )
        {

            if( !strcmp( c, "QUIT" ) )
            {
                p_intf->p_vlc->b_die = VLC_TRUE;
                vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Quit" ) );
                continue;
            }
            else if( !strcmp( c, "VOL_UP" ) )
            {
                audio_volume_t i_newvol;
                aout_VolumeUp( p_intf, 1, &i_newvol );
                vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Vol %%%d"),
                                 i_newvol * 100 / AOUT_VOLUME_MAX );
            }
            else if( !strcmp( c, "VOL_DOWN" ) )
            {
                audio_volume_t i_newvol;
                aout_VolumeDown( p_intf, 1, &i_newvol );
                vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Vol %%%d"),
                                 i_newvol * 100 / AOUT_VOLUME_MAX );
            }
            else if( !strcmp( c, "MUTE" ) )
            {
                audio_volume_t i_newvol = -1;
                aout_VolumeMute( p_intf, &i_newvol );
                if( i_newvol == 0 )
                {
                    vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Mute" ) );
                }
                else
                {
                    vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Vol %d%%"),
                                     i_newvol * 100 / AOUT_VOLUME_MAX );
                }
            }
            if( p_vout )
            {
                if( !strcmp( c, "FULLSCREEN" ) )
                {
                    p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
                    continue;
                }
                if( !strcmp( c, "ACTIVATE" ) )
                {
                    vlc_value_t val;
                    val.psz_string = "ENTER";
                    if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
                    {
                        msg_Warn( p_intf, "key-press failed" );
                    }
                    continue;
                }

                if( !strcmp( c, "LEFT" ) )
                {
                    vlc_value_t val;
                    val.psz_string = "LEFT";
                    if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
                    {
                        msg_Warn( p_intf, "key-press failed" );
                    }
                    continue;
                }

                if( !strcmp( c, "RIGHT" ) )
                {
                    vlc_value_t val;
                    val.psz_string = "RIGHT";
                    if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
                    {
                        msg_Warn( p_intf, "key-press failed" );
                    }
                    continue;
                }

                if( !strcmp( c, "UP" ) )
                {
                    vlc_value_t val;
                    val.psz_string = "UP";
                    if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
                    {
                        msg_Warn( p_intf, "key-press failed" );
                    }
                    continue;
                }

                if( !strcmp( c, "DOWN" ) )
                {
                    vlc_value_t val;
                    val.psz_string = "DOWN";
                    if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
                    {
                        msg_Warn( p_intf, "key-press failed" );
                    }
                    continue;
                }
            }

            if( !strcmp( c, "PLAY" ) )
            {
                p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                              FIND_ANYWHERE );
                if( p_playlist )
                {
                    playlist_Play( p_playlist );
                    vlc_object_release( p_playlist );
                }
                continue;
            }

            if( !strcmp( c, "PLAYPAUSE" ) )
            {
                vlc_value_t val;
                val.i_int = PLAYING_S;
                if( p_input )
                {
                    var_Get( p_input, "state", &val );
                }
                if( p_input && val.i_int != PAUSE_S )
                {
                    vout_OSDMessage( VLC_OBJECT(p_intf), DEFAULT_CHAN,
                                     _( "Pause" ) );
                    val.i_int = PAUSE_S;
                    var_Set( p_input, "state", val );
                }
                else
                {
                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                  FIND_ANYWHERE );
                    if( p_playlist )
                    {
                        vlc_mutex_lock( &p_playlist->object_lock );
                        if( p_playlist->i_size )
                        {
                            vlc_mutex_unlock( &p_playlist->object_lock );
                            vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Play" ) );
                            playlist_Play( p_playlist );
                            vlc_object_release( p_playlist );
                        }
                    }
                }
                continue;
            }

            else if( p_input )
            {
                if( !strcmp( c, "AUDIO_TRACK" ) )
                {
                    vlc_value_t val, list, list2;
                    int i_count, i;
                    var_Get( p_input, "audio-es", &val );
                    var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
                                &list, &list2 );
                    i_count = list.p_list->i_count;
                    for( i = 0; i < i_count; i++ )
                    {
                        if( val.i_int == list.p_list->p_values[i].i_int )
                        {
                            break;
                        }
                    }
                    /* value of audio-es was not in choices list */
                    if( i == i_count )
                    {
                        msg_Warn( p_input,
                                  "invalid current audio track, selecting 0" );
                        var_Set( p_input, "audio-es",
                                 list.p_list->p_values[0] );
                        i = 0;
                    }
                    else if( i == i_count - 1 )
                    {
                        var_Set( p_input, "audio-es",
                                 list.p_list->p_values[0] );
                        i = 0;
                    }
                    else
                    {
                        var_Set( p_input, "audio-es",
                                 list.p_list->p_values[i+1] );
                        i++;
                    }
                    vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                     _("Audio track: %s"),
                                     list2.p_list->p_values[i].psz_string );
                }
                else if( !strcmp( c, "SUBTITLE_TRACK" ) )
                {
                    vlc_value_t val, list, list2;
                    int i_count, i;
                    var_Get( p_input, "spu-es", &val );
                    var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
                                &list, &list2 );
                    i_count = list.p_list->i_count;
                    for( i = 0; i < i_count; i++ )
                    {
                        if( val.i_int == list.p_list->p_values[i].i_int )
                        {
                            break;
                        }
                    }
                    /* value of audio-es was not in choices list */
                    if( i == i_count )
                    {
                        msg_Warn( p_input, "invalid current subtitle track, selecting 0" );
                        var_Set( p_input, "spu-es", list.p_list->p_values[0] );
                        i = 0;
                    }
                    else if( i == i_count - 1 )
                    {
                        var_Set( p_input, "spu-es", list.p_list->p_values[0] );
                        i = 0;
                    }
                    else
                    {
                        var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
                        i = i + 1;
                    }
                    vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                     _("Subtitle track: %s"),
                                     list2.p_list->p_values[i].psz_string );
                }
                else if( !strcmp( c, "PAUSE" ) )
                {
                    vlc_value_t val;
                    vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Pause" ) );
                    val.i_int = PAUSE_S;
                    var_Set( p_input, "state", val );
                }
                else if( !strcmp( c, "NEXT" ) )
                {
                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                          FIND_ANYWHERE );
                    if( p_playlist )
                    {
                        playlist_Next( p_playlist );
                        vlc_object_release( p_playlist );
                    }
                }
                else if( !strcmp( c, "PREV" ) )
                {
                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                          FIND_ANYWHERE );
                    if( p_playlist )
                    {
                        playlist_Prev( p_playlist );
                        vlc_object_release( p_playlist );
                    }
                }
                else if( !strcmp( c, "STOP" ) )
                {
                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                          FIND_ANYWHERE );
                    if( p_playlist )
                    {
                        playlist_Stop( p_playlist );
                        vlc_object_release( p_playlist );
                    }
                }
                else if( !strcmp( c, "FAST" ) )
                {
                    vlc_value_t val; val.b_bool = VLC_TRUE;
                    var_Set( p_input, "rate-faster", val );
                }
                else if( !strcmp( c, "SLOW" ) )
                {
                    vlc_value_t val; val.b_bool = VLC_TRUE;
                    var_Set( p_input, "rate-slower", val );
                }
/* beginning of modifications by stephane Thu Jun 19 15:29:49 CEST 2003 */
                else if ( !strcmp(c, "CHAPTER_N" ) ||
                          !strcmp( c, "CHAPTER_P" ) )
                {
                    unsigned int i_chapter = 0;

                    if( !strcmp( c, "CHAPTER_N" ) )
                    {
                        var_SetVoid( p_input, "next-chapter" );
                    }
                    else if( !strcmp( c, "CHAPTER_P" ) )
                    {
                        var_SetVoid( p_input, "prev-chapter" );
                    }
                }
/* end of modification by stephane Thu Jun 19 15:29:49 CEST 2003 */
            }
        }

        free( code );
    }
}
Example #26
0
static void copy_loop(int ptym, int ignoreeof)
{
	pid_t child;
	int nread;
	char buf[BUFFSIZE];
	struct sigaction act;

	if ((child = fork()) < 0) {
		die("fork error");
	} else if (!child) {
		fd_set fds;

		while (1) {
			FD_ZERO(&fds);
			FD_SET(lsock, &fds);
			FD_SET(STDIN_FILENO, &fds);
			select(lsock + 1, &fds, NULL, NULL, NULL);

			if (FD_ISSET(STDIN_FILENO, &fds)) {
				if ((nread = read(STDIN_FILENO, buf, BUFFSIZE)) < 0)
					die("read error from stdin");
				else if (!nread)
					break;
				if (write(ptym, buf, nread) != nread)
					die("writen error to master pty");
			}
			if (FD_ISSET(lsock, &fds)) {
				char* ir;
				char* irchars;
				int ret;

				while ((ret = lirc_nextcode(&ir)) == 0) {
					if (ir == NULL)
						break;
					while ((ret = lirc_code2char(lconfig, ir, &irchars)) == 0 && irchars != NULL)
						if (write(ptym, irchars, strlen(irchars)) != (int) strlen(irchars))
							die("writen error to master pty");
					free(ir);
					if (ret == -1)
						break;
				}
				if (ret == -1)
					break;
			}
		}
		if (!ignoreeof)
			kill(getppid(), SIGTERM);
		lirc_freeconfig(lconfig);
		lirc_deinit();
		_exit(0);
	}

	act.sa_handler = sig_term;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;       /* we need EINTR */
	sigaction(SIGTERM, &act, NULL);

	while (1) {
		if ((nread = read(ptym, buf, BUFFSIZE)) <= 0)
			break;
		if (write(STDOUT_FILENO, buf, nread) != nread)
			die("writen error to stdout");
	}
	if (!sigcaught)
		kill(child, SIGTERM);
	lirc_freeconfig(lconfig);
	lirc_deinit();
}
Example #27
0
static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition, void * data)
{
    char *code;
    char *c;
    gint playlist_time, playlist_pos, output_time, v;
    int ret;
    char *ptr;
    gint balance;
#if 0
    gboolean show_pl;
#endif
    int n;
    gchar *utf8_title_markup;

    while ((ret = lirc_nextcode (&code)) == 0 && code != NULL)
    {
        while ((ret = lirc_code2char (config, code, &c)) == 0 && c != NULL)
        {
            if (strcasecmp ("PLAY", c) == 0)
                aud_drct_play ();
            else if (strcasecmp ("STOP", c) == 0)
                aud_drct_stop ();
            else if (strcasecmp ("PAUSE", c) == 0)
                aud_drct_pause ();
            else if (strcasecmp ("PLAYPAUSE", c) == 0)
                aud_drct_play_pause ();
            else if (strncasecmp ("NEXT", c, 4) == 0)
            {
                ptr = c + 4;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);

                if (n <= 0)
                    n = 1;
                for (; n > 0; n--)
                {
                    aud_drct_pl_next ();
                }
            }
            else if (strncasecmp ("PREV", c, 4) == 0)
            {
                ptr = c + 4;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);

                if (n <= 0)
                    n = 1;
                for (; n > 0; n--)
                {
                    aud_drct_pl_prev ();
                }
            }
            else if (strcasecmp ("SHUFFLE", c) == 0)
                aud_set_bool (NULL, "shuffle", ! aud_get_bool (NULL, "shuffle"));
            else if (strcasecmp ("REPEAT", c) == 0)
                aud_set_bool (NULL, "repeat", ! aud_get_bool (NULL, "repeat"));
            else if (strncasecmp ("FWD", c, 3) == 0)
            {
                ptr = c + 3;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr) * 1000;

                if (n <= 0)
                    n = 5000;
                output_time = aud_drct_get_time ();

                int playlist = aud_playlist_get_active ();
                playlist_pos = aud_playlist_get_position (playlist);
                playlist_time =
                    aud_playlist_entry_get_length (playlist, playlist_pos,
                                                   FALSE);
                if (playlist_time - output_time < n)
                    output_time = playlist_time - n;
                aud_drct_seek (output_time + n);
            }
            else if (strncasecmp ("BWD", c, 3) == 0)
            {
                ptr = c + 3;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr) * 1000;

                if (n <= 0)
                    n = 5000;
                output_time = aud_drct_get_time ();
                if (output_time < n)
                    output_time = n;
                aud_drct_seek (output_time - n);
            }
            else if (strncasecmp ("VOL_UP", c, 6) == 0)
            {
                ptr = c + 6;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_main (&v);
                if (v > (100 - n))
                    v = 100 - n;
                aud_drct_set_volume_main (v + n);
            }
            else if (strncasecmp ("VOL_DOWN", c, 8) == 0)
            {
                ptr = c + 8;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_main (&v);
                if (v < n)
                    v = n;
                aud_drct_set_volume_main (v - n);
            }
            else if (strcasecmp ("QUIT", c) == 0)
            {
                aud_drct_quit ();
            }
            else if (strcasecmp ("MUTE", c) == 0)
            {
                if (mute == 0)
                {
                    mute = 1;
                    /* store the master volume so
                       we can restore it on unmute. */
                    aud_drct_get_volume_main (&mute_vol);
                    aud_drct_set_volume_main (0);
                }
                else
                {
                    mute = 0;
                    aud_drct_set_volume_main (mute_vol);
                }
            }
            else if (strncasecmp ("BAL_LEFT", c, 8) == 0)
            {
                ptr = c + 8;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_balance (&balance);
                balance -= n;
                if (balance < -100)
                    balance = -100;
                aud_drct_set_volume_balance (balance);
            }
            else if (strncasecmp ("BAL_RIGHT", c, 9) == 0)
            {
                ptr = c + 9;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_balance (&balance);
                balance += n;
                if (balance > 100)
                    balance = 100;
                aud_drct_set_volume_balance (balance);
            }
            else if (strcasecmp ("BAL_CENTER", c) == 0)
            {
                balance = 0;
                aud_drct_set_volume_balance (balance);
            }
            else if (strcasecmp ("LIST", c) == 0)
            {
#if 0
                show_pl = aud_drct_pl_win_is_visible ();
                show_pl = (show_pl) ? 0 : 1;
                aud_drct_pl_win_toggle (show_pl);
#endif
            }
            else if (strcasecmp ("PLAYLIST_CLEAR", c) == 0)
            {
                aud_drct_stop ();
                int playlist = aud_playlist_get_active ();
                aud_playlist_entry_delete (playlist, 0,
                                           aud_playlist_entry_count
                                           (playlist));
            }
            else if (strncasecmp ("PLAYLIST_ADD ", c, 13) == 0)
            {
                aud_drct_pl_add (c + 13, -1);
            }
            else if ((strlen (c) == 1) && ((*c >= '0') || (*c <= '9')))
            {
                if (track_no_pos < 63)
                {
                    if (tid)
                        g_source_remove (tid);
                    track_no[track_no_pos++] = *c;
                    track_no[track_no_pos] = 0;
                    tid = g_timeout_add (1500, jump_to, NULL);
                    utf8_title_markup = g_markup_printf_escaped ("%s", track_no);
                    hook_call ("aosd toggle", utf8_title_markup);
                }
            }
            else
            {
                fprintf (stderr, _("%s: unknown command \"%s\"\n"),
                         plugin_name, c);
            }
        }
        free (code);
        if (ret == -1)
            break;
    }
    if (ret == -1)
    {
        /* something went badly wrong */
        fprintf (stderr, _("%s: disconnected from LIRC\n"), plugin_name);
        cleanup ();
        if (aud_get_bool ("lirc", "enable_reconnect"))
        {
            int reconnect_timeout = aud_get_int ("lirc", "reconnect_timeout");
            fprintf (stderr,
                     _("%s: will try reconnect every %d seconds...\n"),
                     plugin_name, reconnect_timeout);
            g_timeout_add (1000 * reconnect_timeout, reconnect_lirc, NULL);
        }
    }

    return TRUE;
}