dasher r3602 - in trunk: . Src/DasherCore Src/Gtk2 Src/MacOSX Src/Win32



Author: pwelche
Date: Wed Oct 29 16:13:24 2008
New Revision: 3602
URL: http://svn.gnome.org/viewvc/dasher?rev=3602&view=rev

Log:
Currently all input modules are known at compile time, so factories are an
unnecessary complication. These may be replaced later, but it is easier to
fix bugs in the simpler code. The number of instances of using translatable
strings as unique keys is reduced, though not completed.


Removed:
   trunk/Src/DasherCore/ModuleFactory.h
   trunk/Src/DasherCore/WrapperFactory.cpp
   trunk/Src/DasherCore/WrapperFactory.h
Modified:
   trunk/ChangeLog
   trunk/Src/DasherCore/DasherInterfaceBase.cpp
   trunk/Src/DasherCore/DasherInterfaceBase.h
   trunk/Src/DasherCore/DasherModule.cpp
   trunk/Src/DasherCore/DasherModule.h
   trunk/Src/DasherCore/Makefile.am
   trunk/Src/DasherCore/ModuleManager.cpp
   trunk/Src/DasherCore/ModuleManager.h
   trunk/Src/DasherCore/TrainingHelper.h
   trunk/Src/Gtk2/DasherControl.cpp
   trunk/Src/MacOSX/COSXDasherControl.mm
   trunk/Src/Win32/Dasher.cpp

Modified: trunk/Src/DasherCore/DasherInterfaceBase.cpp
==============================================================================
--- trunk/Src/DasherCore/DasherInterfaceBase.cpp	(original)
+++ trunk/Src/DasherCore/DasherInterfaceBase.cpp	Wed Oct 29 16:13:24 2008
@@ -37,7 +37,6 @@
 #include "UserLog.h"
 #include "BasicLog.h"
 #endif
-#include "WrapperFactory.h"
 #include "DasherGameMode.h"
 
 // Input filters
@@ -90,10 +89,10 @@
   m_DasherScreen = NULL;
   m_pDasherView = NULL;
   m_pInput = NULL;
+  m_pInputFilter = NULL;
   m_AlphIO = NULL;
   m_ColourIO = NULL;
   m_pUserLog = NULL;
-  m_pInputFilter = NULL;
   m_pNCManager = NULL;
 
   // Various state variables
@@ -207,7 +206,6 @@
   delete m_pDasherView;
   delete m_ColourIO;
   delete m_AlphIO;
-  delete m_pInputFilter;
   delete m_pNCManager;
   //  delete m_pTrainingHelper;
   // Do NOT delete Edit box or Screen. This class did not create them.
