SASC
DVBSoftCAM

plugin_dummy.c

Go to the documentation of this file.
00001 /*
00002    DVBLoopback - plugin_dummy.c
00003    Copyright Alan Nisota 2006
00004 
00005    This file is part of DVBLoopback.
00006 
00007     DVBLoopback is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     DVBLoopback is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with DVBLoopback; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 */
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <fcntl.h>
00024 #include <pthread.h>
00025 #include <sys/mman.h>
00026 #include <sys/poll.h>
00027 #include <sys/ioctl.h>
00028 #include <signal.h>
00029 #include <string.h>
00030 #include <getopt.h>
00031 #include <unistd.h>
00032 #include <errno.h>
00033 #include "list.h"
00034 
00035 // Header Needed for Demuxer
00036 #include <linux/dvb/dmx.h>
00037 
00038 // Header Needed for Frontend
00039 #include <linux/dvb/frontend.h>
00040 
00041 // YOU MUST INCLUDE THIS
00042 //
00043 // Provides Structs for parser commands
00044 #include "process_req.h"
00045 
00046 // YOU MUST INCLUDE THIS
00047 //
00048 // Provides Structs for message passing
00049 #include "msg_passing.h"
00050 
00051 // Define your plugin load order here
00052 //
00053 // Must be even, < 32, >= 8, and unique (total of 12 plugins allowed currently)
00054 #define PLUGIN_ID 16
00055 #include "debug.h" //This is required to happen AFTER PLUGIN_ID is defined
00056 
00057 /* LongOpt Array 
00058  *
00059  * option constructor: String name, int has_arg, StringBuffer flag, int val
00060  *
00061  *      name    - The long option String. 
00062  *      has_arg - Indicates whether the option has no argument (NO_ARGUMENT) 0, a 
00063  *                required argument (REQUIRED_ARGUMENT) 1 or an optional argument 
00064  *                (OPTIONAL_ARGUMENT) 2. 
00065  *      flag    - If non-null, this is a location to store the value of "val" 
00066  *                when this option is encountered, otherwise "val" is treated 
00067  *                as the equivalent short option character. 
00068  *      val     - The value to return for this long option, or the equivalent 
00069  *                single letter option to emulate if flag is null.
00070  *
00071  * MUST BE TERMINATED WITH {0,0,0,0} (Null Option?)
00072  */
00073 
00074 static int dummy_value = 0;
00075 static struct option Dummy_Opts[] = {
00076   {"dummy-param", 2, &dummy_value, 'd'},
00077   {0, 0, 0, 0},
00078 };
00079 
00080 static void connect_dummy(struct parser_adpt *pc_all)
00081 {
00082   printf("Connect Called\n");
00083 }
00084 
00085 static struct option *parseopt_dummy(arg_enum_t cmd)
00086 {
00087   if(cmd == ARG_INIT) {
00088     return Dummy_Opts;
00089   } 
00090   if(cmd == ARG_HELP) {
00091     printf("   --dummy-param <adapter number> :\n");
00092   } 
00093   if(! dummy_value)
00094     return NULL;
00095 
00096   switch(dummy_value) {
00097     case 'd':
00098       if(optarg){
00099         printf("Attaching to adapter%i\n", atoi(optarg));
00100       }
00101       break;
00102   }
00103   //must reset dummy_value after every call
00104   dummy_value = 0;
00105   return NULL;
00106 }
00107 
00108 /* struct plugin_cmd is used to pass information about this plugin to the main loop
00109    
00110    plugin_cmd struct is defined as:
00111   
00112    struct plugin_cmd {
00113      struct list_head list;
00114      int plugin;
00115      struct option * (*parse_args)(arg_enum_t);
00116      void (*connect)(struct parser_adpt *);
00117      void (*launch)();
00118      void (*message)(struct msg *, unsigned int priority);
00119      void (*send_msg)(struct parser_cmds *pc, int msg);
00120      void (*shutdown)();
00121    };
00122 
00123    'list' and 'plugin' MUST be initialized properly (see below) but all others
00124    may be set to 'NULL' when that feature is not required.
00125   
00126    ---
00127    struct list_head list;
00128 
00129    Any structure which is used as a list must have 'struct list_head list;' as
00130    the first element.  This will be managed by the list-handling functions, so
00131    just initialize it to '{NULL, NULL}'.  there should never be a need to work
00132    with the elements of a list, since the functions and macros do that for you.
00133 
00134 
00135    ---
00136    int plugin;
00137 
00138    'plugin' is the identifier for this plugin.  It should be unique compared to
00139    any other plugins used.  Other plugins can pass messages to this one by
00140    specifying this identifier
00141    
00142    ---
00143    struct option * (*parse_args)(arg_enum_t);
00144 
00145    function which deals with option parsing.  It should behave as follows:
00146      when arg_enum_t is 'ARG_INIT' returns a pointer to the parameter structure
00147      when arg_enum_t is 'ARG_HELP' displays a help message describing cmdline
00148           arguments
00149      in all other cases, check the cmdline variable and process arguments as
00150           needed
00151 
00152    ---
00153 
00154    void (*connect)(struct parser_adpt *);
00155 
00156    connect will be called once for each adapter that is being used. (So if 3
00157    cards are used, 'connect' will be called 3 times each time with a different
00158    parser_adpt parameter.
00159    All device-level initialization should be done here.
00160 
00161    parser_adpt is defined as:
00162 
00163    struct parser_adpt {
00164      struct parser_cmds *frontend;
00165      struct parser_cmds *demux;
00166      struct parser_cmds *dvr;
00167      struct parser_cmds *ca;
00168    };
00169 
00170    each element of parser_adpt supplies information about a given device
00171 
00172   struct parser_cmds {
00173     int type;
00174     pthread_t thread;
00175     struct common_data *common;
00176     struct list_head pre_open;
00177     struct list_head post_open;
00178     struct list_head pre_close;
00179     struct list_head post_close;
00180     struct list_head pre_read;
00181     struct list_head post_read;
00182     struct list_head pre_poll;
00183     struct list_head post_poll;
00184     struct list_head pre_ioctl;
00185     struct list_head post_ioctl;
00186     unsigned char *mmap;
00187     ...
00188   }
00189 
00190   type is the type of device defined in this structure.  It will be one of:
00191     DVB_DEVICE_FRONTEND, DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, -1
00192 
00193   thread is the processing thread handling this device.  Plugins should not
00194     normally need to access this parameter
00195 
00196   common contains information common to all devices on the current adapter.
00197     This should primarily be used to determine the adapter number
00198 
00199   all of the pre/post lists contain commands to be executed before/after
00200   receiving a query for the given syscall.
00201   normally inside the 'connect' function a plugin would do something like:
00202     struct cmd_list *fe_postioctl = register_cmd(fe_tune);
00203     list_add_tail(&fe_postioctl->list, &pc_all->frontend->post_ioctl); 
00204 
00205     which indicates that the 'fe_tune' function inside the current plugin will
00206     be called after an ioctl has been processed (this could be used to post-
00207     process the output of an ioctl from the 'real' card)
00208 
00209   mmap conatins a pointer that is mmaped to the virtual device (but only for the
00210     dvr device).  It will contain the results of a 'read' in the case of
00211     a post_read callback, or can be filled in by the plugin during a pre_read
00212     call instead of allowing a read from the real card to happen.
00213 
00214   the parser_cmds struct contains additional elements, but these should be
00215     ignored by plugins
00216 
00217   ---
00218   void (*launch)();
00219 
00220   launch is called once all plugins have gone through 'connect' for all adapters
00221   it is often used to spawn processing threads needed by the plugins
00222 
00223   ---
00224   void (*message)(struct msg *, unsigned int priority);
00225 
00226   message is used to receive a message from another plugin
00227 
00228 
00229   ---
00230   void (*send_msg)(struct parser_cmds *pc, int msg);
00231 
00232   send_msg is used to tell this plugin that another plugin is expecting to
00233     receive messages from this one.  Normally this just indicates that the current
00234     plugin should broadcast messages.
00235 
00236   ---
00237   void (*shutdown)();
00238 
00239   shutdown is called to try to cleanup gracefully before exitiong
00240 */ 
00241 
00242 static struct plugin_cmd plugin_cmds = {{NULL, NULL}, PLUGIN_ID, "dummy",
00243                      parseopt_dummy, connect_dummy, NULL, NULL, NULL, NULL, NULL};
00244 int __attribute__((constructor)) __dummy_init(void)
00245 {
00246   // communicates the existance of teh current plugin to the main program.
00247   list_add(&plugin_cmds.list, &plugin_cmdlist);
00248   return 0;
00249 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines