Changeset 5924 for branches/newapi
- Timestamp:
- 12/03/07 06:17:48 (12 months ago)
- Location:
- branches/newapi/licq
- Files:
-
- 2 added
- 1 removed
- 15 modified
-
licq/log.h (modified) (1 diff)
-
src/CMakeLists.txt (modified) (1 diff)
-
src/daemon.cpp (modified) (9 diffs)
-
src/globals.cpp (added)
-
src/globals.h (added)
-
src/main.cpp (modified) (4 diffs)
-
src/plugin/plugincacheimpl.cpp (modified) (2 diffs)
-
src/plugin/plugininstanceimpl.cpp (modified) (1 diff)
-
src/plugin/pluginlibrary.h (modified) (1 diff)
-
src/plugin/pluginloader.h (modified) (1 diff)
-
src/plugin/pluginmanager.h (modified) (2 diffs)
-
src/plugin/pluginmanagerimpl.cpp (modified) (4 diffs)
-
src/plugin/pluginmanagerimpl.h (modified) (3 diffs)
-
src/plugin/test/pluginlibrarytest.cpp (modified) (2 diffs)
-
src/static.cpp (deleted)
-
src/test/log.cpp (modified) (1 diff)
-
src/test/log.h (modified) (2 diffs)
-
src/util/log.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/newapi/licq/licq/log.h
r5912 r5924 33 33 { 34 34 public: 35 /**36 * Get the calling thread's log. Can only be called from the37 * daemon's or plugin's main thread (i.e. the thread executing38 * Plugin::run()).39 *40 * @returns The calling thread's log instance.41 */42 static Log* getThreadLog();43 44 35 enum Level 45 36 { -
branches/newapi/licq/src/CMakeLists.txt
r5909 r5924 1 1 set(daemon_SRCS 2 2 daemon.cpp 3 globals.cpp 3 4 main.cpp 4 static.cpp5 5 6 6 # backgroundcodes.c -
branches/newapi/licq/src/daemon.cpp
r5921 r5924 19 19 20 20 #include "daemon.h" 21 #include "globals.h" 21 22 #include "licq/exception/invalidargumentexception.h" 22 23 #include "licq/exception/runtimeexception.h" … … 38 39 #include <sys/types.h> 39 40 41 Licq::Daemon* Licq::Daemon::getInstance() 42 { 43 return LicqDaemon::Globals::getDaemon(); 44 } 45 40 46 static inline void printLicqVersion(std::ostream& os) 41 47 { … … 78 84 79 85 LicqDaemon::Daemon::Daemon() 80 : myLog( *Licq::Log::getThreadLog())86 : myLog(Globals::getDaemonLog()) 81 87 { 82 88 // Empty … … 165 171 if (vm.count("plugin")) 166 172 { 167 PluginManager* pluginManager = PluginManager::getInstance();173 PluginManager* pluginManager = Globals::getPluginManager(); 168 174 169 175 std::vector<std::string> … … 182 188 int LicqDaemon::Daemon::main() 183 189 { 184 PluginManager::getInstance()->unloadAll();185 190 return 1; 186 191 } … … 189 194 std::vector< boost::shared_ptr<const Licq::Plugin::Information> >* info) 190 195 { 191 PluginManager::getInstance()->getPluginInformation(info);196 Globals::getPluginManager()->getPluginInformation(info); 192 197 } 193 198 … … 226 231 void LicqDaemon::Daemon::setupDefaultPluginPaths(bool reload) 227 232 { 228 PluginCache* cache = PluginManager::getInstance()->getPluginCache();233 PluginCache* cache = Globals::getPluginManager()->getPluginCache(); 229 234 cache->addSearchPath(myBaseDir + ".plugins/"); 230 235 … … 237 242 setupDefaultPluginPaths(false); 238 243 239 PluginCache* cache = PluginManager::getInstance()->getPluginCache();244 PluginCache* cache = Globals::getPluginManager()->getPluginCache(); 240 245 for (std::vector<std::string>::const_iterator it = paths.begin(); 241 246 it != paths.end(); ++it) … … 249 254 void LicqDaemon::Daemon::printAvailablePlugins(std::ostream& os) const 250 255 { 251 PluginCache* cache = PluginManager::getInstance()->getPluginCache();256 PluginCache* cache = Globals::getPluginManager()->getPluginCache(); 252 257 253 258 const size_t size = cache->getSize(); -
branches/newapi/licq/src/main.cpp
r5918 r5924 8 8 9 9 #include "daemon.h" 10 #include "globals.h" 10 11 #include "licq/exception/exception.h" 11 12 #include "licq/exception/invalidargumentexception.h" 13 #include "licq/exception/runtimeexception.h" 14 #include "licq/log.h" 12 15 #include "plugin/pluginmanager.h" 13 #include "util/log.h"14 16 #include "util/logdistributor.h" 15 17 #include "util/tr.h" … … 20 22 21 23 /* 22 #ifdef HAVE_CONFIG_H23 #include "config.h"24 #endif25 26 #include <signal.h>27 #include <cstdlib>28 #include <cstring>29 30 #include <locale>31 32 24 #include "licq.h" 33 25 #include "licq_sighandler.h" … … 40 32 } 41 33 #endif 42 43 // Localization44 #include "gettext.h"45 34 */ 46 47 #include "licq_constants.h"48 49 // define a global variable for the base directory containing the data50 // and config subdirectories51 char BASE_DIR[MAX_FILENAME_LEN];52 char SHARE_DIR[MAX_FILENAME_LEN];53 char LIB_DIR[MAX_FILENAME_LEN];54 unsigned short DEBUG_LEVEL;55 35 56 36 int main(int argc, char** argv) 57 37 { 58 // Set up logging59 LicqDaemon::LogDistributor logDistributor; 60 LicqDaemon:: Log::setThreadLog(new LicqDaemon::Log("licq", &logDistributor));61 Licq::Log& log = *Licq::Log::getThreadLog();38 int retval = EXIT_SUCCESS; 39 40 LicqDaemon::Globals globals; 41 Licq::Log& log = globals.getDaemonLog(); 62 42 63 43 // Enable logging to stderr 64 44 LicqDaemon::StreamLogSink streamLogSink(std::cerr); 65 logDistributor.registerSink(&streamLogSink);45 globals.getLogDistributor()->registerSink(&streamLogSink); 66 46 if (!isatty(STDERR_FILENO)) 67 47 streamLogSink.setUseColors(false); 68 48 69 // Configure PluginManager70 LicqDaemon::PluginManager::getInstance()->setPluginLogSink(&logDistributor);71 72 // Fail if argv[0] isn't set73 if (argc < 1)74 {75 log.fatal() << tr("Licq requires argv[0] to be set");76 exit(EXIT_FAILURE);77 }78 79 int retval = 0;80 49 try 81 50 { 82 51 LicqDaemon::setupLocalization(); 83 52 84 LicqDaemon::Daemon* daemon = LicqDaemon::Daemon::getInstance(); 53 if (argc < 1) 54 throw Licq::RuntimeException(tr("Licq requires argv[0] to be set")); 55 56 LicqDaemon::Daemon* daemon = globals.getDaemon(); 85 57 daemon->installSignalHandlers(); 86 58 59 bool continueAfterInit = false; 87 60 try 88 61 { 89 if (!daemon->init(argc, argv, streamLogSink)) 90 exit(EXIT_SUCCESS); 62 continueAfterInit = daemon->init(argc, argv, streamLogSink); 63 if (!continueAfterInit) 64 retval = EXIT_SUCCESS; 91 65 } 92 66 catch (const Licq::InvalidArgumentException& ex) … … 94 68 std::cerr << ex << "\n"; 95 69 std::cerr << tr("Try `%1% --help' for more information.") % argv[0] << "\n"; 96 exit(EXIT_FAILURE);70 retval = EXIT_FAILURE; 97 71 } 98 72 99 retval = daemon->main(); 73 if (continueAfterInit) 74 retval = daemon->main(); 100 75 } 101 76 catch (const Licq::Exception& ex) 102 77 { 103 78 log.fatal() << ex; 104 exit(EXIT_FAILURE);79 retval = EXIT_FAILURE; 105 80 } 106 81 catch (const std::exception& ex) 107 82 { 108 83 log.fatal() << tr("Caught std::exception: %1%") % ex.what(); 109 exit(EXIT_FAILURE);84 retval = EXIT_FAILURE; 110 85 } 111 86 catch (...) 112 87 { 113 88 log.fatal() << tr("Caught unknown exception"); 114 exit(EXIT_FAILURE);89 throw; 115 90 } 116 91 117 if (retval != 0) 92 globals.cleanup(); 93 94 if (retval != EXIT_SUCCESS) 118 95 log.error(tr("Licq finished with exit code %1%") % retval); 119 96 120 logDistributor.unregisterSink(&streamLogSink);97 globals.getLogDistributor()->unregisterSink(&streamLogSink); 121 98 return retval; 122 99 123 100 /* 124 #if ENABLE_NLS125 // prepare daemon localization126 setlocale(LC_MESSAGES,"");127 setlocale(LC_CTYPE,"");128 bindtextdomain(PACKAGE, LOCALEDIR);129 textdomain(PACKAGE);130 #endif131 132 // Make sure argv[0] is defined otherwise licq will crash if it is NULL133 if (argv[0] == NULL)134 argv[0] = strdup("licq");135 101 #ifdef USE_SOCKS5 136 102 SOCKSinit(argv[0]); -
branches/newapi/licq/src/plugin/plugincacheimpl.cpp
r5913 r5924 18 18 */ 19 19 20 #include "globals.h" 20 21 #include "licq/exception/invalidargumentexception.h" 21 22 #include "licq/exception/runtimeexception.h" … … 117 118 LicqDaemon::PluginCacheImpl::PluginCacheImpl(PluginLoader& loader, 118 119 bool testMode) 119 : myLog( *Licq::Log::getThreadLog()),120 : myLog(Globals::getDaemonLog()), 120 121 myLoader(loader), 121 122 myInTestMode(testMode) -
branches/newapi/licq/src/plugin/plugininstanceimpl.cpp
r5921 r5924 57 57 { 58 58 delete myThread; 59 59 60 myLibrary->destroyPlugin(myPlugin); 61 myPlugin = NULL; 60 62 61 63 delete static_cast<Log*>(mySetup.log); -
branches/newapi/licq/src/plugin/pluginlibrary.h
r5921 r5924 33 33 { 34 34 public: 35 virtual ~PluginLibrary() {}36 37 35 virtual unsigned int getPluginAbiVersion() = 0; 38 36 virtual void getPluginInformation(Licq::Plugin::Information* info) = 0; 39 37 virtual Licq::Plugin* createPlugin(const Licq::Plugin::Setup& setup) = 0; 40 38 virtual void destroyPlugin(Licq::Plugin* plugin) = 0; 39 40 protected: 41 virtual ~PluginLibrary() { /* Empty */ } 41 42 }; 42 43 -
branches/newapi/licq/src/plugin/pluginloader.h
r5362 r5924 35 35 { 36 36 public: 37 virtual ~PluginLoader() {}37 virtual boost::shared_ptr<PluginLibrary> load(const std::string& filename) = 0; 38 38 39 virtual boost::shared_ptr<PluginLibrary> load(const std::string& filename) = 0; 39 protected: 40 virtual ~PluginLoader() { /* Empty */ } 40 41 }; 41 42 -
branches/newapi/licq/src/plugin/pluginmanager.h
r5921 r5924 27 27 #include <vector> 28 28 29 namespace Licq30 {31 class LogSink;32 }33 34 29 namespace LicqDaemon 35 30 { … … 44 39 { 45 40 public: 46 /**47 * @returns The PluginManager singleton.48 */49 static PluginManager* getInstance();50 51 virtual void unloadAll() = 0;52 53 virtual void setPluginLogSink(Licq::LogSink* sink) = 0;54 55 41 virtual void getPluginInformation( 56 42 std::vector< boost::shared_ptr<const Licq::Plugin::Information> >* info) = 0; -
branches/newapi/licq/src/plugin/pluginmanagerimpl.cpp
r5921 r5924 22 22 #include "plugin/pluginmanagerimpl.h" 23 23 24 LicqDaemon::PluginManagerImpl::PluginManagerImpl(PluginCache& cache) 24 LicqDaemon::PluginManagerImpl::PluginManagerImpl(PluginCache& cache, 25 Licq::LogSink& sink) 25 26 : myCache(cache), 26 myPluginLogSink( NULL)27 myPluginLogSink(sink) 27 28 { 28 29 // Empty … … 32 33 { 33 34 // Empty 34 }35 36 void LicqDaemon::PluginManagerImpl::unloadAll()37 {38 myPlugins.clear();39 myCache.clear();40 myCache.unloadUnusedLibraries();41 }42 43 void LicqDaemon::PluginManagerImpl::setPluginLogSink(Licq::LogSink* sink)44 {45 assert(myPluginLogSink == NULL);46 myPluginLogSink = sink;47 35 } 48 36 … … 61 49 loadPlugin(const std::string& filename, int argc, char** argv) 62 50 { 63 assert(myPluginLogSink != NULL);64 65 51 const size_t index = myCache.getIndex(filename); 66 52 … … 71 57 72 58 boost::shared_ptr<PluginInstance> 73 instance(new PluginInstanceImpl(info, lib, *myPluginLogSink));59 instance(new PluginInstanceImpl(info, lib, myPluginLogSink)); 74 60 75 61 Licq::Plugin::Id id = instance->load(argc, argv); -
branches/newapi/licq/src/plugin/pluginmanagerimpl.h
r5921 r5924 25 25 #include <map> 26 26 27 namespace Licq 28 { 29 class LogSink; 30 } 31 27 32 namespace LicqDaemon 28 33 { … … 35 40 /** 36 41 * @param cache PluginCache to use. 42 * @param sink LogSink that plugins should use. 37 43 */ 38 explicit PluginManagerImpl(PluginCache& cache);44 PluginManagerImpl(PluginCache& cache, Licq::LogSink& sink); 39 45 40 46 ~PluginManagerImpl(); 41 42 void unloadAll();43 44 /**45 * Set the LogSink that plugins will log to. This must have been46 * called before the first call to loadPlugin().47 */48 void setPluginLogSink(Licq::LogSink* sink);49 47 50 48 void getPluginInformation( … … 61 59 private: 62 60 PluginCache& myCache; 63 Licq::LogSink *myPluginLogSink;61 Licq::LogSink& myPluginLogSink; 64 62 65 63 typedef std::map<Licq::Plugin::Id, -
branches/newapi/licq/src/plugin/test/pluginlibrarytest.cpp
r5921 r5924 18 18 */ 19 19 20 #include "globals.h" 20 21 #include "licq/log.h" 21 22 #include "plugin/pluginlibraryimpl.h" … … 108 109 109 110 Licq::Plugin::Setup setup; 110 setup.log = Licq::Log::getThreadLog();111 setup.log = &LicqDaemon::Globals::getDaemonLog(); 111 112 setup.argc = 1; 112 113 setup.argv = (char**)argv; -
branches/newapi/licq/src/test/log.cpp
r5906 r5924 18 18 */ 19 19 20 #include "globals.h" 20 21 #include "test/log.h" 21 22 22 Licq::Log * Licq::Log::getThreadLog()23 Licq::Log& LicqDaemon::Globals::getDaemonLog() 23 24 { 24 25 static LicqTest::Log testLog; 25 return &testLog;26 return testLog; 26 27 } -
branches/newapi/licq/src/test/log.h
r5911 r5924 30 30 /** 31 31 * A log for unit-tests that prints to std::clog. The single instance 32 * of this class is returned from Licq ::Log::getThreadLog().32 * of this class is returned from LicqDaemon::Globals::getDaemonLog(). 33 33 */ 34 34 class Log : public Licq::Log … … 49 49 ~Log() { /* Empty */ } 50 50 51 friend class Licq ::Log;51 friend class LicqDaemon::Globals; 52 52 }; 53 53 -
branches/newapi/licq/src/util/log.h
r5911 r5924 44 44 Log(const std::string& owner, Licq::LogSink* sink); 45 45 46 /**47 * Makes @a log the default log for the calling thread. @a log will48 * be automatically deleted when the thread exits. This method may49 * only be called once per thread.50 *51 * @see getThreadLog()52 */53 static void setThreadLog(const Log* log);54 55 46 // From Licq::Log 56 47 void log(Level level, const std::string& msg);
