Changeset b3078b4 in nscp
- Timestamp:
- 11/21/09 17:59:42 (4 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 01a278b
- Parents:
- 92c4b5b
- Files:
-
- 3 added
- 6 edited
-
build.cmake (added)
-
service/NSCPlugin.cpp (modified) (1 diff)
-
service/NSCPlugin.h (modified) (3 diffs)
-
service/NSClient++-2005.vcproj (modified) (1 diff)
-
service/NSClient++.cpp (modified) (6 diffs)
-
service/NSClient++.h (modified) (6 diffs)
-
service/StdAfx.h (modified) (2 diffs)
-
service/commands.hpp (added)
-
service/logger.hpp (added)
Legend:
- Unmodified
- Added
- Removed
-
service/NSCPlugin.cpp
rd05c3f0 rb3078b4 46 46 ,lastIsMsgPlugin_(false) 47 47 ,broken_(false) 48 ,plugin_id_(0) 48 49 { 49 50 plugin_id_ = ++last_plugin_id_; 50 51 } 51 52 /* -
service/NSCPlugin.h
rd05c3f0 rb3078b4 108 108 dll::dll module_; 109 109 bool broken_; 110 static unsigned int last_plugin_id_; 111 unsigned int plugin_id_; 110 112 111 113 typedef int (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f); … … 186 188 return bLoaded_; 187 189 } 190 unsigned int get_id() const { return plugin_id_; } 188 191 189 192 private: … … 195 198 }; 196 199 197 200 unsigned int NSCPlugin::last_plugin_id_ = 0; 201 202 203 -
service/NSClient++-2005.vcproj
r818b54e rb3078b4 2139 2139 </File> 2140 2140 <File 2141 RelativePath=".\commands.hpp" 2142 > 2143 </File> 2144 <File 2141 2145 RelativePath=".\include\config.h" 2142 2146 > -
service/NSClient++.cpp
rd05c3f0 rb3078b4 1060 1060 } 1061 1061 for (pluginList::size_type i=0;i<plugins_.size();++i) { 1062 NSCPlugin *p = plugins_[i];1062 plugin_type p = plugins_[i]; 1063 1063 if (!moduleList.empty()) 1064 1064 moduleList += _T(", "); 1065 moduleList += p->getModule(); 1066 if (p->getModule() == sModule) { 1067 LOG_DEBUG_STD(_T("Found module: ") + p->getName() + _T("...")); 1068 try { 1069 return p->commandLineExec(command, argLen, args); 1070 } catch (NSPluginException e) { 1071 LOG_ERROR_STD(_T("Could not execute command: ") + e.error_ + _T(" in ") + e.file_); 1072 return -1; 1065 if (p) { 1066 moduleList += p->getModule(); 1067 if (p->getModule() == sModule) { 1068 LOG_DEBUG_STD(_T("Found module: ") + p->getName() + _T("...")); 1069 try { 1070 return p->commandLineExec(command, argLen, args); 1071 } catch (NSPluginException e) { 1072 LOG_ERROR_STD(_T("Could not execute command: ") + e.error_ + _T(" in ") + e.file_); 1073 return -1; 1074 } 1073 1075 } 1074 1076 } … … 1123 1125 } 1124 1126 for (pluginList::reverse_iterator it = plugins_.rbegin(); it != plugins_.rend(); ++it) { 1125 NSCPlugin *p = *it;1126 if ( p == NULL)1127 plugin_type p = *it; 1128 if (!p) 1127 1129 continue; 1128 1130 try { … … 1146 1148 return; 1147 1149 } 1150 commands_.remove_all(); 1148 1151 for (pluginList::iterator it = plugins_.begin(); it != plugins_.end();) { 1149 NSCPlugin *p = (*it);1152 plugin_type p = (*it); 1150 1153 try { 1151 if ( p != NULL&& (unloadLoggers|| !p->isLoaded())) {1154 if (!p && (unloadLoggers|| !p->isLoaded())) { 1152 1155 it = plugins_.erase(it); 1153 delete p;1156 //delete p; 1154 1157 continue; 1155 1158 } … … 1209 1212 */ 1210 1213 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 1211 return addPlugin(new NSCPlugin(file)); 1214 plugin_type plugin(new NSCPlugin(file)); 1215 return addPlugin(plugin); 1212 1216 } 1213 1217 /** … … 1235 1239 1236 1240 std::wstring NSClientT::describeCommand(std::wstring command) { 1237 boost::shared_lock<boost::shared_mutex> readLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(5)); 1238 if (!readLock.owns_lock()) { 1239 LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 1240 return _T("Failed to get mutex when describing command: ") + command; 1241 } 1242 cmdMap::const_iterator cit = cmdDescriptions_.find(command); 1243 if (cit == cmdDescriptions_.end()) 1244 return _T("Command not found: ") + command + _T(", maybe it has not been register?"); 1245 return (*cit).second; 1241 return commands_.describe(command); 1246 1242 } 1247 1243 std::list<std::wstring> NSClientT::getAllCommandNames() { 1248 std::list<std::wstring> lst; 1249 boost::shared_lock<boost::shared_mutex> readLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(5)); 1250 if (!readLock.owns_lock()) { 1251 LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 1252 return lst; 1253 } 1254 for (cmdMap::const_iterator cit = cmdDescriptions_.begin(); cit != cmdDescriptions_.end(); ++cit) { 1255 lst.push_back((*cit).first); 1256 } 1257 return lst; 1258 } 1259 void NSClientT::registerCommand(std::wstring cmd, std::wstring desc) { 1260 boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(10)); 1261 if (!writeLock.owns_lock()) { 1262 LOG_ERROR_STD(_T("FATAL ERROR: Failed to describe command:") + cmd); 1263 return; 1264 } 1265 cmdDescriptions_[cmd] = desc; 1244 return commands_.list(); 1245 } 1246 void NSClientT::registerCommand(unsigned int id, std::wstring cmd, std::wstring desc) { 1247 return commands_.register_command(id, cmd, desc); 1266 1248 } 1267 1249 … … 1578 1560 return _T(""); 1579 1561 } 1562 1563 void NSClientT::nsclient_log_error(std::wstring file, int line, std::wstring error) { 1564 NSAPIMessage(NSCAPI::error, file.c_str(), line, error); 1565 } -
service/NSClient++.h
rd05c3f0 rb3078b4 27 27 #include <config.h> 28 28 #include <service/system_service.hpp> 29 29 30 #include "NSCPlugin.h" 31 #include "commands.hpp" 32 #include "logger.hpp" 33 30 34 //#include <nsclient_session.hpp> 31 35 … … 55 59 * 56 60 */ 57 class NSClientT /*: public nsclient_session::session_handler_interface*/ {61 class NSClientT : public nsclient::logger /*: public nsclient_session::session_handler_interface*/ { 58 62 59 63 public: … … 88 92 }; 89 93 90 typedef NSCPlugin*plugin_type;94 typedef boost::shared_ptr<NSCPlugin> plugin_type; 91 95 typedef std::vector<plugin_type> pluginList; 92 typedef std::map<std::wstring,std::wstring> cmdMap;96 //typedef std::map<std::wstring,std::wstring> cmdMap; 93 97 typedef std::list<cached_log_entry> log_cache_type; 94 98 pluginList plugins_; … … 99 103 boost::timed_mutex messageMutex; 100 104 boost::shared_mutex m_mutexRW; 101 boost::shared_mutex m_mutexRWcmdDescriptions;102 cmdMap cmdDescriptions_;105 //boost::shared_mutex m_mutexRWcmdDescriptions; 106 //cmdMap cmdDescriptions_; 103 107 typedef enum log_status {log_unknown, log_looking, log_debug, log_nodebug }; 104 108 log_status debug_; … … 114 118 bool enable_shared_session_; 115 119 120 nsclient::commands commands_; 121 116 122 117 123 public: 118 124 // c-tor, d-tor 119 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false) {}125 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this) {} 120 126 virtual ~NSClientT(void) {} 121 127 void enableDebug(bool debug = true) { … … 137 143 #endif 138 144 void service_on_session_changed(DWORD dwSessionId, bool logon, DWORD dwEventType); 145 146 147 // Logger impl 148 void nsclient_log_error(std::wstring file, int line, std::wstring error); 149 139 150 140 151 // Member functions -
service/StdAfx.h
rd05c3f0 rb3078b4 47 47 #include <NSCAPI.h> 48 48 49 #include <boost/shared_ptr.hpp> 49 50 #include <boost/thread/thread.hpp> 50 51 #include <boost/thread/locks.hpp> … … 52 53 #include <boost/algorithm/string.hpp> 53 54 #include <boost/filesystem.hpp> 55 #include <boost/foreach.hpp>
Note: See TracChangeset
for help on using the changeset viewer.








