Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

lirc.c

00001 /*****************************************************************************
00002  * lirc.c : lirc module for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2003-2005 the VideoLAN team
00005  * $Id: lirc.c 12836 2005-10-15 13:23:08Z sigmunau $
00006  *
00007  * Author: Sigmund Augdal Helberg <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <string.h>
00029 
00030 #include <fcntl.h>
00031 
00032 #include <vlc/vlc.h>
00033 #include <vlc/intf.h>
00034 
00035 #include <lirc/lirc_client.h>
00036 
00037 /*****************************************************************************
00038  * intf_sys_t: description and status of FB interface
00039  *****************************************************************************/
00040 struct intf_sys_t
00041 {
00042     struct lirc_config *config;
00043 };
00044 
00045 /*****************************************************************************
00046  * Local prototypes
00047  *****************************************************************************/
00048 static int  Open    ( vlc_object_t * );
00049 static void Close   ( vlc_object_t * );
00050 static void Run     ( intf_thread_t * );
00051 
00052 /*****************************************************************************
00053  * Module descriptor
00054  *****************************************************************************/
00055 vlc_module_begin();
00056     set_category( CAT_INTERFACE );
00057     set_subcategory( SUBCAT_INTERFACE_CONTROL );
00058     set_description( _("Infrared remote control interface") );
00059     set_capability( "interface", 0 );
00060     set_callbacks( Open, Close );
00061 vlc_module_end();
00062 
00063 /*****************************************************************************
00064  * Open: initialize interface
00065  *****************************************************************************/
00066 static int Open( vlc_object_t *p_this )
00067 {
00068     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00069     int i_fd;
00070 
00071     /* Allocate instance and initialize some members */
00072     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
00073     if( p_intf->p_sys == NULL )
00074     {
00075         msg_Err( p_intf, "out of memory" );
00076         return 1;
00077     }
00078 
00079     p_intf->pf_run = Run;
00080 
00081     i_fd = lirc_init( "vlc", 1 );
00082     if( i_fd == -1 )
00083     {
00084         msg_Err( p_intf, "lirc_init failed" );
00085         free( p_intf->p_sys );
00086         return 1;
00087     }
00088 
00089     /* We want polling */
00090     fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
00091 
00092     if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
00093     {
00094         msg_Err( p_intf, "lirc_readconfig failed" );
00095         lirc_deinit();
00096         free( p_intf->p_sys );
00097         return 1;
00098     }
00099 
00100     return 0;
00101 }
00102 
00103 /*****************************************************************************
00104  * Close: destroy interface
00105  *****************************************************************************/
00106 static void Close( vlc_object_t *p_this )
00107 {
00108     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00109 
00110     /* Destroy structure */
00111     lirc_freeconfig( p_intf->p_sys->config );
00112     lirc_deinit();
00113     free( p_intf->p_sys );
00114 }
00115 
00116 /*****************************************************************************
00117  * Run: main loop
00118  *****************************************************************************/
00119 static void Run( intf_thread_t *p_intf )
00120 {
00121     char *code, *c;
00122 
00123     while( !p_intf->b_die )
00124     {
00125         /* Sleep a bit */
00126         msleep( INTF_IDLE_SLEEP );
00127 
00128         /* We poll the lircsocket */
00129         if( lirc_nextcode(&code) != 0 )
00130         {
00131             break;
00132         }
00133 
00134         if( code == NULL )
00135         {
00136             continue;
00137         }
00138 
00139         while( !p_intf->b_die
00140                 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
00141                 && c != NULL )
00142         {
00143             vlc_value_t keyval;
00144 
00145             if( strncmp( "key-", c, 4 ) )
00146             {
00147                 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" );
00148                 break;
00149             }
00150             keyval.i_int = config_GetInt( p_intf, c );
00151             var_Set( p_intf->p_vlc, "key-pressed", keyval );
00152         }
00153         free( code );
00154     }
00155 }
00156 

Generated on Tue Dec 20 10:14:31 2005 for vlc-0.8.4a by  doxygen 1.4.2