Пример #1
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;
}
Пример #2
0
Файл: lirc.c Проект: 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 );
    }
}
Пример #3
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);
        }
    }
}
Пример #4
0
void CLirc::Process()
{
  m_profileId = CServiceBroker::GetProfileManager().GetCurrentProfileId();
  m_irTranslator.Load("Lircmap.xml");

  // make sure work-around (CheckDaemon) uses the same socket path as lirc_init
  const char* socket_path = getenv("LIRC_SOCKET_PATH");
  socket_path = socket_path ? socket_path : "/var/run/lirc/lircd";
  setenv("LIRC_SOCKET_PATH", socket_path, 0);

  while (!m_bStop)
  {
    {
      CSingleLock lock(m_critSection);

      // lirc_client is buggy because it does not close socket, if connect fails
      // work around by checking if daemon is running before calling lirc_init
      if (!CheckDaemon())
      {
        CSingleExit lock(m_critSection);
        Sleep(1000);
        continue;
      }

      m_fd = lirc_init(const_cast<char*>("kodi"), 0);
      if (m_fd <= 0)
      {
        CSingleExit lock(m_critSection);
        Sleep(1000);
        continue;
      }
    }

    char *code;
    while (!m_bStop)
    {
      int ret = lirc_nextcode(&code);
      if (ret < 0)
      {
        lirc_deinit();
        Sleep(1000);
        break;
      }
      if (code != nullptr)
      {
        if (m_profileId != CServiceBroker::GetProfileManager().GetCurrentProfileId())
        {
          m_profileId = CServiceBroker::GetProfileManager().GetCurrentProfileId();
          m_irTranslator.Load("Lircmap.xml");
        }
        ProcessCode(code);
        free(code);
      }
    }
  }

  lirc_deinit();
}
Пример #5
0
int
main (int argc, const char *argv[]) {
  int fd;
  struct lirc_config *config;
  char *code;

  if ((fd = lirc_init("lirc", 1)) == -1) {
    fprintf(stderr, "cannot init lirc\n");
    exit(EXIT_FAILURE);
  }

  fprintf(stdout, "LIRC FD = %d\n", fd);
  fflush(stdout);

#if 0 // XXX test non-block socket (for integration with tcdr)
  if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) == -1) {
    fprintf(stderr, "cannot make socket as non block\n");
    exit(EXIT_FAILURE);
  }
