Update of /cvsroot/playerstage/code/player/libplayercore
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31036/libplayercore
Modified Files:
configfile.cc configfile.h drivertable.h interface_util.c
interface_util.h plugins.cc plugins.h
Log Message:
added geoff pluggable interface patch
Index: interface_util.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayercore/interface_util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** interface_util.c 20 May 2007 00:30:15 -0000 1.3
--- interface_util.c 21 May 2007 11:03:32 -0000 1.4
***************
*** 22,25 ****
--- 22,27 ----
#include <string.h>
+ #include <stdio.h>
+ #include <stdlib.h>
#include <libplayercore/player.h> // for interface constants
***************
*** 99,102 ****
--- 101,107 ----
};
+ static player_interface_t* itable;
+ static int itable_len;
+
/*
* A string table of the message types, used to print type strings in error
***************
*** 118,121 ****
--- 123,236 ----
/*
+ * Initialises the interface names/codes table.
+ */
+ int itable_init (void)
+ {
+ int ii;
+
+ for (itable_len = 0; interfaces[itable_len].interf; itable_len++);
+
+ if ((itable = (player_interface_t*) calloc (itable_len, sizeof
(player_interface_t))) == NULL)
+ {
+ printf ("itable_init: Failed to allocate memory for interface table\n");
+ return -1;
+ }
+
+ for (ii = 0; ii < itable_len; ii++)
+ {
+ itable[ii].interf = interfaces[ii].interf;
+ itable[ii].name = strdup (interfaces[ii].name);
+ }
+
+ return 0;
+ }
+
+ /*
+ * Grows the interface table to newSize, filling each interface between the
+ * old end and the new end with (0xFFFF, "nointerfXX").
+ */
+ int itable_grow (int newSize)
+ {
+ int ii;
+
+ if ((itable = (player_interface_t*) realloc (itable, (newSize * sizeof
(player_interface_t)))) == NULL)
+ {
+ printf("itable_grow: Failed to reallocate table memory\n");
+ return -1;
+ }
+ // Fill in from the old end to the new end with undefined interfaces
+ for (ii = itable_len; ii < newSize; ii++)
+ {
+ itable[ii].interf = 0xFFFF;
+ if ((itable[ii].name = (char*) malloc (12)) == NULL)
+ {
+ printf("itable_grow: Failed to allocate memory for name\n");
+ return -1;
+ }
+ snprintf (itable[ii].name, 12, "nointerf%d", ii);
+ }
+ // Set the new length
+ itable_len = newSize;
+ }
+
+ /*
+ * Destroys the interface names/codes table.
+ */
+ void itable_destroy (void)
+ {
+ int ii;
+
+ for (ii = 0; ii < itable_len; ii++)
+ {
+ if (itable[ii].name != NULL)
+ free (itable[ii].name);
+ }
+ free (itable);
+ }
+
+ /*
+ * Add a new interface to the interface table.
+ */
+ int itable_add (const char *name, int code, int replace)
+ {
+ if(code < itable_len)
+ {
+ // It's already in the table. Did the caller say to replace?
+ if(!replace)
+ {
+ // Nope; return an error
+ return(-1);
+ }
+ else
+ {
+ // Yes; replace
+ if ((itable[code].name = strdup (name)) == NULL)
+ {
+ printf("itable_add: Failed to allocate memory for name\n");
+ return -1;
+ }
+
+ return 0;
+ }
+ }
+ else
+ {
+ // Not in the table; add it
+ if (itable_grow (code + 1) < 0)
+ {
+ printf ("itable_add: Failed to grow interface table\n");
+ return -1;
+ }
+ itable[code].interf = code;
+ if ((itable[code].name = strdup (name)) == NULL)
+ {
+ printf("itable_add: Failed to allocate memory for name\n");
+ return -1;
+ }
+ return 0;
+ }
+ }
+
+ /*
* looks through the array of available interfaces for one which the given
* name. if found, interface is filled out (the caller must provide storage)
***************
*** 126,138 ****
{
int i;
! for(i=0; interfaces[i].interf; i++)
{
! if(!strcmp(name, interfaces[i].name))
{
! *interface = interfaces[i];
! return(0);
}
}
! return(-1);
}
--- 241,253 ----
{
int i;
! for(i=0; i<itable_len; i++)
{
! if(!strcmp(name, itable[i].name))
{
! *interface = itable[i];
! return 0;
}
}
! return -1;
}
***************
*** 146,158 ****
{
int i;
! for(i=0; interfaces[i].interf; i++)
{
! if(code == interfaces[i].interf)
{
! *interface = interfaces[i];
! return(0);
}
}
! return(-1);
}
--- 261,273 ----
{
int i;
! for(i=0; i<itable_len; i++)
{
! if(code == itable[i].interf)
{
! *interface = itable[i];
! return 0;
}
}
! return -1;
}
***************
*** 166,176 ****
{
int i;
! if(startpos > sizeof(interfaces))
return 0;
! for(i = startpos; interfaces[i].interf != 0; i++)
{
! if(code == interfaces[i].interf)
{
! return interfaces[i].name;
}
}
--- 281,291 ----
{
int i;
! if(startpos > itable_len)
return 0;
! for(i = startpos; i<itable_len; i++)
{
! if(code == itable[i].interf)
{
! return itable[i].name;
}
}
***************
*** 185,192 ****
{
// static char unknownstring[15];
! if (code < sizeof(interfaces))
{
! if (interfaces[code].interf != 0xFFFF)
! return interfaces[code].name;
}
// snprintf (unknownstring, 15, "unknown[%d]", code);
--- 300,307 ----
{
// static char unknownstring[15];
! if (code < itable_len)
{
! if (itable[code].interf != 0xFFFF)
! return itable[code].name;
}
// snprintf (unknownstring, 15, "unknown[%d]", code);
***************
*** 201,208 ****
{
unsigned int ii;
! for(ii=0; interfaces[ii].interf; ii++)
{
! if(!strcmp(name, interfaces[ii].name))
! return interfaces[ii].interf;
}
return 0xFFFF;
--- 316,323 ----
{
unsigned int ii;
! for(ii=0; ii<itable_len; ii++)
{
! if(!strcmp(name, itable[ii].name))
! return itable[ii].interf;
}
return 0xFFFF;
Index: plugins.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayercore/plugins.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** plugins.cc 18 Jan 2006 22:44:25 -0000 1.6
--- plugins.cc 21 May 2007 11:03:32 -0000 1.7
***************
*** 19,34 ****
*
*/
!
#if HAVE_CONFIG_H
#include <config.h>
#endif
! #if HAVE_LIBLTDL
! #include <ltdl.h>
! #endif
!
! #include <string.h>
! #include <stdlib.h>
! #include <unistd.h>
// Shouldn't really need this; <libplayercore/playercommon.h> includes
--- 19,30 ----
*
*/
!
#if HAVE_CONFIG_H
#include <config.h>
#endif
! #include <string.h>
! #include <stdlib.h>
! #include <unistd.h>
// Shouldn't really need this; <libplayercore/playercommon.h> includes
***************
*** 43,54 ****
#include <replace/replace.h>
// Try to load a given plugin, using a particular search algorithm.
// Returns true on success and false on failure.
! bool
LoadPlugin(const char* pluginname, const char* cfgfile)
{
#if HAVE_LIBLTDL
static int init_done = 0;
!
if( !init_done )
{
--- 39,52 ----
#include <replace/replace.h>
+ #include "plugins.h"
+
// Try to load a given plugin, using a particular search algorithm.
// Returns true on success and false on failure.
! lt_dlhandle
LoadPlugin(const char* pluginname, const char* cfgfile)
{
#if HAVE_LIBLTDL
static int init_done = 0;
!
if( !init_done )
{
***************
*** 58,69 ****
PLAYER_ERROR2( "Error(s) initializing dynamic loader (%d, %s)",
errors, lt_dlerror() );
! return false;
}
else
init_done = 1;
}
!
lt_dlhandle handle=NULL;
- PluginInitFn initfunc;
char fullpath[PATH_MAX] = {0};
char* playerpath;
--- 56,66 ----
PLAYER_ERROR2( "Error(s) initializing dynamic loader (%d, %s)",
errors, lt_dlerror() );
! return NULL;
}
else
init_done = 1;
}
!
lt_dlhandle handle=NULL;
char fullpath[PATH_MAX] = {0};
char* playerpath;
***************
*** 83,87 ****
{
PLAYER_MSG1(2, "failed (%s)\n", lt_dlerror() );
! return(false);
}
}
--- 80,84 ----
{
PLAYER_MSG1(2, "failed (%s)\n", lt_dlerror() );
! return NULL;
}
}
***************
*** 93,97 ****
{
PLAYER_MSG1(1,"PLAYERPATH: %s\n", playerpath);
!
// yep, now parse it, as a colon-separated list of directories
i=0;
--- 90,94 ----
{
PLAYER_MSG1(1,"PLAYERPATH: %s\n", playerpath);
!
// yep, now parse it, as a colon-separated list of directories
i=0;
***************
*** 112,116 ****
strcat(fullpath,pluginname);
! PLAYER_MSG1(1, "trying to load %s...", fullpath);
if((handle = lt_dlopenext(fullpath)))
--- 109,113 ----
strcat(fullpath,pluginname);
! PLAYER_MSG1(1, "trying to load %s...", fullpath);
if((handle = lt_dlopenext(fullpath)))
***************
*** 126,130 ****
}
}
!
// try to load it from the directory where the config file is
if(!handle && cfgfile)
--- 123,127 ----
}
}
!
// try to load it from the directory where the config file is
if(!handle && cfgfile)
***************
*** 182,198 ****
{
PLAYER_ERROR1("error loading plugin: %s", pluginname);
! return false;
}
!
! // Now invoke the initialization function
if(handle)
{
PLAYER_MSG0(1, "invoking player_driver_init()...");
! initfunc = (PluginInitFn)lt_dlsym(handle,"player_driver_init");
if( !initfunc )
{
! PLAYER_ERROR1("failed to resolve player_driver_init: %s\n",
! lt_dlerror() );
return(false);
}
--- 179,208 ----
{
PLAYER_ERROR1("error loading plugin: %s", pluginname);
! return NULL;
}
!
! return handle;
!
! #else
! PLAYER_ERROR("Sorry, no support for shared libraries, so can't load
plugins.");
! PLAYER_ERROR("You should install libltdl, which is part of GNU libtool,
then re-compile player.");
! return 0;
! #endif
! }
!
! // Initialise a driver plugin
! bool InitDriverPlugin(lt_dlhandle handle)
! {
! #if HAVE_LIBLTDL
! DriverPluginInitFn initfunc;
! // Invoke the initialization function
if(handle)
{
PLAYER_MSG0(1, "invoking player_driver_init()...");
! initfunc = (DriverPluginInitFn)lt_dlsym(handle,"player_driver_init");
if( !initfunc )
{
! PLAYER_ERROR1("failed to resolve player_driver_init: %s\n",
lt_dlerror());
return(false);
}
***************
*** 201,206 ****
if( (initfunc_result = (*initfunc)(driverTable)) != 0)
{
! PLAYER_ERROR1("error returned by player_driver_init: %d",
! initfunc_result );
return(false);
}
--- 211,215 ----
if( (initfunc_result = (*initfunc)(driverTable)) != 0)
{
! PLAYER_ERROR1("error returned by player_driver_init: %d",
initfunc_result);
return(false);
}
***************
*** 212,222 ****
else
return(false);
-
#else
PLAYER_ERROR("Sorry, no support for shared libraries, so can't load
plugins.");
PLAYER_ERROR("You should install libltdl, which is part of GNU libtool,
then re-compile player.");
! return false;
#endif
}
--- 221,266 ----
else
return(false);
#else
PLAYER_ERROR("Sorry, no support for shared libraries, so can't load
plugins.");
PLAYER_ERROR("You should install libltdl, which is part of GNU libtool,
then re-compile player.");
! return(false);
#endif
}
+ // Initialise an interface plugin
+ playerxdr_function_t* InitInterfacePlugin(lt_dlhandle handle)
+ {
+ #if HAVE_LIBLTDL
+ InterfPluginInitFn initfunc;
+ playerxdr_function_t *flist;
+ // Invoke the initialization function
+ if(handle)
+ {
+ PLAYER_MSG0(1, "invoking player_plugininterf_gettable()...");
+
+ initfunc =
(InterfPluginInitFn)lt_dlsym(handle,"player_plugininterf_gettable");
+ if( !initfunc )
+ {
+ PLAYER_ERROR1("failed to resolve player_plugininterf_gettable: %s\n",
lt_dlerror());
+ return(NULL);
+ }
+
+ if( (flist = (*initfunc)()) == NULL)
+ {
+ PLAYER_ERROR("player_plugininterf_gettable returned NULL");
+ return(NULL);
+ }
+
+ PLAYER_MSG0(1, "success");
+
+ return(flist);
+ }
+ else
+ return(NULL);
+ #else
+ PLAYER_ERROR("Sorry, no support for shared libraries, so can't load
plugins.");
+ PLAYER_ERROR("You should install libltdl, which is part of GNU libtool,
then re-compile player.");
+ return(NULL);
+ #endif
+ }
Index: drivertable.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayercore/drivertable.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** drivertable.h 15 Nov 2005 01:14:57 -0000 1.2
--- drivertable.h 21 May 2007 11:03:32 -0000 1.3
***************
*** 42,47 ****
typedef Driver* (*DriverInitFn) (ConfigFile *cf, int section);
! /// @brief Function signature for plugin initialization functions
! typedef int (*PluginInitFn) (DriverTable* table);
--- 42,47 ----
typedef Driver* (*DriverInitFn) (ConfigFile *cf, int section);
! /// @brief Function signature for driver plugin initialization functions
! typedef int (*DriverPluginInitFn) (DriverTable* table);
Index: interface_util.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayercore/interface_util.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** interface_util.h 14 Mar 2007 16:41:51 -0000 1.5
--- interface_util.h 21 May 2007 11:03:32 -0000 1.6
***************
*** 34,41 ****
{
uint16_t interf;
! const char* name;
} player_interface_t;
/*
* looks through the array of available interfaces for one which the given
* name. if found, interface is filled out (the caller must provide storage)
--- 34,62 ----
{
uint16_t interf;
! char* name;
} player_interface_t;
/*
+ * Initialises the interface names/codes table.
+ */
+ int itable_init (void);
+
+ /*
+ * Grows the interface table to newSize, filling each interface between the
+ * old end and the new end with (0xFFFF, "nointerfXX").
+ */
+ int itable_grow (int newSize);
+
+ /*
+ * Destroys the interface names/codes table.
+ */
+ void itable_destroy (void);
+
+ /*
+ * Add a new interface to the interface table.
+ */
+ int itable_add (const char *name, int code, int replace);
+
+ /*
* looks through the array of available interfaces for one which the given
* name. if found, interface is filled out (the caller must provide storage)
Index: configfile.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayercore/configfile.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** configfile.h 2 May 2006 21:25:53 -0000 1.10
--- configfile.h 21 May 2007 11:03:32 -0000 1.11
***************
*** 430,436 ****
--- 430,442 ----
public: bool ParseDriver(int section);
+ // Parse an interface block, and update the interface systems accordingly
+ public: bool ParseInterface(int section);
+
// Parse all driver blocks
public: bool ParseAllDrivers();
+ // Parse all interface blocks
+ public: bool ParseAllInterfaces();
+
/// @brief Get the number of sections.
public: int GetSectionCount();
Index: plugins.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayercore/plugins.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** plugins.h 24 May 2005 22:41:56 -0000 1.1
--- plugins.h 21 May 2007 11:03:32 -0000 1.2
***************
*** 20,23 ****
*/
! bool LoadPlugin(const char* pluginname, const char* cfgfile);
--- 20,37 ----
*/
! #if HAVE_LIBLTDL
! #include <ltdl.h>
! #else
! #define lt_dlhandle int
! #endif
!
! #include <libplayerxdr/functiontable.h>
+ /// @brief Function signature for interface plugin initialization functions
+ typedef playerxdr_function_t* (*InterfPluginInitFn) (void);
+
+ lt_dlhandle LoadPlugin(const char* pluginname, const char* cfgfile);
+
+ bool InitDriverPlugin(lt_dlhandle handle);
+
+ playerxdr_function_t* InitInterfacePlugin(lt_dlhandle handle);
Index: configfile.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayercore/configfile.cc,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** configfile.cc 2 May 2006 20:44:09 -0000 1.14
--- configfile.cc 21 May 2007 11:03:32 -0000 1.15
***************
*** 48,51 ****
--- 48,52 ----
#include <libplayercore/plugins.h>
#include <libplayercore/addr_util.h>
+ #include <libplayerxdr/functiontable.h>
//extern int global_playerport;
***************
*** 2058,2061 ****
--- 2059,2063 ----
Device *device;
int count;
+ lt_dlhandle handle;
entry = NULL;
***************
*** 2066,2074 ****
if (pluginname != NULL)
{
! if(!LoadPlugin(pluginname,this->filename))
{
PLAYER_ERROR1("failed to load plugin: %s", pluginname);
return (false);
}
}
--- 2068,2081 ----
if (pluginname != NULL)
{
! if((handle = LoadPlugin(pluginname,this->filename)) == NULL)
{
PLAYER_ERROR1("failed to load plugin: %s", pluginname);
return (false);
}
+ if(!InitDriverPlugin(handle))
+ {
+ PLAYER_ERROR1("failed to initialise plugin: %s", pluginname);
+ return (false);
+ }
}
***************
*** 2132,2134 ****
--- 2139,2224 ----
}
+ // Parse all interface blocks
+ bool
+ ConfigFile::ParseAllInterfaces()
+ {
+ for(int i = 1; i < this->GetSectionCount(); i++)
+ {
+ // Check for new-style device block
+ if(strcmp(this->GetSectionType(i), "interface") == 0)
+ {
+ if(!this->ParseInterface(i))
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Parse an interface block, and update the interface systems accordingly
+ bool
+ ConfigFile::ParseInterface(int section)
+ {
+ const char *pluginname;
+ const char *interfacename;
+ int interfacecode;
+ int replace;
+ lt_dlhandle handle;
+ playerxdr_function_t *flist;
+
+ // Check if this interface is replacing an existing one's messages
+ replace = this->ReadInt(section, "replace", 0);
+
+ // Get the interface name
+ interfacename = this->ReadString(section, "name", NULL);
+ if (interfacename == NULL)
+ {
+ PLAYER_ERROR1("No interface name specified in section %d", section);
+ return false;
+ }
+
+ // Get the interface code
+ interfacecode = this->ReadInt(section, "code", -1);
+ if (interfacecode == -1)
+ {
+ PLAYER_ERROR1("No interface code specified in section %d", section);
+ return false;
+ }
+
+ // Find the plugin name
+ pluginname = this->ReadString(section, "plugin", NULL);
+ if (pluginname == NULL)
+ {
+ PLAYER_ERROR1("No plugin name specified for plugin interface in section
%d", section);
+ return false;
+ }
+
+ // Load the plugin
+ if((handle = LoadPlugin(pluginname,this->filename)) == NULL)
+ {
+ PLAYER_ERROR1("failed to load plugin: %s", pluginname);
+ return false;
+ }
+
+ // Get the function table list
+ if((flist = InitInterfacePlugin(handle)) == NULL)
+ {
+ PLAYER_ERROR1("failed to initialise plugin: %s", pluginname);
+ return false;
+ }
+ // Add the function table list
+ if(playerxdr_ftable_add_multi(flist, replace) < 0)
+ {
+ PLAYER_ERROR1("Failed to add interface functions for plugin interface
%s", interfacename);
+ return false;
+ }
+
+ // Add the interface name to the interface names table
+ if(itable_add (interfacename, interfacecode, replace) < 0)
+ {
+ PLAYER_ERROR2("Failed to add interface name/code: %s/%d", interfacename,
interfacecode);
+ return false;
+ }
+
+ return true;
+ }
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit