Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -1,6 +1,6 @@ -CPPFLAGS := -I. -DUSE_TCL_STUBS=1 -DXVFS_MODE=standalone +CPPFLAGS := -I. -DUSE_TCL_STUBS=1 -DXVFS_MODE_STANDALONE CFLAGS := -fPIC -g3 -ggdb3 -Wall LDFLAGS := LIBS := -ltclstub8.6 all: example.so Index: xvfs-core.c ================================================================== --- xvfs-core.c +++ xvfs-core.c @@ -1,9 +1,10 @@ #include #include #include +#if defined(XVFS_MODE_SERVER) || defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE) #define XVFS_ROOT_MOUNTPOINT "//xvfs:/" struct xvfs_tclfs_instance_info { struct Xvfs_FSInfo *fsInfo; Tcl_Obj *mountpoint; @@ -74,12 +75,13 @@ pathStr = xvfs_relativePath(path, instanceInfo); fprintf(stderr, "Called open(%s)!\n", pathStr); return(NULL); } +#endif /* XVFS_MODE_SERVER || XVFS_MODE_STANDALONE || XVFS_MODE_FLEIXBLE */ -#if XVFS_MODE == standalone +#if defined(XVFS_MODE_STANDALONE) /* * Tcl_Filesystem handlers for the standalone implementation */ static struct xvfs_tclfs_instance_info xvfs_tclfs_standalone_info; static int xvfs_tclfs_standalone_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr) { @@ -141,11 +143,11 @@ Tcl_SetResult(interp, "Unable to allocate Tcl_Filesystem object", NULL); } return(TCL_ERROR); } - xvfs_tclfs_Info->typeName = strdup("xvfs"); + xvfs_tclfs_Info->typeName = "xvfs"; xvfs_tclfs_Info->structureLength = sizeof(*xvfs_tclfs_Info); xvfs_tclfs_Info->version = TCL_FILESYSTEM_VERSION_1; xvfs_tclfs_Info->pathInFilesystemProc = xvfs_tclfs_standalone_pathInFilesystem; xvfs_tclfs_Info->dupInternalRepProc = NULL; xvfs_tclfs_Info->freeInternalRepProc = NULL; @@ -188,10 +190,12 @@ return(tcl_ret); } return(TCL_OK); } -#else +#endif + +#if defined(XVFS_MODE_SERVER) int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) { return(TCL_ERROR); } #endif Index: xvfs-core.h ================================================================== --- xvfs-core.h +++ xvfs-core.h @@ -1,7 +1,7 @@ -#ifndef XVFS_COMMON_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 -#define XVFS_COMMON_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 1 +#ifndef XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 +#define XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 1 #include #define XVFS_PROTOCOL_VERSION 1 @@ -15,12 +15,48 @@ xvfs_proc_getChildren_t getChildrenProc; xvfs_proc_getData_t getDataProc; xvfs_proc_getInfo_t getInfoProc; }; -#if XVFS_MODE == standalone -#define Xvfs_Register(interp, fsInfo) xvfs_standalone_register(interp, fsInfo) +#define XVFS_REGISTER_INTERFACE(name) int name(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo); + +#if defined(XVFS_MODE_STANDALONE) +/* + * In standalone mode, we just redefine calls to + * Xvfs_Register() to go to the xvfs_standalone_register() + * function + */ +# define Xvfs_Register xvfs_standalone_register +XVFS_REGISTER_INTERFACE(Xvfs_Register) + +#elif defined(XVFS_MODE_FLEXIBLE) +/* + * In flexible mode we declare an external symbol named + * Xvfs_Register(), as well as an internal symbol called + * xvfs_flexible_register(), which we redefine future + * calls to Xvfs_Register() to invoke + */ +extern XVFS_REGISTER_INTERFACE(Xvfs_Register) +# define Xvfs_Register xvfs_flexible_register +XVFS_REGISTER_INTERFACE(Xvfs_Register) + +#elif defined(XVFS_MODE_CLIENT) +/* + * In client mode we declare an external symbol named + * Xvfs_Register() that must be provided by the environment + * we are loaded into + */ +extern XVFS_REGISTER_INTERFACE(Xvfs_Register) + +#elif defined(XVFS_MODE_SERVER) +/* + * In server mode we are going to implementing Xvfs_Register() + * for flexible/client modes, just forward declare it + */ +XVFS_REGISTER_INTERFACE(Xvfs_Register) + +#else +# error Unsupported XVFS_MODE #endif -int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo); #endif