@@ -509,13 +507,14 @@
 void CDasherInterfaceBase::CreateInput() {
   if(m_pInput) {
     m_pInput->Deactivate();
-    m_pInput->Unref();
   }
 
   m_pInput = (CDasherInput *)GetModuleByName(GetStringParameter(SP_INPUT_DEVICE));
 
+  if (m_pInput == NULL)
+    m_pInput = (CDasherInput *)GetDefaultInputDevice();
+
   if(m_pInput) {
-    m_pInput->Ref();
     m_pInput->Activate();
   }
 
@@ -896,54 +895,69 @@
 {
   if(m_pInputFilter) {
     m_pInputFilter->Deactivate();
-    m_pInputFilter->Unref();
     m_pInputFilter = NULL;
   }
 
 #ifndef _WIN32_WCE
   m_pInputFilter = (CInputFilter *)GetModuleByName(GetStringParameter(SP_INPUT_FILTER));
-#else
-  m_pInputFilter = (CInputFilter *)GetModuleByName("Click Mode");
 #endif
 
-  if(m_pInputFilter) {
-    m_pInputFilter->Ref();
-    m_pInputFilter->Activate();
-  }
-  else {
-    // Fall back to a sensible alternative if for some reason the
-    // current choice isn't valid.
-    if(GetStringParameter(SP_INPUT_FILTER) != "Normal Control")
-      SetStringParameter(SP_INPUT_FILTER, "Normal Control");
-  }
+  if (m_pInputFilter == NULL)
+    m_pInputFilter = (CInputFilter *)GetDefaultInputMethod();
+
+  m_pInputFilter->Activate();
 }
 
-void CDasherInterfaceBase::RegisterFactory(CModuleFactory *pFactory) {
-  m_oModuleManager.RegisterFactory(pFactory);
+CDasherModule *CDasherInterfaceBase::RegisterModule(CDasherModule *pModule) {
+    return m_oModuleManager.RegisterModule(pModule);
 }
  
 CDasherModule *CDasherInterfaceBase::GetModule(ModuleID_t iID) {
-   return m_oModuleManager.GetModule(iID);
+    return m_oModuleManager.GetModule(iID);
 }
 
 CDasherModule *CDasherInterfaceBase::GetModuleByName(const std::string &strName) {
-   return m_oModuleManager.GetModuleByName(strName);
+    return m_oModuleManager.GetModuleByName(strName);
+}
+
+CDasherModule *CDasherInterfaceBase::GetDefaultInputDevice() {
+    return m_oModuleManager.GetDefaultInputDevice();
+}
+
+CDasherModule *CDasherInterfaceBase::GetDefaultInputMethod() {
+    return m_oModuleManager.GetDefaultInputMethod();
+}
+
+void CDasherInterfaceBase::SetDefaultInputDevice(CDasherModule *pModule) {
+    m_oModuleManager.SetDefaultInputDevice(pModule);
+}
+
+void CDasherInterfaceBase::SetDefaultInputMethod(CDasherModule *pModule) {
+    m_oModuleManager.SetDefaultInputMethod(pModule);
 }
 
 void CDasherInterfaceBase::CreateFactories() {
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDefaultFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel,3, _("Normal Control"))));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new COneDimensionalFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CEyetrackerFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CClickFilter(m_pEventHandler, m_pSettingsStore, this)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new COneButtonDynamicFilter(m_pEventHandler, m_pSettingsStore, this)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CTwoButtonDynamicFilter(m_pEventHandler, m_pSettingsStore, this)));
+  SetDefaultInputMethod(
+    RegisterModule(new CDefaultFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel,3, _("Normal Control")))
+  );
+  RegisterModule(new COneDimensionalFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel));
+  RegisterModule(new CEyetrackerFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel));
+#ifndef _WIN32_WCE
+  RegisterModule(new CClickFilter(m_pEventHandler, m_pSettingsStore, this));
+#else
+  SetDefaultInputMethod(
+    RegisterModule(new CClickFilter(m_pEventHandler, m_pSettingsStore, this));
+  );
+#endif
+  RegisterModule(new COneButtonDynamicFilter(m_pEventHandler, m_pSettingsStore, this));
+  RegisterModule(new CTwoButtonDynamicFilter(m_pEventHandler, m_pSettingsStore, this));
   // TODO: specialist factory for button mode
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 5, 1, true,8, _("Menu Mode"))));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 3, 0, false,10, _("Direct Mode"))));
-  //  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 4, 0, false,11, "Buttons 3")));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 3, 3, false,12, _("Alternating Direct Mode"))));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 4, 2, false,13, _("Compass Mode"))));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CStylusFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel,15, _("Stylus Control"))));
+  RegisterModule(new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 5, 1, true,8, _("Menu Mode")));
+  RegisterModule(new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 3, 0, false,10, _("Direct Mode")));
+  //  RegisterModule(new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 4, 0, false,11, "Buttons 3"));
+  RegisterModule(new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 3, 3, false,12, _("Alternating Direct Mode")));
+  RegisterModule(new CDasherButtons(m_pEventHandler, m_pSettingsStore, this, 4, 2, false,13, _("Compass Mode")));
+  RegisterModule(new CStylusFilter(m_pEventHandler, m_pSettingsStore, this, m_pDasherModel,15, _("Stylus Control")));
 
 }
 

Modified: trunk/Src/DasherCore/DasherInterfaceBase.h
==============================================================================
--- trunk/Src/DasherCore/DasherInterfaceBase.h	(original)
+++ trunk/Src/DasherCore/DasherInterfaceBase.h	Wed Oct 29 16:13:24 2008
@@ -335,7 +335,13 @@
   /// @}
 
   // Module management functions
-  void RegisterFactory(CModuleFactory *pFactory);
+  CDasherModule *RegisterModule(CDasherModule *pModule);
+  CDasherModule *GetModule(ModuleID_t iID);
+  CDasherModule *GetModuleByName(const std::string &strName);
+  CDasherModule *GetDefaultInputDevice();
+  CDasherModule *GetDefaultInputMethod();
+  void SetDefaultInputDevice(CDasherModule *);
+  void SetDefaultInputMethod(CDasherModule *);
 
   void StartShutdown();
 
@@ -428,9 +434,6 @@
 
   /// @}
 
-  CDasherModule *GetModule(ModuleID_t iID);
-  CDasherModule *GetModuleByName(const std::string &strName);
-
   CEventHandler *m_pEventHandler;
   CSettingsStore *m_pSettingsStore;
 
@@ -584,12 +587,12 @@
   CDasherScreen *m_DasherScreen;
   CDasherView *m_pDasherView;
   CDasherInput *m_pInput;
+  CInputFilter* m_pInputFilter;
+  CModuleManager m_oModuleManager;
   CAlphIO *m_AlphIO;
   CColourIO *m_ColourIO;
   CNodeCreationManager *m_pNCManager;
   CUserLogBase *m_pUserLog; 
-  CInputFilter* m_pInputFilter;
-  CModuleManager m_oModuleManager;
   //  CTrainingHelper *m_pTrainingHelper;
   /// @}
 

Modified: trunk/Src/DasherCore/DasherModule.cpp
==============================================================================
--- trunk/Src/DasherCore/DasherModule.cpp	(original)
+++ trunk/Src/DasherCore/DasherModule.cpp	Wed Oct 29 16:13:24 2008
@@ -1,3 +1,23 @@
+// DasherModule.cpp
+// 
+// Copyright (c) 2008 The Dasher Team
+//
+// This file is part of Dasher.
+//
+// Dasher is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//  
+// Dasher is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//  
+// You should have received a copy of the GNU General Public License
+// along with Dasher; if not, write to the Free Software 
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 #include "DasherModule.h"
 
 #include <iostream>
@@ -6,33 +26,10 @@
 // 0 = Input method
 // 1 = Input filter
 
-// IDs:
-// 0 = Mouse input
-// 1 = Socket input
-// 2 = 1D mouse input
-// 3 = Default filter
-// 4 = 1D mode
-// 5 = Eyetracker mode
-// 6 = Dynamic Filter
-// 7 = Click Mode
-// 8 = Button mode (menu)
-// 9 = One button filter (obsolete?)
-// 10 = Button mode (static 3)
-// 11 = Button mode (static 4)
-// 12 = Button mode (alternating)
-// 13 = Button mode (compass)
-// 14 = Two button dynamic filter (Radford mode)
-// 15 = Stylus input filter
-// 16 = Joystick input
-// 17 = Discrete joystick
-// 18 = 1D joystick
-// 19 = Tilt
-
 CDasherModule::CDasherModule(Dasher::CEventHandler * pEventHandler, CSettingsStore * pSettingsStore, ModuleID_t iID, int iType, const char *szName) 
   : CDasherComponent(pEventHandler, pSettingsStore) {
   m_iID = iID;
   m_iType = iType;
-  m_iRefCount = 0;
   m_szName = szName;
 }
 
@@ -40,6 +37,10 @@
   return m_iID;
 }
 
+void CDasherModule::SetID(ModuleID_t id) {
+  m_iID = id;
+}
+
 int CDasherModule::GetType() {
   return m_iType;
 }
@@ -47,14 +48,3 @@
 const char *CDasherModule::GetName() {
   return m_szName;
 }
-
-void CDasherModule::Ref() {
-  ++m_iRefCount;
-}
-
-void CDasherModule::Unref() {
-  --m_iRefCount;
-
-  if(m_iRefCount == 0)
-    delete this;
-}

Modified: trunk/Src/DasherCore/DasherModule.h
==============================================================================
--- trunk/Src/DasherCore/DasherModule.h	(original)
+++ trunk/Src/DasherCore/DasherModule.h	Wed Oct 29 16:13:24 2008
@@ -1,14 +1,33 @@
-#ifndef __DASHER_MODULE_H__
-#define __DASHER_MODULE_H__
+// DasherModule.h
+// 
+// Copyright (c) 2008 The Dasher Team
+//
+// This file is part of Dasher.
+//
+// Dasher is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//  
+// Dasher is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//  
+// You should have received a copy of the GNU General Public License
+// along with Dasher; if not, write to the Free Software 
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifndef DASHER_MODULE_H
+#define DASHER_MODULE_H
+
+#include <vector>
 
 #include "../Common/ModuleSettings.h"
 #include "DasherComponent.h"
 
-#ifdef WIN32
-typedef __int64 ModuleID_t;
-#else
-typedef long long int ModuleID_t;
-#endif
+class CDasherModule;
+typedef std::vector<CDasherModule*>::size_type ModuleID_t;
 
 /// \ingroup Core
 /// @{
@@ -17,6 +36,7 @@
   CDasherModule(Dasher::CEventHandler * pEventHandler, CSettingsStore * pSettingsStore, ModuleID_t iID, int iType, const char *szName);
 
   virtual ModuleID_t GetID();
+  virtual void SetID(ModuleID_t);
   virtual int GetType();
   virtual const char *GetName();
 
@@ -24,24 +44,9 @@
     return false;
   };
 
-  // Basic Reference counting
-
-  ///
-  /// Add a reference to the module
-  ///
-
-  virtual void Ref();
-
-  /// 
-  /// Remove a reference to the module
-  ///
-
-  virtual void Unref();
-
  private:
   ModuleID_t m_iID;
   int m_iType;
-  int m_iRefCount;
   const char *m_szName;
 };
 /// @}

Modified: trunk/Src/DasherCore/Makefile.am
==============================================================================
--- trunk/Src/DasherCore/Makefile.am	(original)
+++ trunk/Src/DasherCore/Makefile.am	Wed Oct 29 16:13:24 2008
@@ -87,7 +87,6 @@
 		InputFilter.h \
 		MemoryLeak.cpp \
 		MemoryLeak.h \
-		ModuleFactory.h \
 		ModuleManager.cpp \
 		ModuleManager.h \
 		NodeCreationManager.cpp \
@@ -129,8 +128,6 @@
 		UserLogTrial.cpp \
 		UserLogTrial.h \
 		View/DelayedDraw.h \
-		WrapperFactory.cpp \
-		WrapperFactory.h \
 		XMLUtil.cpp \
 		XMLUtil.h
 

Modified: trunk/Src/DasherCore/ModuleManager.cpp
==============================================================================
--- trunk/Src/DasherCore/ModuleManager.cpp	(original)
+++ trunk/Src/DasherCore/ModuleManager.cpp	Wed Oct 29 16:13:24 2008
@@ -1,42 +1,108 @@
-#include "ModuleManager.h"
+// ModuleManager.cpp
+//
+// Copyright (c) 2008 The Dasher Team
+//
+// This file is part of Dasher.
+//
+// Dasher is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// Dasher is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Dasher; if not, write to the Free Software 
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#include <iostream>
+#include <stdexcept>
 
-void CModuleManager::RegisterFactory(CModuleFactory *pFactory) {
-  pFactory->Start();
+#include "ModuleManager.h"
 
-  while(pFactory->IsMore()) {
-    ModuleID_t iID;
-    int iType;
-    std::string strName;
+using namespace Dasher;
 
-    pFactory->GetNext(&iID, &iType, &strName);
+CDasherModule *CModuleManager::RegisterModule(CDasherModule *pModule) {
+    m_vModules.push_back(pModule);
+    ModuleID_t id = m_vModules.size() - 1;
+    pModule->SetID(id);
+
+    // This does
+    //     m_mapNameToID[pModule->GetName()] = id;
+    // but with error checking.
+    std::pair<std::map<const std::string, ModuleID_t>::iterator, bool> res;
+    std::pair<const std::string, ModuleID_t> keyvalue(pModule->GetName(), id);
+    res = m_mapNameToID.insert(keyvalue);
+    if (!res.second)
+        std::cerr << "Module \"" << pModule->GetName()
+                  << "\" registered twice" << std::endl;
 
-    m_mapModules[iID] = pFactory;
-  }
+    return pModule;
 }
 
 CDasherModule *CModuleManager::GetModule(ModuleID_t iID) {
-  // TODO: Error checking here
-  
-  return m_mapModules[iID]->GetModule(iID);
+    // This does
+    //     return m_vModules[iID];
+    // but with error checking.
+    try {
+        return m_vModules.at(iID);
+    }
+    catch (std::out_of_range) {
+        std::cerr << "Module with ID " << iID << " not found" << std::endl;
+        return NULL;
+    }
 }
 
 CDasherModule *CModuleManager::GetModuleByName(const std::string strName) {
-  for(std::map<ModuleID_t, CModuleFactory *>::iterator it(m_mapModules.begin()); it != m_mapModules.end(); ++it) {
-    if(strName == (it->second)->GetName(it->first))
-      return (it->second)->GetModule(it->first);
-  }
-
-  return 0;
+    // This does
+    //    return m_vModules[m_mapNameToID[strName]];
+    // but with error checking.
+    std::map<const std::string, ModuleID_t>::iterator res;
+    res = m_mapNameToID.find(strName);
+    if (res == m_mapNameToID.end()) {
+        std::cerr << "Module \"" << strName << "\" not registered" <<std::endl;
+        return NULL;
+    } else {
+        return m_vModules[res->second];
+    }
 }
 
 void CModuleManager::ListModules(int iType, std::vector<std::string> &vList) {
-  for(std::map<ModuleID_t, CModuleFactory *>::iterator it(m_mapModules.begin()); it != m_mapModules.end(); ++it) {
-    if((it->second)->GetType(it->first) == iType)
-      vList.push_back((it->second)->GetName(it->first));
-  }
+    for (ModuleID_t i = 0; i < m_vModules.size(); ++i) {
+        if(m_vModules[i]->GetType() == iType)
+            vList.push_back(m_vModules[i]->GetName());
+    }
 }
 
 CModuleManager::~CModuleManager() {
-  for(std::map<ModuleID_t, CModuleFactory *>::iterator it(m_mapModules.begin()); it != m_mapModules.end(); ++it)
-    delete it->second;
+    for (ModuleID_t i = 0; i < m_vModules.size(); ++i) {
+        delete m_vModules[i];
+    }
+}
+
+CDasherModule *CModuleManager::GetDefaultInputDevice() {
+    return m_pDefaultInputDevice;
+}
+
+CDasherModule *CModuleManager::GetDefaultInputMethod() {
+    return m_pDefaultInputMethod;
+}
+
+void CModuleManager::SetDefaultInputDevice(CDasherModule *p) {
+    if (p->GetType() == InputDevice)
+        m_pDefaultInputDevice = p;
+    else
+        std::cerr << "Tried to register " << p->GetName()
+                  << " as an input device" << std::endl;
+}
+
+void CModuleManager::SetDefaultInputMethod(CDasherModule *p) {
+    if (p->GetType() == InputMethod)
+        m_pDefaultInputMethod = p;
+    else
+        std::cerr << "Tried to register " << p->GetName()
+                  << " as an input method" << std::endl;
 }

Modified: trunk/Src/DasherCore/ModuleManager.h
==============================================================================
--- trunk/Src/DasherCore/ModuleManager.h	(original)
+++ trunk/Src/DasherCore/ModuleManager.h	Wed Oct 29 16:13:24 2008
@@ -1,27 +1,59 @@
-#ifndef __MODULE_MANAGER_H__
-#define __MODULE_MANAGER_H__
+// ModuleManager.h
+//
+// Copyright (c) 2008 The Dasher Team
+//
+// This file is part of Dasher.
+//
+// Dasher is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// Dasher is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Dasher; if not, write to the Free Software 
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifndef MODULE_MANAGER_H
+#define MODULE_MANAGER_H
 
 #include "DasherModule.h"
-#include "ModuleFactory.h"
 
 #include <map>
 #include <string>
 #include <vector>
 
+namespace Dasher {
+
+enum ModuleType {InputDevice = 0, InputMethod = 1};
+
 /// \ingroup Core
 /// \{
 class CModuleManager {
  public:
   ~CModuleManager();
-  void RegisterFactory(CModuleFactory *pFactory);
+  CDasherModule *RegisterModule(CDasherModule *pModule);
   CDasherModule *GetModule(ModuleID_t iID);
   CDasherModule *GetModuleByName(const std::string strName);
+  CDasherModule *GetDefaultInputDevice();
+  CDasherModule *GetDefaultInputMethod();
+  void SetDefaultInputDevice(CDasherModule *);
+  void SetDefaultInputMethod(CDasherModule *);
 
   void ListModules(int iType, std::vector<std::string> &vList);
 
  private:
-  std::map<ModuleID_t, CModuleFactory *> m_mapModules;
+  std::vector<CDasherModule *> m_vModules;
+  std::map<const std::string, ModuleID_t> m_mapNameToID;
+  CDasherModule *m_pDefaultInputDevice;
+  CDasherModule *m_pDefaultInputMethod;
 };
 /// \}
 
+}
+
 #endif

Modified: trunk/Src/DasherCore/TrainingHelper.h
==============================================================================
--- trunk/Src/DasherCore/TrainingHelper.h	(original)
+++ trunk/Src/DasherCore/TrainingHelper.h	Wed Oct 29 16:13:24 2008
@@ -1,4 +1,4 @@
-// TrainingHelper.cpp.h
+// TrainingHelper.h
 //
 // Copyright (c) 2007 The Dasher Team
 //

Modified: trunk/Src/Gtk2/DasherControl.cpp
==============================================================================
--- trunk/Src/Gtk2/DasherControl.cpp	(original)
+++ trunk/Src/Gtk2/DasherControl.cpp	Wed Oct 29 16:13:24 2008
@@ -6,7 +6,7 @@
 #include "DasherControl.h"
 #include "Timer.h"
 #include "../DasherCore/Event.h"
-#include "../DasherCore/WrapperFactory.h"
+#include "../DasherCore/ModuleManager.h"
 
 #include <fcntl.h>
 
@@ -44,29 +44,23 @@
 }
 
 void CDasherControl::CreateLocalFactories() {
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherMouseInput(m_pEventHandler, m_pSettingsStore)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CSocketInput(m_pEventHandler, m_pSettingsStore)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasher1DMouseInput(m_pEventHandler, m_pSettingsStore)));
+  // Create locally cached copies of the mouse input objects, as we
+  // need to pass coordinates to them from the timer callback
+  m_pMouseInput =
+    (CDasherMouseInput *)  RegisterModule(new CDasherMouseInput(m_pEventHandler, m_pSettingsStore));
+  SetDefaultInputDevice(m_pMouseInput);
+  m_p1DMouseInput =
+    (CDasher1DMouseInput *)RegisterModule(new CDasher1DMouseInput(m_pEventHandler, m_pSettingsStore));
+  RegisterModule(new CSocketInput(m_pEventHandler, m_pSettingsStore));
 
 #ifdef JOYSTICK
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherJoystickInput(m_pEventHandler, m_pSettingsStore, this)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherJoystickInputDiscrete(m_pEventHandler, m_pSettingsStore, this)));
+  RegisterModule(new CDasherJoystickInput(m_pEventHandler, m_pSettingsStore, this));
+  RegisterModule(new CDasherJoystickInputDiscrete(m_pEventHandler, m_pSettingsStore, this));
 #endif
   
 #ifdef TILT
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherTiltInput(m_pEventHandler, m_pSettingsStore, this)));
+  RegisterModule(new CDasherTiltInput(m_pEventHandler, m_pSettingsStore, this));
 #endif