#endif

  if (lirc_readconfig(NULL, &config, NULL) == 0) {
    while (lirc_nextcode(&code) == 0) {
      if (!code)
        continue;

      if (strstr(code, "KEY_MENU")) {
        fprintf(stdout, "MENU\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_PLAYPAUSE")) {
        fprintf(stdout, "PLAY\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_FORWARD")) {
        fprintf(stdout, "FWRD\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_REWIND")) {
        fprintf(stdout, "RWND\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_VOLUMEUP")) {
        fprintf(stdout, "VLUP\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_VOLUMEDOWN")) {
        fprintf(stdout, "VLDN\n");
        fflush(stdout);
      } else {
        fprintf(stderr, "UNKN\n");
      }

      free(code);
    }

    lirc_freeconfig(config);
  }

  lirc_deinit();
  
  return 0;
}
Пример #6
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;
}
Пример #7
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;
}
Пример #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;

}
Пример #9
0
char *lirc_nextir(struct lirc_state *state)
{
	static int warning=1;
	char *code;
	int ret;
	
	if(warning)
	{
		fprintf(stderr,"%s: warning: lirc_nextir() is obsolete\n",
			state->lirc_prog);
		warning=0;
	}
	ret=lirc_nextcode(state, &code);
	if(ret==-1) return(NULL);
	return(code);
}
/**
 * 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;
}
Пример #11
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;
}
Пример #12
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;
    }
}
Пример #13
0
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;
}
Пример #14
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;
}
Пример #15
0
Файл: lirc.cpp Проект: 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."));
        }
    }
}
Пример #16
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 );
    }
}
Пример #17
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;
}
Пример #18
0
/* This is our thread function.  It is like main(), but for a thread*/
void *threadFunc(void *arg)
{
    struct lirc_config *config;
    int buttonTimer = millis();

    char *code;
    char *c;

    //Initiate LIRC. Exit on failure
    if(lirc_init("lirc",1)==-1)
        exit(EXIT_FAILURE);

    //Read the default LIRC config at /etc/lirc/lircd.conf This is the config for your remot$
    if(lirc_readconfig(NULL,&config,NULL)==0)
    {
        //Do stuff while LIRC socket is open 0=open -1=closed.
        while(lirc_nextcode(&code)==0)
        {
            //If code = NULL, meaning nothing was returned from LIRC socket,
            //then skip lines below and start while loop again.
            if(code==NULL) continue;
            {
                if (millis() - buttonTimer  > 400) {
                    //Check to see if the string "KEY_#" appears anywhere within the string $
                    if(strstr (code,"KEY_F")) {
                        printf("MATCH on KEY_F\n");
                        sLED(0,200,0,0);
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_G")) {
                        printf("MATCH on KEY_G\n");
                        MODE = 2;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_H")) {
                        printf("MATCH on KEY_H\n");
                        MODE = 1;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_E")) {
                        printf("MATCH on KEY_E\n");
                        sLED(0,0,100,0);
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_A")) {
                        printf("MATCH on KEY_A\n");
                        sLED(0,0,0,0);
                        buttonTimer = millis();
                    }

                }
            }
            //Need to free up code before the next loop
            free(code);
        }
        //Frees the data structures associated with config.
        lirc_freeconfig(config);
    }
    //lirc_deinit() closes the connection to lircd and does some internal clean-up stuff.
    lirc_deinit();
    //exit(EXIT_SUCCESS);
    return NULL;
}
Пример #19
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;
}
Пример #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);
}
Пример #21
0
void master_irda::run()
{

    c_irda_logic irda_queue(my_data2);
    //Read the default LIRC config at /etc/lirc/lircd.conf  This is the config for your remote.
    if(lirc_readconfig(NULL,&config,NULL)==0)
    {
        // std::cout << " jestem w iflirc_readconfig(NULL,&config,NULL)==0 \n ";
        //Do stuff while LIRC socket is open  0=open  -1=closed.
        while(lirc_nextcode(&code)==0 )
        {
            std::cout << " w while \n";
            if (go_while==false)     /// TO NIE DZIALA DO POPRAWY
            {
                break;  // koncze petle zamykam wątek
            }
            //If code = NULL, meaning nothing was returned from LIRC socket,
            //then skip lines below and start while loop again.
            if(code==NULL) {
                std::cout << " kontynuuje\n";
                continue;}
            {
                //Make sure there is a 400ms gap before detecting button presses.
                if (millis() - buttonTimer  > 400 ){

                    digitalWrite(BUZZER,ON);

                    // time out   OK menu
                    if (millis() - buttonTimer  > 30000 && buttonMENU == 1){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " timeout menu " <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        buttonMENU=0;  // flaga na 0  nie wejdze juz do timeout
                        irda_queue._add('e');
                    }
                    //////////////////////////////////////////////////////////////
                    //Check to see if the string "KEY_1" appears anywhere within the string 'code'.

                    if(strstr (code,"KEY_POWER")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " wcisnieto POWER" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('P');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_1")){
                        irda_queue._add('1');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_2")){
                        irda_queue._add('2');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_3")){
                        irda_queue._add('3');
                        //my_data2->mainLCD->printString(1,1,"klawisz 3");
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_4")){
                        irda_queue._add('4');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_5")){
                        irda_queue._add('5');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_6")){
                        irda_queue._add('6');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_7")){
                        irda_queue._add('7');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_8")){
                        irda_queue._add('8');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_9")){
                        irda_queue._add('9');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_0")){
                        irda_queue._add('0');
                        buttonTimer = millis();
                    }
                    ////////////////////////////////////
                    else if(strstr (code,"KEY_INFO")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " operacja na diodzie" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('I');
                        buttonTimer = millis();
                    }
                    /////////////////////////////////////////////////
                    else if(strstr (code,"KEY_TV")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " wcisnieto PLAY" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('t');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_AUDIO")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " wcisnieto PAUSE" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('A');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_VOLUMEUP")){
                        irda_queue._add('+');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_VOLUMEDOWN")){
                        irda_queue._add('-');
                        buttonTimer = millis();
                    }
                    /////////////////////////////////////////////

                    else if(strstr (code,"KEY_DOWN")){
                        irda_queue._add('D');
                        buttonTimer = millis();
                    }

                    else if(strstr (code,"KEY_UP")){
                        irda_queue._add('U');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_OK")){
                        irda_queue._add('O');
                        buttonMENU=0;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_MENU")){
                        irda_queue._add('M');
                        buttonMENU=1;// wlacz timeout dla menu
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_EXIT")){
                        irda_queue._add('e');
                        buttonMENU = 0;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_RADIO")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " sterowanie projektorem" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('r');   //idziemy do sterowania projektorem
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_EPG")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " przegladanie katalogu z filmami" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        buttonMENU=1;
                        irda_queue._add('E');   //idziemy do sterowania projektorem
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_CHANNELUP")){

                        irda_queue._add('^');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_CHANNELDOWN")){

                        irda_queue._add('/');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_MUTE")){
                        irda_queue._add('m');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_FAVORITES")){
                        irda_queue._add('F');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_REFRESH")){
                        irda_queue._add('R');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_LANGUAGE")){
                        irda_queue._add('L');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_SUBTITLE")){
                        irda_queue._add('S');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_SAT")){
                        irda_queue._add('s');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_TEXT")){
                        irda_queue._add('T');
                        buttonTimer = millis();
                    }
                }
            }
            //Need to free up code before the next loop
            free(code);

            digitalWrite(BUZZER,OFF);
        }
        //Frees the data structures associated with config.
        lirc_freeconfig(config);
    }
    log_file_mutex.mutex_lock();
    log_file_cout << INFO << " koniec watku master IRDA  "<<   std::endl;
    log_file_mutex.mutex_unlock();


    //lirc_deinit() closes the connection to lircd and does some internal clean-up stuff.
    lirc_deinit();
    // exit(EXIT_SUCCESS);


}
Пример #22
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);
}
//Main function
int main(int argc, char* argv[])
{
    //LIRC Variables
    struct lirc_config *config;

    //HTTP Variables
    char *host = "10.0.0.2";
    char *http_request_format = "POST /php/remote_control_api.php HTTP/1.1\n"
                                "Host: 10.0.0.2\n"
                                "Content-Type: application/x-www-form-urlencoded\n"
                                "Content-Length: 10\n\n"
                                "function=%s\n";
    char http_request[MAX_HTTP_REQUEST_LEN];
    char http_response[MAX_HTTP_RESPONSE_LEN];

    //Socket Variables
    int sockfd, error;
    struct addrinfo hints, *addrinfo_list, *addrinfo;

    //Misc Variables
    int valid_key = 0;
    struct timeval tv;
    gettimeofday(&tv, NULL);
    time_t start_time = tv.tv_sec, end_time, time_delay;

    //Outputs usage and exits if given more than one file path in arguments
    if (argc>2)
    {
        fprintf(stderr, "Usage: %s <config file>\n", argv[0]);
        return -1;
    }

    //Initializes LIRC and exits if unsuccessful, called at start of execution
    if (lirc_init("lirc",1)==-1)
    {
        fprintf(stderr, "lirc_init: failed to initialize lirc\n");
        return -1;
    }

    //Clears hints structure and set appropriately for call to getaddrinfo()
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    //Gets the linked list of possible addrinfo structures
    if (error = getaddrinfo(host, PORT, &hints, &addrinfo_list) != 0)
    {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
        return -1;
    }

    //Iterate through linked list of possible addrinfo structures and attempts to create socket to connect to
    for (addrinfo = addrinfo_list; addrinfo != NULL; addrinfo = addrinfo->ai_next)
    {
        //Creates a socket
        if ((sockfd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) == -1)
        {
            continue;
        }

        //Connect to socket
        if (connect(sockfd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1)
        {
            close(sockfd);
            continue;
        }

        //Break out of loop if calls to socket() and connect() are both successful
        break;
    }

    //If none of the addrinfo structures in the linked list works, then exit program
    if (addrinfo == NULL)
    {
        fprintf(stderr, "failed to connect to %s\n", host);
        return -1;
    }

    fprintf(stdout, "connection to %s was successful\n\n", host);

    close(sockfd);

    //Read in configuration file from either argument or default path
    if (lirc_readconfig(argc==2 ? argv[1]:NULL, &config, NULL) == 0)
    {
        char *code; //Used to store the key code of the remote

        //Blocks the program until an IR signal is recieved from key press
        while (lirc_nextcode(&code)==0)
        {
            //Handle logic key press, if any
            if (code==NULL) continue;
            {
                gettimeofday(&tv, NULL);
                end_time = tv.tv_sec;
                printf("Starttime=%ld\tEndtime=%ld\n\n", start_time, end_time);
                if (end_time - start_time > DELAY)
                {
                    //Clears request and response buffer
                    memset(&http_request, 0, sizeof http_request);
                    memset(&http_response, 0, sizeof http_response);

                    if (strstr(code,"KEY_POWER"))
                    {
                        if ((valid_key = handle_key_power(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_STOP"))
                    {
                        if ((valid_key = handle_key_stop(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_PAUSE"))
                    {
                        if ((valid_key = handle_key_pause(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_PLAY"))
                    {
                        if ((valid_key = handle_key_play(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_REWIND"))
                    {
                        if ((valid_key = handle_key_rewind(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_FORWARD"))
                    {
                        if ((valid_key = handle_key_forward(http_request, http_request_format)) == -1) { return -1; }
                    }

                    if (valid_key)
                    {
                        //Creates socket
                        if ((sockfd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) == -1)
                        {
                            return -1;
                        }

                        //Connect to socket
                        if (connect(sockfd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1)
                        {
                            close(sockfd);
                            return -1;
                        }

                        if (send_http_request(sockfd, http_request) == -1)
                        {
                            fprintf(stderr, "An error has occur while sending the HTTP request\n");
                        }
                        else
                        {
                            fprintf(stdout, "HTTP request has been sent successfully.\n"
                                            "--------------------------------------------------\n"
                                            "%s\n\n", http_request);
                        }

                        if (receive_http_response(sockfd, http_response) == -1)
                        {
                            fprintf(stderr, "An error has occur while receiving the HTTP response\n");
                        }
                        else
                        {
                            fprintf(stdout, "HTTP response has been received successfully.\n"
                                            "--------------------------------------------------\n"
                                            "%s\n\n", http_response);
                        }

                        close(sockfd);
                    }
                    gettimeofday(&tv, NULL);
                    start_time = tv.tv_sec;
                }
            }
            free(code); //Free allocated memory for code after key press is handled
        }
        lirc_freeconfig(config); //Free allocated memory for configuration structure
    }

    //Deallocate memory from linked list of addrinfo structures
    freeaddrinfo(addrinfo_list);

    lirc_deinit(); //Deinitializes LIRC, called at end of program execution

    return 0; //EXIT_SUCCESS
} //end of main()
Пример #24
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();
}
Пример #25
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);
}
Пример #26
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 );
    }
}
Пример #27
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;
}
Пример #28
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 );
    }
}
Пример #29
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();
}
Пример #30
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;
}