Kernel - Cleaning up messages
[tpg/acess2.git] / Kernel / modules.c
index 58521ba..786d409 100644 (file)
 #define        USE_UDI 0
 
 // === PROTOTYPES ===
- int   Module_int_Initialise(tModule *Module, char *ArgString);
+ int   Module_int_Initialise(tModule *Module, const char *ArgString);
+void   Modules_int_GetBuiltinArray(void);
 void   Modules_LoadBuiltins(void);
-void   Modules_SetBuiltinParams(char *Name, char *ArgString);
- int   Module_RegisterLoader(tModuleLoader *Loader);
- int   Module_LoadMem(void *Buffer, Uint Length, char *ArgString);
- int   Module_LoadFile(char *Path, char *ArgString);
+void   Modules_SetBuiltinParams(const char *Name, char *ArgString);
+ int   Modules_InitialiseBuiltin(const char *Name);
+// int Module_RegisterLoader(tModuleLoader *Loader);
+// int Module_LoadMem(void *Buffer, Uint Length, char *ArgString);
+// int Module_LoadFile(char *Path, char *ArgString);
  int   Module_int_ResolveDeps(tModule *Info);
  int   Module_IsLoaded(const char *Name);
+// int Module_EnsureLoaded(const char *Name);
 
 // === EXPORTS ===
 EXPORT(Module_RegisterLoader);
@@ -26,9 +29,9 @@ EXPORT(Module_RegisterLoader);
 #if USE_UDI
 extern int     UDI_LoadDriver(void *Base);
 #endif
-extern void    StartupPrint(char *Str);
-extern void    gKernelModules;
-extern void    gKernelModulesEnd;
+extern void    StartupPrint(const char *Str);
+extern tModule gKernelModules;
+extern tModule gKernelModulesEnd;
 
 // === GLOBALS ===
  int   giNumBuiltinModules = 0;
@@ -50,11 +53,11 @@ char        **gasBuiltinModuleArgs;
  * \retval 0   Returned on success
  * \retval >0  Error code form the module's initialisation function
  */
-int Module_int_Initialise(tModule *Module, char *ArgString)
+int Module_int_Initialise(tModule *Module, const char *ArgString)
 {
         int    i, j;
         int    ret;
-       char    **deps;
+       const char      **deps;
        char    **args;
        tModule *mod;
        
@@ -282,7 +285,7 @@ int Modules_InitialiseBuiltin(const char *Name)
 /**
  * \brief Sets the parameters for a builtin module
  */
-void Modules_SetBuiltinParams(char *Name, char *ArgString)
+void Modules_SetBuiltinParams(const char *Name, char *ArgString)
 {
         int    i;
        
@@ -321,7 +324,7 @@ int Module_RegisterLoader(tModuleLoader *Loader)
  * \fn int Module_LoadMem(void *Buffer, Uint Length, char *ArgString)
  * \brief Load a module from a memory location
  */
-int Module_LoadMem(void *Buffer, Uint Length, char *ArgString)
+int Module_LoadMem(void *Buffer, Uint Length, const char *ArgString)
 {
        char    path[VFS_MEMPATH_SIZE];
        
@@ -331,10 +334,10 @@ int Module_LoadMem(void *Buffer, Uint Length, char *ArgString)
 }
 
 /**
- * \fn int Module_LoadFile(char *Path, char *ArgString)
+ * \fn int Module_LoadFile(const char *Path, const char *ArgString)
  * \brief Load a module from a file
  */
-int Module_LoadFile(char *Path, char *ArgString)
+int Module_LoadFile(const char *Path, const char *ArgString)
 {
        void    *base;
        tModule *info;
@@ -395,7 +398,7 @@ int Module_LoadFile(char *Path, char *ArgString)
  */
 int Module_int_ResolveDeps(tModule *Info)
 {
-       char    **names = Info->Dependencies;
+       const char      **names = Info->Dependencies;
        
        // Walk dependencies array
        for( ; *names; names++ )
@@ -428,3 +431,19 @@ int Module_IsLoaded(const char *Name)
        // not found - return false
        return 0;
 }
+
+/**
+ * \brief Load a module if needed
+ */
+int Module_EnsureLoaded(const char *Name)
+{
+       if( Module_IsLoaded(Name) )
+               return 0;
+
+       if( Modules_InitialiseBuiltin(Name) == 0 )
+               return 0;
+
+       // TODO: Load from a file?
+
+       return -1;
+}

UCC git Repository :: git.ucc.asn.au