-  
-  
-  // Create locally cached copies of the mouse input objects, as we
-  // need to pass coordinates to them from the timer callback
-  
-  m_pMouseInput = (CDasherMouseInput *)GetModule(0);
-  m_pMouseInput->Ref();
-
-  m_p1DMouseInput = (CDasher1DMouseInput *)GetModule(2);
-  m_p1DMouseInput->Ref();
-
 }
 
 void CDasherControl::SetupUI() {
@@ -192,12 +186,10 @@
 
 CDasherControl::~CDasherControl() {
   if(m_pMouseInput) {
-    m_pMouseInput->Unref();
     m_pMouseInput = NULL;
   }
 
   if(m_p1DMouseInput) {
-    m_p1DMouseInput->Unref();
     m_p1DMouseInput = NULL;
   }
 

Modified: trunk/Src/MacOSX/COSXDasherControl.mm
==============================================================================
--- trunk/Src/MacOSX/COSXDasherControl.mm	(original)
+++ trunk/Src/MacOSX/COSXDasherControl.mm	Wed Oct 29 16:13:24 2008
@@ -10,7 +10,7 @@
 #import <Cocoa/Cocoa.h>
 #import "COSXDasherControl.h"
 #import "COSXSettingsStore.h"
-#import "WrapperFactory.h"
+#import "ModuleManager.h"
 #import "COSXMouseInput.h"
 #import "DasherUtil.h"
 #import "DasherApp.h"
@@ -39,32 +39,20 @@
 }
 
 void COSXDasherControl::CreateLocalFactories() {
-  
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new COSXMouseInput(m_pEventHandler, m_pSettingsStore)));
-
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new COSX1DMouseInput(m_pEventHandler, m_pSettingsStore)));
-  
-  
-  
   // Create locally cached copies of the mouse input objects, as we
   // need to pass coordinates to them from the timer callback
