Update of /cvsroot/anet/ANet/ANet_Daemon/Core
In directory usw-pr-cvs1:/tmp/cvs-serv1025/Core
Added Files:
IMC.c ModuleLoader.c StubModule.c
Log Message:
""
--- NEW FILE: IMC.c ---
#include "Modules.h"
#include "IMC.h"
#include "StubModule.h"
ANetMemoryTag currentGlobals;
UInt32 CallModuleFunction(char *moduleName, char *instanceName,
UInt32 funcID, ...)
{
//find the instance in the hash
//use the module info in the list to find the
// function pointer
//set up currentGlobals (store previous value in a
// *local* variable, set up new value)
//call the function using the arguments
//restore previous value of currentGlobals
//return module function's returned value
}
ANetMemoryTag ANetGetGlobals()
{
return currentGlobals;
}
--- NEW FILE: ModuleLoader.c ---
#include "Modules.h"
#include "IMC.h" //inter-module communication
#include "StubModule.h"
// define some list of ANetModuleInfo here
// also define some hash of (moduleName,instanceName) -> ANetMemoryTag here
void Test()
{
LoadModules();
CreateInstance("StubModule", "Stub1");
CreateInstance("StubModule", "Stub2");
CallModuleFunction("StubModule", "Stub1", kStubMain, 10);
}
void LoadModules()
{
LoadInternalModule(StubModuleLoad);
}
void CreateInstance(char *moduleName, char *instanceName)
{
//store info in hash
//call the module's ANetModuleCreateInstanceFuncPtr
//store the instance's globals (g) in hash
}
void LoadInternalModule(ANetModuleLoadFuncPtr func)
{
//call func
//store info in list
}
--- NEW FILE: StubModule.c ---
#include <iostream.h>
#include "Modules.h"
#include "IMC.h"
#include "StubModule.h"
#include "XMLCommon.h"
// for now, assume that ANetMemoryTag is an int
// This is called when the module is loaded
UInt32 StubModuleLoad(ANetModuleInfo *modInfo)
{
ANetAddModuleName(modInfo, "StubModule");
ANetFunctionMap newInstance = {"StubCreate", kModuleCreateInstance,
StubCreate};
ANetFunctionMap main = {"StubMain", kStubMain, StubMain};
ANetFunctionMap func1 = {"StubFunc1", kStubFunc1, StubFunc1};
ANetFunctionMap func2 = {"StubFunc2", kStubFunc2, StubFunc2};
ANetAddFunctionMap(modInfo, newInstance);
ANetAddFunctionMap(modInfo, main);
ANetAddFunctionMap(modInfo, func1);
ANetAddFunctionMap(modInfo, func2);
return 0;
}
// This is called when a new instance is created
UInt32 StubCreate(ANetTagID tag, ANetMemoryTag *g)
{
*g = random() % 30;
return 0;
}
UInt32 StubMain(UInt32 val)
{
printf("MAIN: Argument value: %d\n", val);
printf("MAIN: Global value: %d\n", ANetGetGlobals());
printf("Calling my func1...\n");
StubFunc1(val);
return 0;
}
UInt32 StubFunc1(UInt32 val)
{
printf("FUNC1: Argument value: %d\n", val);
printf("FUNC1: Global value: %d\n", ANetGetGlobals());
printf("Calling Stub2's Func2 with our global as argument...\n");
CallModuleFunction("StubModule", "Stub2", kStubFunc2,
ANetGetGlobals());
printf("FUNC1: Global value: %d\n", ANetGetGlobals());
return 0;
}
UInt32 StubFunc2(UInt32 val)
{
printf("FUNC2: Argument value: %d\n", val);
printf("FUNC2: Global value: %d\n", ANetGetGlobals());
return 0;
}
|