#include <serverbase.h>

Public Member Functions | |
| ServerBase (SERVER_ID srvID, MODULE_INSTANCE_ID instOffset=0) | |
| Class constructor. | |
| virtual | ~ServerBase () |
| Class destructor. | |
| bool | GetModules (ModuleList *moduleList, const wxString &moduleName, MODULE_INSTANCE_ID instanceID=MODULE_INSTANCE_ID_NONE) |
| std::vector< wxFileName > | GetAvailableModules () |
| Get filenames of available (instantiated or not) modules. | |
| virtual size_t | AddAvailableModules (const wxString &pathToModules) |
| Update lists of currently available modules. | |
| SERVER_ID | GetID () const |
| Get server ID. | |
Protected Member Functions | |
| std::vector< MODULE_HANDLE_ID > | findModuleHandles (const wxString &name) |
| ModuleHandle< T > * | getModuleHandle (MODULE_HANDLE_ID id) const |
| Get module handle of given id. | |
| MODULE_ID | createPreferedModuleInstance () |
| Create new module instance only if prefered module found (Kernel::preferedModules). | |
| MODULE_ID | createModuleInstance (const wxString libName=wxT("*")) |
| T * | getModule (const MODULE_ID &moduleID) const |
| Get module. | |
| void | releaseModule (const MODULE_ID &id) |
| Release given module. | |
| void | releaseModules () |
| Release all loaded modules. | |
Protected Attributes | |
| SERVER_ID | serverID |
| Server type ID. | |
| MODULE_INSTANCE_ID | instanceOffset |
| Instance offset - all module instance IDs will start from it. | |
Private Types | |
| typedef std::vector < ModuleHandle< T > * > | ModuleHandleList |
Private Attributes | |
| ModuleHandleList | moduleHandles |
| List of available scene import/export modules. | |
Friends | |
| class | Kernel |
Definition at line 26 of file serverbase.h.
typedef std::vector<ModuleHandle<T> *> VRUT::ServerBase< T >::ModuleHandleList [private] |
Definition at line 29 of file serverbase.h.
| VRUT::ServerBase< T >::ServerBase | ( | SERVER_ID | srvID, | |
| MODULE_INSTANCE_ID | instOffset = 0 | |||
| ) | [inline] |
Class constructor.
Definition at line 85 of file serverbase.h.
00086 : serverID(srvID), instanceOffset(instOffset) 00087 { 00088 }
| VRUT::ServerBase< T >::~ServerBase | ( | ) | [inline, virtual] |
Class destructor.
Definition at line 92 of file serverbase.h.
00093 { 00094 releaseModules(); 00095 }
| std::vector< MODULE_HANDLE_ID > VRUT::ServerBase< T >::findModuleHandles | ( | const wxString & | name | ) | [inline, protected] |
Find module handles with library filename matching name (supports '*' and '?'), case insensitive Does not update available modules by calling AddAvailableModules
Definition at line 99 of file serverbase.h.
00100 { 00101 wxString nameU = name.Upper(); 00102 #ifdef __WXDEBUG__ 00103 if (!nameU.EndsWith(wxT("_D"))) 00104 nameU.Append(wxT("_D")); 00105 #endif 00106 std::vector<MODULE_HANDLE_ID> foundHandles; 00107 for (MODULE_HANDLE_ID i = 0; i < moduleHandles.size(); i++) 00108 { 00109 const wxString modName = moduleHandles[i]->GetFileName().GetName().Upper(); 00110 if (modName.Matches(nameU) || modName.Matches(wxT("LIB") + nameU)) 00111 foundHandles.push_back(i); 00112 } 00113 return foundHandles; 00114 }
| ModuleHandle< T > * VRUT::ServerBase< T >::getModuleHandle | ( | MODULE_HANDLE_ID | id | ) | const [inline, protected] |
Get module handle of given id.
Definition at line 118 of file serverbase.h.
00119 { 00120 return ( index >= moduleHandles.size() ? (ModuleHandle<T> *)NULL : moduleHandles[index] ); 00121 }
| MODULE_ID VRUT::ServerBase< T >::createPreferedModuleInstance | ( | ) | [inline, protected] |
Create new module instance only if prefered module found (Kernel::preferedModules).
Definition at line 125 of file serverbase.h.
00126 { 00127 AddAvailableModules(MODULE_PATHS[serverID]); 00128 const Kernel::ModuleNamesList * preferedModules = KERNEL->GetPreferedModules(); 00129 for (Kernel::ModuleNamesList::const_iterator nameIt = preferedModules->begin(); 00130 nameIt != preferedModules->end(); nameIt++) 00131 { 00132 wxString lookForName = nameIt->Upper(); 00133 for (typename ModuleHandleList::iterator it = moduleHandles.begin(); 00134 it != moduleHandles.end(); it++) 00135 { 00136 wxString libName = (*it)->GetFileName().GetName(); 00137 if (libName.Upper().Matches(wxString::Format(wxT("*%s*"), lookForName.c_str()))) 00138 { 00139 MODULE_INSTANCE_ID modInstID = (*it)->InstantiateModule(); 00140 if (modInstID != MODULE_INSTANCE_ID_NONE) 00141 return MODULE_ID(serverID, (*it)->GetID(), modInstID); 00142 else 00143 { 00144 LOGWARNING(wxString::Format(wxT("%sPreffered module '%s' is invalid, adding to forbidden list"), 00145 SERVER_CLASS_NAMES[serverID].c_str(), libName.c_str())); 00146 KERNEL->ForbidModule(libName); 00147 } 00148 } 00149 } 00150 } 00151 00152 return MODULE_ID_NONE; 00153 }
| MODULE_ID VRUT::ServerBase< T >::createModuleInstance | ( | const wxString | libName = wxT("*") |
) | [inline, protected] |
Create new module instance and get its id
| [in] | libName | Create instance of module matching given name, default value searches for prefered names and then any name |
MODULE_ID_NONE if no matching module found Try prefered
Try any
Find exact match
Definition at line 157 of file serverbase.h.
00158 { 00159 AddAvailableModules(MODULE_PATHS[serverID]); 00160 if (libName.IsSameAs(wxT("*"))) 00161 { 00163 MODULE_ID modID = createPreferedModuleInstance(); 00164 if (modID != MODULE_ID_NONE) 00165 return modID; 00166 00168 for (typename ModuleHandleList::iterator it = moduleHandles.begin(); 00169 it != moduleHandles.end(); it++) 00170 { 00171 wxString modlibName = (*it)->GetFileName().GetName(); 00172 if (!KERNEL->IsForbidden(modlibName)) 00173 { 00174 MODULE_INSTANCE_ID modInstID = (*it)->InstantiateModule(); 00175 if (modInstID != MODULE_INSTANCE_ID_NONE) 00176 return MODULE_ID(serverID, (*it)->GetID(), modInstID); 00177 else 00178 { 00179 LOGWARNING(wxString::Format(wxT("%Module '%s' is invalid, adding to forbidden list"), 00180 SERVER_CLASS_NAMES[serverID].c_str(), modlibName.c_str())); 00181 KERNEL->ForbidModule(modlibName); 00182 } 00183 } 00184 } 00185 } 00186 else 00187 { 00189 std::vector<MODULE_HANDLE_ID> foundHandles = findModuleHandles(libName); 00190 for (std::vector<MODULE_HANDLE_ID>::const_iterator hid = foundHandles.begin(); 00191 hid != foundHandles.end(); hid++) 00192 { 00193 ModuleHandle<T> * modHandle = getModuleHandle(*hid); 00194 wxString modlibName = modHandle->GetFileName().GetName(); 00195 if (!KERNEL->IsForbidden(modlibName)) 00196 { 00197 MODULE_INSTANCE_ID modInstID = modHandle->InstantiateModule(); 00198 if (modInstID != MODULE_INSTANCE_ID_NONE) 00199 return MODULE_ID(serverID, *hid, modInstID); 00200 else 00201 KERNEL->ForbidModule(modlibName); 00202 } 00203 } 00204 } 00205 00206 return MODULE_ID_NONE; 00207 }
| T * VRUT::ServerBase< T >::getModule | ( | const MODULE_ID & | moduleID | ) | const [inline, protected] |
Get module.
Definition at line 211 of file serverbase.h.
00212 { 00213 ModuleHandle<T> * moduleHandle = getModuleHandle(moduleID.GetHandleID()); 00214 if (moduleHandle) 00215 return moduleHandle->GetModule(moduleID.GetInstanceID()); 00216 00217 return (T *)NULL; 00218 }
| void VRUT::ServerBase< T >::releaseModule | ( | const MODULE_ID & | id | ) | [inline, protected] |
Release given module.
Definition at line 222 of file serverbase.h.
00223 { 00224 ModuleHandle<T> * modHandle = getModuleHandle(id.GetHandleID()); 00225 if (modHandle) 00226 modHandle->Release(id.GetInstanceID()); 00227 }
| void VRUT::ServerBase< T >::releaseModules | ( | ) | [inline, protected] |
Release all loaded modules.
Definition at line 323 of file serverbase.h.
00324 { 00325 SAFE_DELETE_ARR_EACH(moduleHandles, moduleHandles.size()); 00326 moduleHandles.clear(); 00327 }
| bool VRUT::ServerBase< T >::GetModules | ( | ModuleList * | moduleList, | |
| const wxString & | moduleName, | |||
| MODULE_INSTANCE_ID | instanceID = MODULE_INSTANCE_ID_NONE | |||
| ) | [inline] |
Get instantiated modules with given module name (and instance ID optionally)
| [out] | moduleList | Will be filled with corresponding modules |
| [in] | moduleName | Module name (or module filename without extension), '*' and '?' allowed |
| [in] | instanceID | If defined one or no module is returned, otherwise instance ID is ignored |
false if no module with moduleName name exists Definition at line 231 of file serverbase.h.
00232 { 00233 bool found = false; 00234 typename ModuleHandleList::iterator it; 00235 for (it = moduleHandles.begin(); it != moduleHandles.end(); it++) 00236 { 00237 if (*it && (*it)->IsLoaded()) 00238 { 00239 wxString modFname = (*it)->GetFileName().GetName(); 00240 wxString modName = (*it)->GetName(); 00241 if (modFname.Matches(moduleName) || 00242 ( !modName.IsEmpty() && modName.Matches(moduleName) ) ) 00243 { 00244 if (instanceID != MODULE_INSTANCE_ID_NONE) 00245 { 00246 Module * module = (*it)->GetModule(instanceID); 00247 if (module) 00248 moduleList->push_back(ModulePair(module, instanceID)); 00249 } 00250 else 00251 (*it)->GetModules(moduleList); 00252 found = true; 00253 } 00254 } 00255 } 00256 return found; 00257 }
| std::vector< wxFileName > VRUT::ServerBase< T >::GetAvailableModules | ( | ) | [inline] |
Get filenames of available (instantiated or not) modules.
Definition at line 261 of file serverbase.h.
00262 { 00263 AddAvailableModules(MODULE_PATHS[serverID]); 00264 std::vector<wxFileName> mods; 00265 typename ModuleHandleList::const_iterator it; 00266 for (it = moduleHandles.begin(); it != moduleHandles.end(); it++) 00267 mods.push_back((*it)->GetFileName()); 00268 00269 return mods; 00270 }
| size_t VRUT::ServerBase< T >::AddAvailableModules | ( | const wxString & | pathToModules | ) | [inline, virtual] |
Update lists of currently available modules.
Reimplemented in VRUT::GeneralManager.
Definition at line 274 of file serverbase.h.
00275 { 00276 LOGVERBOSE(SERVER_CLASS_NAMES[serverID] + wxT("Searching for available modules")); 00277 00278 wxString mask = wxT("*") + wxDynamicLibrary::CanonicalizeName(wxT(""), wxDL_MODULE); 00279 unsigned modulesAdded = 0; 00280 00281 wxDir dir(pathToModules); 00282 if (dir.IsOpened()) 00283 { 00284 wxString filename; 00285 bool cont = dir.GetFirst(&filename, mask, wxDIR_FILES); 00286 while (cont) 00287 { 00288 wxFileName wxfname(wxGetCwd() + wxT("/") + pathToModules + wxT("/") + filename); 00289 bool alreadyAdded = false; 00290 for (unsigned cur = 0; cur < moduleHandles.size() && !alreadyAdded; cur++) 00291 if (wxfname == moduleHandles[cur]->GetFileName()) 00292 alreadyAdded = true; 00293 00294 if (!alreadyAdded) 00295 { 00296 #ifdef __WXDEBUG__ 00297 if (filename.Matches(wxT("*_d.*"))) 00298 { 00299 moduleHandles.push_back(new ModuleHandle<T>(MODULE_HANDLE_ID(moduleHandles.size()), serverID, wxfname, instanceOffset)); 00300 #else 00301 if (!filename.Matches(wxT("*_d.*"))) 00302 { 00303 moduleHandles.push_back(new ModuleHandle<T>(MODULE_HANDLE_ID(moduleHandles.size()), serverID, wxfname, instanceOffset)); 00304 #endif // __WXDEBUG__ 00305 LOG(pathToModules + wxT("/") + filename); 00306 modulesAdded++; 00307 } 00308 } 00309 cont = dir.GetNext(&filename); 00310 } 00311 } 00312 00313 00314 if (modulesAdded) 00315 LOG(wxString::Format(wxT("%s%i "), SERVER_CLASS_NAMES[serverID].c_str(), modulesAdded) 00316 + wxPLURAL("module", "modules", modulesAdded) + wxT(" added")); 00317 00318 return modulesAdded; 00319 }
| SERVER_ID VRUT::ServerBase< T >::GetID | ( | ) | const [inline] |
friend class Kernel [friend] |
Definition at line 80 of file serverbase.h.
ModuleHandleList VRUT::ServerBase< T >::moduleHandles [private] |
SERVER_ID VRUT::ServerBase< T >::serverID [protected] |
MODULE_INSTANCE_ID VRUT::ServerBase< T >::instanceOffset [protected] |
Instance offset - all module instance IDs will start from it.
Definition at line 37 of file serverbase.h.
1.5.5