-  
-  m_pMouseInput = (COSXMouseInput *)GetModule(0);
-  m_pMouseInput->Ref();
-  
-  m_p1DMouseInput = (COSX1DMouseInput *)GetModule(2);
-  m_p1DMouseInput->Ref();
-  
+  m_pMouseInput =
+    (COSXMouseInput *)  RegisterModule(new COSXMouseInput(m_pEventHandler, m_pSettingsStore));
+  m_p1DMouseInput =
+    (COSX1DMouseInput *)RegisterModule(new COSX1DMouseInput(m_pEventHandler, m_pSettingsStore));
 }
   
 COSXDasherControl::~COSXDasherControl() {
   if(m_pMouseInput) {
-    m_pMouseInput->Unref();
     m_pMouseInput = NULL;
   }
   
   if(m_p1DMouseInput) {
-    m_p1DMouseInput->Unref();
     m_p1DMouseInput = NULL;
   }
 }

Modified: trunk/Src/Win32/Dasher.cpp
==============================================================================
--- trunk/Src/Win32/Dasher.cpp	(original)
+++ trunk/Src/Win32/Dasher.cpp	Wed Oct 29 16:13:24 2008
@@ -1,7 +1,7 @@
 
 #include "Common\WinCommon.h"          // must include pch first
 
-#include "../DasherCore/WrapperFactory.h"
+#include "../DasherCore/ModuleManager.h"
 
 #include "Dasher.h"
 #include "../DasherCore/Event.h"
@@ -51,10 +51,10 @@
 
 void CDasher::CreateLocalFactories() {
 #ifndef _WIN32_WCE
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CSocketInput(m_pEventHandler, m_pSettingsStore)));
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CBTSocketInput(m_pEventHandler, m_pSettingsStore)));
+  RegisterModule(new CSocketInput(m_pEventHandler, m_pSettingsStore));
+  RegisterModule(new CBTSocketInput(m_pEventHandler, m_pSettingsStore));
 #endif
-  RegisterFactory(new CWrapperFactory(m_pEventHandler, m_pSettingsStore, new CDasherMouseInput(m_pEventHandler, m_pSettingsStore, m_pCanvas->getwindow())));
+  RegisterModule(new CDasherMouseInput(m_pEventHandler, m_pSettingsStore, m_pCanvas->getwindow()));
 }
 
 void CDasher::Main() {
@@ -291,4 +291,4 @@
 
 void CDasher::TakeFocus() {
   // TODO: Implement me
-}
\ No newline at end of file
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]