| 1 |
#include "UNsmSystem.h" |
| 2 |
|
| 3 |
#include <cassert> |
| 4 |
#include <algorithm> |
| 5 |
#include <array> |
| 6 |
|
| 7 |
#include "../../Common/UNsmConsts.h" |
| 8 |
#include "../../Common/dummy.h" |
| 9 |
#include "../../Common/NsmInfoUtility.h" |
| 10 |
|
| 11 |
#include "nsmsgs.h" |
| 12 |
#include "UNsmCom.h" |
| 13 |
#include "ModuleUtility.h" |
| 14 |
#include "resource.h" |
| 15 |
|
| 16 |
namespace Regnessem |
| 17 |
{ |
| 18 |
namespace System |
| 19 |
{ |
| 20 |
NsmSystem g_NsmSystem; |
| 21 |
|
| 22 |
// ----------------------------------------------------------------------------- |
| 23 |
|
| 24 |
int NsmSystem::Initialize() |
| 25 |
{ |
| 26 |
// CxgĚěŹ |
| 27 |
HModulesLoaded = g_NsmCom.CreateNsmEvent(NME_SYSTEM_MODULESLOADED); |
| 28 |
HConnectionConnect = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_CONNECT); |
| 29 |
HConnectionDisconnect = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_DISCONNECT); |
| 30 |
HConnectionInfoChange = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_INFOCHANGE); |
| 31 |
HConnectionMembersAdd = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_MEMBERS_ADD); |
| 32 |
HConnectionMembersRemove = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_MEMBERS_REMOVE); |
| 33 |
HConnectionMembersInfoChange = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_MEMBERS_INFOCHANGE); |
| 34 |
HConnectionMembersInfoChanging = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_MEMBERS_INFOCHANGING); |
| 35 |
HConnectionGroupsAdd = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_GROUPS_ADD); |
| 36 |
HConnectionGroupsRemove = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_GROUPS_REMOVE); |
| 37 |
HConnectionGroupsInfoChange = g_NsmCom.CreateNsmEvent(NME_SYSTEM_CONNECTION_GROUPS_INFOCHANGE); |
| 38 |
|
| 39 |
HSessionOpen = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_OPEN); |
| 40 |
HSessionClose = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_CLOSE); |
| 41 |
HSessionInfoChange = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_INFOCHANGE); |
| 42 |
HSessionMembersAdd = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_MEMBERS_ADD); |
| 43 |
HSessionMembersRemove = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_MEMBERS_REMOVE); |
| 44 |
HSessionMembersInfoChange = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_MEMBERS_INFOCHANGE); |
| 45 |
|
| 46 |
HSessionSendMessage = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_SENDMESSAGE); |
| 47 |
HSessionReceiveMessage = g_NsmCom.CreateNsmEvent(NME_SYSTEM_SESSION_RECEIVEMESSAGE); |
| 48 |
|
| 49 |
HFileSessionOpen = g_NsmCom.CreateNsmEvent(NME_SYSTEM_FILESESSION_OPEN); |
| 50 |
HFileSessionClose = g_NsmCom.CreateNsmEvent(NME_SYSTEM_FILESESSION_CLOSE); |
| 51 |
HFileSessionInfoChange = g_NsmCom.CreateNsmEvent(NME_SYSTEM_FILESESSION_INFOCHANGE); |
| 52 |
|
| 53 |
// T[rXĚěŹ |
| 54 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_EXIT, Service::DoExit); |
| 55 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_DEBUG_PRINT, Service::DoDebugPrint); |
| 56 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ENUMPROTOCOLS, Service::DoEnumProtocols); |
| 57 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ENUMMODULES, Service::DoEnumModules); |
| 58 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_GETPLUGININFO, Service::DoGetPluginInfo); |
| 59 |
|
| 60 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_CREATE, Service::DoCreateConnection); |
| 61 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_DELETE, Service::DoDeleteConnection); |
| 62 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GETINFO, Service::DoGetConnectionInfo); |
| 63 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_SETINFO, Service::DoSetConnectionInfo); |
| 64 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_ENUM, Service::DoEnumConnections); |
| 65 |
|
| 66 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_MEMBERS_ADD, Service::DoAddMember); |
| 67 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_MEMBERS_REMOVE, Service::DoRemoveMember); |
| 68 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_MEMBERS_GETINFO, Service::DoGetMemberInfo); |
| 69 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_MEMBERS_SETINFO, Service::DoSetMemberInfo); |
| 70 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_MEMBERS_BEGINUPDATE, Service::DoBeginUpdate); |
| 71 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_MEMBERS_ENDUPDATE, Service::DoEndUpdate); |
| 72 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_MEMBERS_ENUM, Service::DoEnumMembers); |
| 73 |
|
| 74 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GROUPS_ADD, Service::DoAddGroup); |
| 75 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GROUPS_REMOVE, Service::DoRemoveGroup); |
| 76 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GROUPS_GETINFO, Service::DoGetGroupInfo); |
| 77 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GROUPS_SETINFO, Service::DoSetGroupInfo); |
| 78 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GROUPS_BEGINUPDATE, Service::DoBeginGroupsUpdate); |
| 79 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GROUPS_ENDUPDATE, Service::DoEndGroupsUpdate); |
| 80 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_GROUPS_ENUM, Service::DoEnumGroups); |
| 81 |
|
| 82 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_CREATE, Service::DoCreateSession); |
| 83 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_DELETE, Service::DoDeleteSession); |
| 84 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_GETINFO, Service::DoGetSessionInfo); |
| 85 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_SETINFO, Service::DoSetSessionInfo); |
| 86 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_ENUM, Service::DoEnumSessions); |
| 87 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_MEMBERS_ADD, Service::DoAddSessionMember); |
| 88 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_MEMBERS_REMOVE, Service::DoRemoveSessionMember); |
| 89 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_MEMBERS_GETINFO, Service::DoGetSessionMemberInfo); |
| 90 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_MEMBERS_SETINFO, Service::DoSetSessionMemberInfo); |
| 91 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_MEMBERS_BEGINUPDATE, Service::DoBeginSessionMembersUpdate); |
| 92 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_MEMBERS_ENDUPDATE, Service::DoEndSessionMembersUpdate); |
| 93 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_MEMBERS_ENUM, Service::DoEnumSessionMembers); |
| 94 |
|
| 95 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_SENDMESSAGE, Service::DoSendMessage); |
| 96 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_RECEIVEMESSAGE, Service::DoReceiveMessage); |
| 97 |
|
| 98 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_FILESESSION_CREATE, Service::DoCreateFileSession); |
| 99 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_FILESESSION_DELETE, Service::DoDeleteFileSession); |
| 100 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_FILESESSION_GETINFO, Service::DoGetFileSessionInfo); |
| 101 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_FILESESSION_SETINFO, Service::DoSetFileSessionInfo); |
| 102 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_FILESESSION_ENUM, Service::DoEnumFileSessions); |
| 103 |
|
| 104 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_UISERVICE_MAIN_ENUM, Service::DoEnumConnectionUIServiceMain); |
| 105 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_UISERVICE_MEMBER_ENUM, Service::DoEnumConnectionUIServiceMember); |
| 106 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_CONNECTION_UISERVICE_GROUP_ENUM, Service::DoEnumConnectionUIServiceGroup); |
| 107 |
|
| 108 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_UISERVICE_MAIN_ENUM, Service::DoEnumSessionUIServiceMain); |
| 109 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_SESSION_UISERVICE_MEMBER_ENUM, Service::DoEnumSessionUIServiceMember); |
| 110 |
|
| 111 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_FILESESSION_UISERVICE_MAIN_ENUM, Service::DoEnumFileSessionUIServiceMain); |
| 112 |
|
| 113 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ADDIN_UISERVICE_MAIN_ENUM, Service::DoEnumAddInUIServiceMain); |
| 114 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ADDIN_UISERVICE_MEMBER_ENUM, Service::DoEnumAddInUIServiceMember); |
| 115 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ADDIN_UISERVICE_GROUP_ENUM, Service::DoEnumAddInUIServiceGroup); |
| 116 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ADDIN_UISERVICE_TAB_ENUM, Service::DoEnumAddInUIServiceTab); |
| 117 |
|
| 118 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ADDIN_UISERVICE_SESSION_MAIN_ENUM, Service::DoEnumAddInUIServiceSessionMain); |
| 119 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ADDIN_UISERVICE_SESSION_MEMBER_ENUM, Service::DoEnumAddInUIServiceSessionMember); |
| 120 |
|
| 121 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_ADDIN_UISERVICE_FILESESSION_MAIN_ENUM, Service::DoEnumAddInUIServiceFileSessionMain); |
| 122 |
|
| 123 |
#ifndef NO_UNDOCUMENTED_REGNESSEM_API |
| 124 |
|
| 125 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_MODULES_REINITIALIZEPLUGINS, Service::DoReInitializePlugins); |
| 126 |
g_NsmCom.CreateNsmService(NMS_SYSTEM_RESTSART, Service::DoRestart); |
| 127 |
g_NsmCom.CreateNsmEvent(NME_SYSTEM_MODULESRELOADED); |
| 128 |
|
| 129 |
#endif |
| 130 |
|
| 131 |
TNsmPluginInitInfo initInfo = NsmComHelper::GetPluginInitInfo(); |
| 132 |
|
| 133 |
// W
[Ěúť |
| 134 |
const NsmPluginList &p = Plugins; |
| 135 |
for(NsmPluginList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 136 |
(*it)->Initialize(&initInfo); |
| 137 |
|
| 138 |
// SW
[ÇIšCxg |
| 139 |
g_NsmCom.NotifyEvent(HModulesLoaded, 0, 0); |
| 140 |
return 0; |
| 141 |
} |
| 142 |
|
| 143 |
int NsmSystem::Terminate() |
| 144 |
{ |
| 145 |
CloseAllFileSession(); |
| 146 |
CloseAllSession(); |
| 147 |
DisconnectAll(); |
| 148 |
|
| 149 |
const NsmPluginList &p = Plugins; |
| 150 |
for(NsmPluginList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 151 |
(*it)->Terminate(); |
| 152 |
Plugins.clear(); |
| 153 |
|
| 154 |
return 0; |
| 155 |
} |
| 156 |
|
| 157 |
// connection ÉÖAľ˝ZbVđSÄÂśé |
| 158 |
void NsmSystem::CloseRelatedSessions(const NsmConnection* connection) |
| 159 |
{ |
| 160 |
NsmThreadSessionList::AutoLock lock(Sessions); |
| 161 |
NsmSessionList &sesList = lock.List(); |
| 162 |
|
| 163 |
for(NsmSessionList::size_type i = sesList.size(); i; --i) |
| 164 |
{ |
| 165 |
const NsmSession *const session = sesList.at(i - 1).get(); |
| 166 |
|
| 167 |
if(session->Connection == connection) |
| 168 |
{ |
| 169 |
const tstring fmt = format(NMS_PROTOCOL_SESSION_CLOSE, connection->Protocol.c_str()); |
| 170 |
g_NsmCom.CallService(g_NsmCom.GetService(fmt), reinterpret_cast<WPARAM>(session), 0); |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
// SÄĚZbVđÂśé |
| 176 |
void NsmSystem::CloseAllSession() |
| 177 |
{ |
| 178 |
NsmThreadSessionList::AutoLock lock(Sessions); |
| 179 |
NsmSessionList &sesList = lock.List(); |
| 180 |
|
| 181 |
for(NsmSessionList::size_type i = sesList.size(); i; --i) |
| 182 |
{ |
| 183 |
const NsmSession *const session = sesList.at(i - 1).get(); |
| 184 |
|
| 185 |
const tstring fmt = format(NMS_PROTOCOL_SESSION_CLOSE, session->Protocol.c_str()); |
| 186 |
g_NsmCom.CallService(g_NsmCom.GetService(fmt), reinterpret_cast<WPARAM>(session), 0); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
// session ÉÖAľ˝t@CZbVđSÄÂśé |
| 191 |
void NsmSystem::CloseRelatedFileSessions(const NsmSession* session) |
| 192 |
{ |
| 193 |
NsmThreadFileSessionList::AutoLock lock(FileSessions); |
| 194 |
NsmFileSessionList &fileSesList = lock.List(); |
| 195 |
|
| 196 |
for(NsmFileSessionList::size_type i = fileSesList.size(); i; --i) |
| 197 |
{ |
| 198 |
const NsmFileSession *const fileSes = fileSesList.at(i - 1).get(); |
| 199 |
|
| 200 |
if(fileSes->Session == session) |
| 201 |
{ |
| 202 |
const tstring fmt = format(NMS_PROTOCOL_FILESESSION_CLOSE, fileSes->Protocol.c_str()); |
| 203 |
g_NsmCom.CallService(g_NsmCom.GetService(fmt), reinterpret_cast<WPARAM>(fileSes), 0); |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
// SÄĚt@CZbVđÂśé |
| 209 |
void NsmSystem::CloseAllFileSession() |
| 210 |
{ |
| 211 |
NsmThreadFileSessionList::AutoLock lock(FileSessions); |
| 212 |
NsmFileSessionList &fileSesList = lock.List(); |
| 213 |
|
| 214 |
for(NsmFileSessionList::size_type i = fileSesList.size(); i; --i) |
| 215 |
{ |
| 216 |
const NsmFileSession *const fileSes = fileSesList.at(i - 1).get(); |
| 217 |
|
| 218 |
const tstring fmt = format(NMS_PROTOCOL_FILESESSION_CLOSE, fileSes->Protocol.c_str()); |
| 219 |
g_NsmCom.CallService(g_NsmCom.GetService(fmt), reinterpret_cast<WPARAM>(fileSes), 0); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
// SÄĚRlNVđí |
| 224 |
void NsmSystem::DisconnectAll() |
| 225 |
{ |
| 226 |
NsmThreadConnectionList::AutoLock lock(Connections); |
| 227 |
NsmConnectionList &conList = lock.List(); |
| 228 |
|
| 229 |
for(NsmConnectionList::size_type i = conList.size(); i; --i) |
| 230 |
{ |
| 231 |
const NsmConnection *const connection = conList.at(i - 1).get(); |
| 232 |
|
| 233 |
const tstring fmt = format(NMS_PROTOCOL_CONNECTION_DISCONNECT, connection->Protocol.c_str()); |
| 234 |
g_NsmCom.CallService(g_NsmCom.GetService(fmt), reinterpret_cast<WPARAM>(connection), 0); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
void NsmSystem::DoConnectionChange() |
| 239 |
{ |
| 240 |
const NsmMainDebug *const wnd = g_NsmCom.DebugWindow.get(); |
| 241 |
if(OnConnectionChange != NULL && wnd != NULL) |
| 242 |
(wnd->*OnConnectionChange)(); |
| 243 |
} |
| 244 |
|
| 245 |
void NsmSystem::DoSessionChange() |
| 246 |
{ |
| 247 |
const NsmMainDebug *const wnd = g_NsmCom.DebugWindow.get(); |
| 248 |
if(OnSessionChange != NULL && wnd != NULL) |
| 249 |
(wnd->*OnSessionChange)(); |
| 250 |
} |
| 251 |
|
| 252 |
void NsmSystem::DoFileSessionChange() |
| 253 |
{ |
| 254 |
if(OnFileSessionChange) |
| 255 |
OnFileSessionChange(this); |
| 256 |
} |
| 257 |
|
| 258 |
void NsmSystem::DoModuleChange() |
| 259 |
{ |
| 260 |
const NsmMainDebug *const wnd = g_NsmCom.DebugWindow.get(); |
| 261 |
if(OnModuleChange != NULL && wnd != NULL) |
| 262 |
(wnd->*OnModuleChange)(); |
| 263 |
} |
| 264 |
|
| 265 |
void NsmSystem::SearchPlugin(const tstring &path) |
| 266 |
{ |
| 267 |
#if defined(_WINDOWS) |
| 268 |
class FindFileHandle |
| 269 |
{ |
| 270 |
public: |
| 271 |
HANDLE Handle; |
| 272 |
FindFileHandle(HANDLE handle) |
| 273 |
:Handle(handle) |
| 274 |
{ |
| 275 |
} |
| 276 |
~FindFileHandle() |
| 277 |
{ |
| 278 |
if(Handle != INVALID_HANDLE_VALUE) |
| 279 |
{ |
| 280 |
FindClose(Handle); |
| 281 |
} |
| 282 |
} |
| 283 |
}; |
| 284 |
|
| 285 |
{ |
| 286 |
WIN32_FIND_DATA fd; |
| 287 |
FindFileHandle h(FindFirstFile(path.c_str(), &fd)); |
| 288 |
|
| 289 |
if(h.Handle == INVALID_HANDLE_VALUE) |
| 290 |
return; |
| 291 |
|
| 292 |
const tstring dir = ExtractFilePath(path); |
| 293 |
|
| 294 |
do { |
| 295 |
NsmPluginListSub t(new NsmPlugin(dir + fd.cFileName)); |
| 296 |
|
| 297 |
if(t->IsLoaded() && |
| 298 |
t->PluginInfo.ApiVersion == NSM_API_VERSION && |
| 299 |
t->PluginInfo.ModuleName != NMM_SYSTEM && |
| 300 |
std::find_if(Plugins.begin(), Plugins.end(), |
| 301 |
NsmPlugin::FindByModuleName(t->PluginInfo.ModuleName)) == Plugins.end()) |
| 302 |
{ |
| 303 |
Plugins.push_back(t); |
| 304 |
} |
| 305 |
} while(FindNextFile(h.Handle, &fd)); |
| 306 |
} |
| 307 |
|
| 308 |
#else |
| 309 |
// [TODO]´â貍šB@NŠÜĆŕČR[hÉźľÄ |
| 310 |
FILE*fp = popen(("dir " + path).c_str(), "r"); |
| 311 |
char buf[256]; |
| 312 |
while(fscanf(fp, "%255s", buf) == 1){ |
| 313 |
std::unique_ptr<TNsmPlugin> t(buf)); |
| 314 |
|
| 315 |
if(t->DllHandle != NULL && |
| 316 |
t->PluginInfo.ApiVersion == NSM_API_VERSION && |
| 317 |
t->PluginInfo.ModuleName != NMM_SYSTEM && |
| 318 |
std::find_if(Plugins.begin(), Plugins.end(), |
| 319 |
std::bind2nd(TNsmPluginListFindByModuleName(), t->PluginInfo.ModuleName)) == Plugins.end()) |
| 320 |
{ |
| 321 |
Plugins.push_back(TNsmPluginListSub(t.release())); |
| 322 |
} |
| 323 |
std::cout << buf << std::endl; |
| 324 |
} |
| 325 |
pclose(fp); |
| 326 |
#endif |
| 327 |
DoModuleChange(); |
| 328 |
} |
| 329 |
|
| 330 |
// ----------------------------------------------------------------------------- |
| 331 |
|
| 332 |
LONG_PTR Service::DoExit(WPARAM /* wParam */, LPARAM /* lParam */) |
| 333 |
{ |
| 334 |
#ifdef _WINDOWS |
| 335 |
Application::Terminate(); |
| 336 |
#else |
| 337 |
Application.Terminate(); |
| 338 |
#endif |
| 339 |
return 0; |
| 340 |
} |
| 341 |
|
| 342 |
LONG_PTR Service::DoDebugPrint(WPARAM wParam, LPARAM /* lParam */) |
| 343 |
{ |
| 344 |
if(wParam) |
| 345 |
g_NsmCom.DoLog(c2t(reinterpret_cast<char *>(wParam)), true); |
| 346 |
|
| 347 |
return 0; |
| 348 |
} |
| 349 |
|
| 350 |
LONG_PTR Service::DoEnumProtocols(WPARAM wParam, LPARAM lParam) |
| 351 |
{ |
| 352 |
const NsmPluginList &p = g_NsmSystem.Plugins; |
| 353 |
for(NsmPluginList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 354 |
{ |
| 355 |
const tstring moduleName = (*it)->PluginInfo.ModuleName; |
| 356 |
if(Common::ModuleUtility::ExtractModuleType(moduleName) == NMM_PROTOCOL) |
| 357 |
{ |
| 358 |
const tstring protcolName = Common::ModuleUtility::ExtractProtocolName(moduleName); |
| 359 |
reinterpret_cast<TEnumProtocolCallback>(wParam)(t2c(protcolName).c_str(), lParam); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
return 0; |
| 364 |
} |
| 365 |
|
| 366 |
LONG_PTR Service::DoEnumModules(WPARAM wParam, LPARAM lParam) |
| 367 |
{ |
| 368 |
const NsmPluginList &p = g_NsmSystem.Plugins; |
| 369 |
for(NsmPluginList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 370 |
reinterpret_cast<TEnumModuleCallback>(wParam)(t2c((*it)->PluginInfo.ModuleName).c_str(), lParam); |
| 371 |
|
| 372 |
return 0; |
| 373 |
} |
| 374 |
|
| 375 |
LONG_PTR Service::DoGetPluginInfo(WPARAM wParam, LPARAM /* lParam */ ) |
| 376 |
{ |
| 377 |
const PNsmPluginInfo pin = reinterpret_cast<PNsmPluginInfo>(wParam); |
| 378 |
|
| 379 |
if(pin->nBufferSize < 1) |
| 380 |
return 0; |
| 381 |
|
| 382 |
const NsmPluginList &p = g_NsmSystem.Plugins; |
| 383 |
NsmPluginList::const_iterator it = |
| 384 |
std::find_if(p.begin(), p.end(), NsmPlugin::FindByModuleName(c2t(pin->lpModuleName))); |
| 385 |
|
| 386 |
if(it != p.end()) |
| 387 |
return (*it)->GetPluginInfo(pin->nInfoNo, pin->lpBuffer, pin->nBufferSize); |
| 388 |
|
| 389 |
if(c2t(pin->lpModuleName) != NMM_SYSTEM) |
| 390 |
return 0; |
| 391 |
|
| 392 |
tstring infoStr; |
| 393 |
|
| 394 |
switch(pin->nInfoNo) |
| 395 |
{ |
| 396 |
case NMPI_APIVER: |
| 397 |
infoStr = NSM_API_VERSION; |
| 398 |
break; |
| 399 |
case NMPI_MODULENAME: |
| 400 |
infoStr = NMM_SYSTEM; |
| 401 |
break; |
| 402 |
case NMPI_TITLE: |
| 403 |
infoStr = Application::Title; |
| 404 |
break; |
| 405 |
case NMPI_DESCRIPTION: |
| 406 |
infoStr = TEXT(RES_FILE_DESCRIPTION); |
| 407 |
break; |
| 408 |
case NMPI_AUTHOR: |
| 409 |
infoStr = TEXT(RES_COMPANY_NAME); |
| 410 |
break; |
| 411 |
case NMPI_COPYRIGHT: |
| 412 |
infoStr = TEXT(RES_LEGAL_COPYRIGHT); |
| 413 |
break; |
| 414 |
case NMPI_PLUGINVER: |
| 415 |
infoStr = RES_FILE_VERSION_T; |
| 416 |
break; |
| 417 |
default: |
| 418 |
return 0; |
| 419 |
} |
| 420 |
|
| 421 |
std::string result = t2c(infoStr); |
| 422 |
if(result.empty()) |
| 423 |
return 0; |
| 424 |
|
| 425 |
std::string::size_type len = std::min<std::string::size_type>(pin->nBufferSize - 1, result.size()); |
| 426 |
|
| 427 |
result.resize(len); |
| 428 |
|
| 429 |
#if defined(_MSC_VER) && !defined(WINCE) |
| 430 |
strcpy_s(pin->lpBuffer, pin->nBufferSize, result.c_str()); |
| 431 |
#else |
| 432 |
strcpy(pin->lpBuffer, result.c_str()); |
| 433 |
#endif |
| 434 |
|
| 435 |
return static_cast<LONG_PTR>(len); |
| 436 |
} |
| 437 |
|
| 438 |
// Connection ------------------------------------------------------------------ |
| 439 |
|
| 440 |
LONG_PTR Service::DoCreateConnection(WPARAM wParam, LPARAM lParam) |
| 441 |
{ |
| 442 |
if(!wParam) |
| 443 |
return 0; |
| 444 |
|
| 445 |
NsmConnectionListSub result; |
| 446 |
{ |
| 447 |
NsmThreadConnectionList::AutoLock lock(g_NsmSystem.Connections); |
| 448 |
NsmConnectionList &p = lock.List(); |
| 449 |
|
| 450 |
result.reset(new NsmConnection( |
| 451 |
c2t(reinterpret_cast<char*>(wParam)), |
| 452 |
c2t(reinterpret_cast<char*>(lParam ? lParam : wParam)))); |
| 453 |
|
| 454 |
p.push_back(result); |
| 455 |
} |
| 456 |
|
| 457 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionConnect, reinterpret_cast<WPARAM>(result.get()), 0); |
| 458 |
g_NsmSystem.DoConnectionChange(); |
| 459 |
|
| 460 |
return reinterpret_cast<LONG_PTR>(result.get()); |
| 461 |
} |
| 462 |
|
| 463 |
LONG_PTR Service::DoDeleteConnection(WPARAM wParam, LPARAM /* lParam */ ) |
| 464 |
{ |
| 465 |
{ |
| 466 |
NsmThreadConnectionList::AutoLock lock(g_NsmSystem.Connections); |
| 467 |
NsmConnectionList &p = lock.List(); |
| 468 |
|
| 469 |
NsmConnectionList::iterator it = |
| 470 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 471 |
if(it == p.end()) |
| 472 |
return -1; |
| 473 |
|
| 474 |
g_NsmSystem.CloseRelatedSessions(it->get()); |
| 475 |
p.erase(it); |
| 476 |
} |
| 477 |
|
| 478 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionDisconnect, wParam, 0); |
| 479 |
g_NsmSystem.DoConnectionChange(); |
| 480 |
|
| 481 |
return 1; |
| 482 |
} |
| 483 |
|
| 484 |
LONG_PTR Service::DoGetConnectionInfo(WPARAM wParam, LPARAM lParam) |
| 485 |
{ |
| 486 |
const NsmConnection *const connection = reinterpret_cast<NsmConnection *>(wParam); |
| 487 |
const PNsmConnectionInfo pin = reinterpret_cast<PNsmConnectionInfo>(lParam); |
| 488 |
|
| 489 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 490 |
const NsmConnectionList &p = lock.List(); |
| 491 |
|
| 492 |
if(std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(connection)) == p.end()) |
| 493 |
return 0; |
| 494 |
|
| 495 |
switch(pin->nInfoKey) |
| 496 |
{ |
| 497 |
case NMCI_PROTOCOL: |
| 498 |
//HACK:API 2.3 |
| 499 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, t2c(connection->Protocol)); |
| 500 |
case NMCI_CAPTION: |
| 501 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, connection->Caption); |
| 502 |
case NMCI_STATUS: |
| 503 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, connection->Status); |
| 504 |
case NMCI_USER_NAME: |
| 505 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, connection->User.Name); |
| 506 |
case NMCI_USER_ACCOUNT: |
| 507 |
//HACK:API 2.3 |
| 508 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, t2c(connection->User.Account)); |
| 509 |
case NMCI_USER_STATUS: |
| 510 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, connection->User.Status()); |
| 511 |
case NMCI_USER_STATUSSTRING: |
| 512 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, connection->User.StatusStr); |
| 513 |
case NMCI_USER_BUSYNESS: |
| 514 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, connection->User.Busyness); |
| 515 |
case NMCI_USER_MAILSTATUS: |
| 516 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, connection->User.MailStatus); |
| 517 |
case NMCI_USER_COMMENT: |
| 518 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, connection->User.Comment); |
| 519 |
// MSN7ACRĆFriendly p[^ |
| 520 |
case NMCI_USER_TILE: |
| 521 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, connection->User.FilePath); |
| 522 |
case NMCI_USER_FRIENDLY: |
| 523 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, connection->User.Friendly); |
| 524 |
case NMCI_DISABLE_TILE: |
| 525 |
return Common::NsmInfoUtility::BoolToNsmInfo(pin->lpInfo, connection->User.DisableTile); |
| 526 |
default: |
| 527 |
assert(0); |
| 528 |
return 0; |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
LONG_PTR Service::DoSetConnectionInfo(WPARAM wParam, LPARAM lParam) |
| 533 |
{ |
| 534 |
NsmConnection *const connection = reinterpret_cast<NsmConnection *>(wParam); |
| 535 |
|
| 536 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 537 |
const NsmConnectionList &p = lock.List(); |
| 538 |
|
| 539 |
if(std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(connection)) == p.end()) |
| 540 |
return 0; |
| 541 |
|
| 542 |
const TNsmConnectionInfo &pin = *reinterpret_cast<PNsmConnectionInfo>(lParam); |
| 543 |
switch(pin.nInfoKey) |
| 544 |
{ |
| 545 |
case NMCI_PROTOCOL: |
| 546 |
//ReadOnly |
| 547 |
//AConnection->Protocol = NsmInfoUtility::NsmInfoToTStr(pin->lpInfo); |
| 548 |
break; |
| 549 |
case NMCI_CAPTION: |
| 550 |
connection->Caption = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 551 |
break; |
| 552 |
case NMCI_STATUS: |
| 553 |
connection->Status = Common::NsmInfoUtility::NsmInfoToInt(pin.lpInfo); |
| 554 |
break; |
| 555 |
case NMCI_USER_ACCOUNT: |
| 556 |
connection->User.Account = Common::NsmInfoUtility::NsmInfoToStr(pin.lpInfo); |
| 557 |
break; |
| 558 |
case NMCI_USER_NAME: |
| 559 |
connection->User.Name = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 560 |
break; |
| 561 |
case NMCI_USER_STATUS: |
| 562 |
connection->User.Status(Common::NsmInfoUtility::NsmInfoToInt(pin.lpInfo)); |
| 563 |
break; |
| 564 |
case NMCI_USER_STATUSSTRING: |
| 565 |
connection->User.StatusStr = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 566 |
break; |
| 567 |
case NMCI_USER_BUSYNESS: |
| 568 |
connection->User.Busyness = Common::NsmInfoUtility::NsmInfoToInt(pin.lpInfo); |
| 569 |
break; |
| 570 |
case NMCI_USER_MAILSTATUS: |
| 571 |
connection->User.MailStatus = Common::NsmInfoUtility::NsmInfoToInt(pin.lpInfo); |
| 572 |
break; |
| 573 |
case NMCI_USER_COMMENT: |
| 574 |
connection->User.Comment = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 575 |
// MSN7\ŚACR |
| 576 |
break; |
| 577 |
case NMCI_USER_TILE: |
| 578 |
connection->User.FilePath = Common::NsmInfoUtility::NsmInfoToStr(pin.lpInfo); |
| 579 |
break; |
| 580 |
case NMCI_USER_FRIENDLY: |
| 581 |
connection->User.Friendly = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 582 |
break; |
| 583 |
case NMCI_DISABLE_TILE: |
| 584 |
connection->User.DisableTile = Common::NsmInfoUtility::NsmInfoToBool(pin.lpInfo); |
| 585 |
break; |
| 586 |
default: |
| 587 |
assert(0); |
| 588 |
break; |
| 589 |
} |
| 590 |
|
| 591 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionInfoChange, wParam, lParam); |
| 592 |
g_NsmSystem.DoConnectionChange(); |
| 593 |
return 1; |
| 594 |
} |
| 595 |
|
| 596 |
LONG_PTR Service::DoEnumConnections(WPARAM wParam, LPARAM lParam) |
| 597 |
{ |
| 598 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 599 |
const NsmConnectionList &p = lock.List(); |
| 600 |
|
| 601 |
for(NsmConnectionList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 602 |
reinterpret_cast<TEnumConnectionCallback>(wParam)(reinterpret_cast<HNsmConnection>(it->get()), lParam); |
| 603 |
|
| 604 |
return 0; |
| 605 |
} |
| 606 |
|
| 607 |
// ----------------------------------------------------------------------------- |
| 608 |
|
| 609 |
LONG_PTR Service::DoAddMember(WPARAM wParam, LPARAM lParam) |
| 610 |
{ |
| 611 |
if(!lParam) |
| 612 |
return 0; |
| 613 |
|
| 614 |
{ |
| 615 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 616 |
const NsmConnectionList &p = lock.List(); |
| 617 |
NsmConnectionList::const_iterator it = |
| 618 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 619 |
if(it == p.end()) |
| 620 |
return 0; |
| 621 |
|
| 622 |
const TAddMemberInfo &pin = *reinterpret_cast<PAddMemberInfo>(lParam); |
| 623 |
|
| 624 |
if(!pin.lpAccount) |
| 625 |
return 0; |
| 626 |
|
| 627 |
NsmMemberListSub q(new NsmMember(c2t(pin.lpAccount))); |
| 628 |
|
| 629 |
NsmMemberList &list = (*it)->SelectList(pin.nListKind); |
| 630 |
|
| 631 |
if(!list.insert(NsmMemberList::value_type(q->Account, q)).second) |
| 632 |
return 0; |
| 633 |
} |
| 634 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionMembersAdd, wParam, lParam); |
| 635 |
return 1; |
| 636 |
} |
| 637 |
|
| 638 |
LONG_PTR Service::DoRemoveMember(WPARAM wParam, LPARAM lParam) |
| 639 |
{ |
| 640 |
{ |
| 641 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 642 |
const NsmConnectionList &p = lock.List(); |
| 643 |
NsmConnectionList::const_iterator it = |
| 644 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 645 |
if(it == p.end()) |
| 646 |
return 0; |
| 647 |
|
| 648 |
NsmMemberList &list = (*it)->SelectList(reinterpret_cast<PNsmMemberInfo>(lParam)->nListKind); |
| 649 |
NsmMemberList::iterator it2 = list.find(c2t(reinterpret_cast<PRemoveMemberInfo>(lParam)->lpAccount)); |
| 650 |
if(it2 == list.end()) |
| 651 |
return 0; |
| 652 |
|
| 653 |
list.erase(it2); |
| 654 |
} |
| 655 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionMembersRemove, wParam, lParam); |
| 656 |
return 1; |
| 657 |
} |
| 658 |
|
| 659 |
LONG_PTR Service::DoSetMemberInfo(WPARAM wParam, LPARAM lParam) |
| 660 |
{ |
| 661 |
const TNsmMemberInfo &MemberInfo = *reinterpret_cast<PNsmMemberInfo>(lParam); |
| 662 |
{ |
| 663 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 664 |
const NsmConnectionList &p = lock.List(); |
| 665 |
NsmConnectionList::const_iterator it = |
| 666 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 667 |
if(it == p.end()) |
| 668 |
return 0; |
| 669 |
|
| 670 |
const NsmMemberList &list = (*it)->SelectList(reinterpret_cast<PNsmMemberInfo>(lParam)->nListKind); |
| 671 |
NsmMemberList::const_iterator it2 = list.find(c2t(reinterpret_cast<PRemoveMemberInfo>(lParam)->lpAccount)); |
| 672 |
if(it2 == list.end()) |
| 673 |
return 0; |
| 674 |
|
| 675 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionMembersInfoChanging, wParam, lParam); |
| 676 |
NsmMember &Member = *it2->second; |
| 677 |
switch(MemberInfo.nInfoKey) |
| 678 |
{ |
| 679 |
case NMMI_ACCOUNT: |
| 680 |
Member.Account = Common::NsmInfoUtility::NsmInfoToStr(MemberInfo.lpInfo); |
| 681 |
break; |
| 682 |
case NMMI_NAME: |
| 683 |
Member.Name = Common::NsmInfoUtility::NsmInfoToStrW(MemberInfo.lpInfo); |
| 684 |
break; |
| 685 |
case NMMI_STATUS: |
| 686 |
Member.Status(Common::NsmInfoUtility::NsmInfoToInt(MemberInfo.lpInfo)); |
| 687 |
break; |
| 688 |
case NMMI_STATUSSTRING: |
| 689 |
Member.StatusStr = Common::NsmInfoUtility::NsmInfoToStrW(MemberInfo.lpInfo); |
| 690 |
break; |
| 691 |
case NMMI_BUSYNESS: |
| 692 |
Member.Busyness = Common::NsmInfoUtility::NsmInfoToInt(MemberInfo.lpInfo); |
| 693 |
break; |
| 694 |
case NMMI_GROUPID: |
| 695 |
Member.Group = Common::NsmInfoUtility::NsmInfoToInt(MemberInfo.lpInfo); |
| 696 |
break; |
| 697 |
case NMMI_HINT: |
| 698 |
Member.Hint = Common::NsmInfoUtility::NsmInfoToStrW(MemberInfo.lpInfo); |
| 699 |
break; |
| 700 |
case NMMI_TYPING: |
| 701 |
Member.Typing = Common::NsmInfoUtility::NsmInfoToBool(MemberInfo.lpInfo); |
| 702 |
break; |
| 703 |
case NMMI_COMMENT: |
| 704 |
Member.Comment = Common::NsmInfoUtility::NsmInfoToStrW(MemberInfo.lpInfo); |
| 705 |
break; |
| 706 |
case NMMI_TILE: |
| 707 |
Member.UserTile = Common::NsmInfoUtility::NsmInfoToStrW(MemberInfo.lpInfo); |
| 708 |
break; |
| 709 |
default: |
| 710 |
assert(0); |
| 711 |
break; |
| 712 |
} |
| 713 |
} |
| 714 |
if((MemberInfo.nFlags & NMIF_NOCHANGEEVENT) == 0) |
| 715 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionMembersInfoChange, wParam, lParam); |
| 716 |
return 1; |
| 717 |
} |
| 718 |
|
| 719 |
LONG_PTR Service::DoGetMemberInfo(WPARAM wParam, LPARAM lParam) |
| 720 |
{ |
| 721 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 722 |
const NsmConnectionList &p = lock.List(); |
| 723 |
NsmConnectionList::const_iterator it = |
| 724 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 725 |
if(it == p.end()) |
| 726 |
return 0; |
| 727 |
|
| 728 |
const PNsmMemberInfo pin = reinterpret_cast<PNsmMemberInfo>(lParam); |
| 729 |
const NsmMemberList &list = (*it)->SelectList(pin->nListKind); |
| 730 |
NsmMemberList::const_iterator it2 = list.find(c2t(pin->lpAccount)); |
| 731 |
if(it2 == list.end()) |
| 732 |
return 0; |
| 733 |
|
| 734 |
const NsmMember &Member = *it2->second; |
| 735 |
switch(pin->nInfoKey) |
| 736 |
{ |
| 737 |
case NMMI_ACCOUNT: |
| 738 |
//HACK:API 2.3 |
| 739 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, t2c(Member.Account)); |
| 740 |
case NMMI_NAME: |
| 741 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.Name); |
| 742 |
case NMMI_STATUS: |
| 743 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, Member.Status()); |
| 744 |
case NMMI_STATUSSTRING: |
| 745 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.StatusStr); |
| 746 |
case NMMI_BUSYNESS: |
| 747 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, Member.Busyness); |
| 748 |
case NMMI_GROUPID: |
| 749 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, Member.Group); |
| 750 |
case NMMI_HINT: |
| 751 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.Hint); |
| 752 |
case NMMI_TYPING: |
| 753 |
return Common::NsmInfoUtility::BoolToNsmInfo(pin->lpInfo, Member.Typing); |
| 754 |
case NMMI_COMMENT: |
| 755 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.Comment); |
| 756 |
case NMMI_TILE: |
| 757 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.UserTile); |
| 758 |
default: |
| 759 |
assert(0); |
| 760 |
return 0; |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
LONG_PTR Service::DoEnumMembers(WPARAM wParam, LPARAM lParam) |
| 765 |
{ |
| 766 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 767 |
const NsmConnectionList &p = lock.List(); |
| 768 |
|
| 769 |
NsmConnectionList::const_iterator it = |
| 770 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 771 |
|
| 772 |
if(it == p.end()) |
| 773 |
return 0; |
| 774 |
|
| 775 |
const TEnumMemberInfo &pin = *reinterpret_cast<PEnumMemberInfo>(lParam); |
| 776 |
const NsmMemberList &list = (*it)->SelectList(pin.nListKind); |
| 777 |
|
| 778 |
for(NsmMemberList::const_iterator it2 = list.begin(); it2 != list.end(); ++it2) |
| 779 |
{ |
| 780 |
const NsmMember &Member = *it2->second; |
| 781 |
pin.lpCallBackProc(t2c(Member.Account).c_str(), pin.nData); |
| 782 |
} |
| 783 |
return 0; |
| 784 |
} |
| 785 |
|
| 786 |
LONG_PTR Service::DoBeginUpdate(WPARAM /* wParam */, LPARAM /* lParam */ ) |
| 787 |
{ |
| 788 |
return 0; |
| 789 |
} |
| 790 |
|
| 791 |
LONG_PTR Service::DoEndUpdate(WPARAM /* wParam */, LPARAM /* lParam */ ) |
| 792 |
{ |
| 793 |
return 0; |
| 794 |
} |
| 795 |
|
| 796 |
// Group ----------------------------------------------------------------------- |
| 797 |
|
| 798 |
LONG_PTR Service::DoAddGroup(WPARAM wParam, LPARAM lParam) |
| 799 |
{ |
| 800 |
{ |
| 801 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 802 |
const NsmConnectionList &p = lock.List(); |
| 803 |
NsmConnectionList::const_iterator it = |
| 804 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 805 |
if(it == p.end()) |
| 806 |
return 0; |
| 807 |
|
| 808 |
NsmGroupList &group = (*it)->Groups; |
| 809 |
|
| 810 |
if(std::find_if(group.begin(), group.end(), NsmGroup::FindById(static_cast<int>(lParam))) != group.end()) |
| 811 |
return 0; |
| 812 |
|
| 813 |
group.push_back(NsmGroupListSub(new NsmGroup(static_cast<int>(lParam)))); |
| 814 |
} |
| 815 |
|
| 816 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionGroupsAdd, wParam, lParam); |
| 817 |
return 1; |
| 818 |
} |
| 819 |
|
| 820 |
LONG_PTR Service::DoRemoveGroup(WPARAM wParam, LPARAM lParam) |
| 821 |
{ |
| 822 |
{ |
| 823 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 824 |
const NsmConnectionList &p = lock.List(); |
| 825 |
NsmConnectionList::const_iterator it = |
| 826 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 827 |
if(it == p.end()) |
| 828 |
return 0; |
| 829 |
|
| 830 |
NsmGroupList::iterator it2 = |
| 831 |
std::find_if((*it)->Groups.begin(), (*it)->Groups.end(), NsmGroup::FindById(static_cast<int>(lParam))); |
| 832 |
if(it2 == (*it)->Groups.end()) |
| 833 |
return 0; |
| 834 |
|
| 835 |
(*it)->Groups.erase(it2); |
| 836 |
} |
| 837 |
|
| 838 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionGroupsRemove, wParam, lParam); |
| 839 |
return 1; |
| 840 |
} |
| 841 |
|
| 842 |
LONG_PTR Service::DoSetGroupInfo(WPARAM wParam, LPARAM lParam) |
| 843 |
{ |
| 844 |
TNsmGroupInfo & GroupInfo = *reinterpret_cast<PNsmGroupInfo>(lParam); |
| 845 |
{ |
| 846 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 847 |
const NsmConnectionList &p = lock.List(); |
| 848 |
NsmConnectionList::const_iterator it = |
| 849 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 850 |
if(it == p.end()) |
| 851 |
return 0; |
| 852 |
|
| 853 |
NsmGroupList::iterator it2 = |
| 854 |
std::find_if((*it)->Groups.begin(), (*it)->Groups.end(), NsmGroup::FindById(GroupInfo.nGroupId)); |
| 855 |
if(it2 == (*it)->Groups.end()) |
| 856 |
return 0; |
| 857 |
|
| 858 |
switch(reinterpret_cast<PNsmGroupInfo>(lParam)->nInfoKey) |
| 859 |
{ |
| 860 |
case NMGI_ID: |
| 861 |
(*it2)->Id = Common::NsmInfoUtility::NsmInfoToInt(GroupInfo.lpInfo); |
| 862 |
break; |
| 863 |
case NMGI_NAME: |
| 864 |
(*it2)->Name = Common::NsmInfoUtility::NsmInfoToStrW(GroupInfo.lpInfo); |
| 865 |
break; |
| 866 |
case NMGI_EXPANDED: |
| 867 |
(*it2)->Expanded = Common::NsmInfoUtility::NsmInfoToBool(GroupInfo.lpInfo); |
| 868 |
break; |
| 869 |
default: |
| 870 |
assert(0); |
| 871 |
break; |
| 872 |
} |
| 873 |
} |
| 874 |
if((GroupInfo.nFlags & NMIF_NOCHANGEEVENT) == 0) |
| 875 |
g_NsmCom.NotifyEvent(g_NsmSystem.HConnectionGroupsInfoChange, wParam, lParam); |
| 876 |
return 1; |
| 877 |
} |
| 878 |
|
| 879 |
LONG_PTR Service::DoGetGroupInfo(WPARAM wParam, LPARAM lParam) |
| 880 |
{ |
| 881 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 882 |
const NsmConnectionList &p = lock.List(); |
| 883 |
NsmConnectionList::const_iterator it = |
| 884 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 885 |
if(it == p.end()) |
| 886 |
return 0; |
| 887 |
|
| 888 |
PNsmGroupInfo pin = reinterpret_cast<PNsmGroupInfo>(lParam); |
| 889 |
|
| 890 |
NsmGroupList::iterator it2 = |
| 891 |
std::find_if((*it)->Groups.begin(), (*it)->Groups.end(), NsmGroup::FindById(pin->nGroupId)); |
| 892 |
if(it2 == (*it)->Groups.end()) |
| 893 |
return 0; |
| 894 |
|
| 895 |
switch(pin->nInfoKey) |
| 896 |
{ |
| 897 |
case NMGI_ID: |
| 898 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, (*it2)->Id); |
| 899 |
case NMGI_NAME: |
| 900 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, (*it2)->Name); |
| 901 |
case NMGI_EXPANDED: |
| 902 |
return Common::NsmInfoUtility::BoolToNsmInfo(pin->lpInfo, (*it2)->Expanded); |
| 903 |
default: |
| 904 |
break; |
| 905 |
} |
| 906 |
assert(0); |
| 907 |
return 0; |
| 908 |
} |
| 909 |
|
| 910 |
LONG_PTR Service::DoEnumGroups(WPARAM wParam, LPARAM lParam) |
| 911 |
{ |
| 912 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 913 |
const NsmConnectionList &p = lock.List(); |
| 914 |
NsmConnectionList::const_iterator it = |
| 915 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 916 |
if(it == p.end()) |
| 917 |
return 0; |
| 918 |
|
| 919 |
const NsmGroupList &gList = (*it)->Groups; |
| 920 |
for(NsmGroupList::const_iterator it2 = gList.begin(); it2 != gList.end(); ++it2) |
| 921 |
{ |
| 922 |
PEnumGroupInfo pin = reinterpret_cast<PEnumGroupInfo>(lParam); |
| 923 |
pin->lpCallBackProc((*it2)->Id, pin->nData); |
| 924 |
} |
| 925 |
|
| 926 |
return 0; |
| 927 |
} |
| 928 |
|
| 929 |
LONG_PTR Service::DoBeginGroupsUpdate(WPARAM /* wParam */, LPARAM /* lParam */) |
| 930 |
{ |
| 931 |
return 0; |
| 932 |
} |
| 933 |
|
| 934 |
LONG_PTR Service::DoEndGroupsUpdate(WPARAM /* wParam */, LPARAM /* lParam */) |
| 935 |
{ |
| 936 |
return 0; |
| 937 |
} |
| 938 |
|
| 939 |
// Session --------------------------------------------------------------------- |
| 940 |
|
| 941 |
LONG_PTR Service::DoCreateSession(WPARAM wParam, LPARAM lParam) |
| 942 |
{ |
| 943 |
NsmSessionListSub result; |
| 944 |
{ |
| 945 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 946 |
const NsmConnectionList &p = lock.List(); |
| 947 |
NsmConnectionList::const_iterator it = |
| 948 |
std::find_if(p.begin(), p.end(), NsmConnection::FindByHandle(reinterpret_cast<NsmConnection *>(wParam))); |
| 949 |
if(it == p.end()) |
| 950 |
return 0; |
| 951 |
|
| 952 |
NsmThreadSessionList::AutoLock lock2(g_NsmSystem.Sessions); |
| 953 |
NsmSessionList &p2 = lock2.List(); |
| 954 |
|
| 955 |
result.reset(new NsmSession(it->get(), (*it)->Protocol)); |
| 956 |
|
| 957 |
p2.push_back(result); |
| 958 |
} |
| 959 |
|
| 960 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionOpen, reinterpret_cast<WPARAM>(result.get()), lParam); |
| 961 |
g_NsmSystem.DoSessionChange(); |
| 962 |
|
| 963 |
return reinterpret_cast<LONG_PTR>(result.get()); |
| 964 |
} |
| 965 |
|
| 966 |
LONG_PTR Service::DoDeleteSession(WPARAM wParam, LPARAM /* lParam */) |
| 967 |
{ |
| 968 |
{ |
| 969 |
NsmThreadSessionList::AutoLock lock(g_NsmSystem.Sessions); |
| 970 |
NsmSessionList &p = lock.List(); |
| 971 |
|
| 972 |
NsmSessionList::iterator it = |
| 973 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 974 |
if(it == p.end()) |
| 975 |
return -1; |
| 976 |
|
| 977 |
g_NsmSystem.CloseRelatedFileSessions(it->get()); |
| 978 |
p.erase(it); |
| 979 |
} |
| 980 |
|
| 981 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionClose, wParam, 0); |
| 982 |
g_NsmSystem.DoSessionChange(); |
| 983 |
return 1; |
| 984 |
} |
| 985 |
|
| 986 |
LONG_PTR Service::DoGetSessionInfo(WPARAM wParam, LPARAM lParam) |
| 987 |
{ |
| 988 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 989 |
const NsmSessionList &p = lock.List(); |
| 990 |
|
| 991 |
NsmSessionList::const_iterator it = |
| 992 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 993 |
if(it == p.end()) |
| 994 |
return 0; |
| 995 |
|
| 996 |
const NsmSession &session = *reinterpret_cast<NsmSession *>(wParam); |
| 997 |
const PNsmSessionInfo pin = reinterpret_cast<PNsmSessionInfo>(lParam); |
| 998 |
switch(pin->nInfoKey) |
| 999 |
{ |
| 1000 |
case NMSI_CAPTION: |
| 1001 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, session.Caption); |
| 1002 |
case NMSI_STATUS: |
| 1003 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, session.Status); |
| 1004 |
case NMSI_CONNECTION: |
| 1005 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, reinterpret_cast<INT32>(session.Connection)); |
| 1006 |
case NMSI_PROTOCOL: |
| 1007 |
//HACK:API 2.3 |
| 1008 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, t2c(session.Protocol)); |
| 1009 |
case NMSI_VISIBLE: |
| 1010 |
return Common::NsmInfoUtility::BoolToNsmInfo(pin->lpInfo, session.Visible); |
| 1011 |
default: |
| 1012 |
assert(0); |
| 1013 |
return 0; |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
LONG_PTR Service::DoSetSessionInfo(WPARAM wParam, LPARAM lParam) |
| 1018 |
{ |
| 1019 |
{ |
| 1020 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1021 |
const NsmSessionList &p = lock.List(); |
| 1022 |
|
| 1023 |
NsmSessionList::const_iterator it = |
| 1024 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1025 |
if(it == p.end()) |
| 1026 |
return 0; |
| 1027 |
|
| 1028 |
NsmSession &session = *reinterpret_cast<NsmSession *>(wParam); |
| 1029 |
const TNsmSessionInfo *const pin = reinterpret_cast<PNsmSessionInfo>(lParam); |
| 1030 |
switch(pin->nInfoKey) |
| 1031 |
{ |
| 1032 |
case NMSI_CAPTION: |
| 1033 |
session.Caption = Common::NsmInfoUtility::NsmInfoToStrW(pin->lpInfo); |
| 1034 |
break; |
| 1035 |
case NMSI_STATUS: |
| 1036 |
session.Status = Common::NsmInfoUtility::NsmInfoToInt(pin->lpInfo); |
| 1037 |
break; |
| 1038 |
case NMSI_CONNECTION: |
| 1039 |
//ReadOnly |
| 1040 |
//ASession.Connection = TNsmConnection(NsmInfoToInt(PNsmSessionInfo(lParam)->lpInfo)); |
| 1041 |
break; |
| 1042 |
case NMSI_PROTOCOL: |
| 1043 |
//ReadOnly |
| 1044 |
//ASession.Protocol = NsmInfoUtility::NsmInfoToTStr(pin->lpInfo); |
| 1045 |
break; |
| 1046 |
case NMSI_VISIBLE: |
| 1047 |
session.Visible = Common::NsmInfoUtility::NsmInfoToBool(pin->lpInfo); |
| 1048 |
break; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionInfoChange, wParam, lParam); |
| 1053 |
g_NsmSystem.DoSessionChange(); |
| 1054 |
return 1; |
| 1055 |
} |
| 1056 |
|
| 1057 |
LONG_PTR Service::DoEnumSessions(WPARAM wParam, LPARAM lParam) |
| 1058 |
{ |
| 1059 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1060 |
const NsmSessionList &p = lock.List(); |
| 1061 |
|
| 1062 |
for(NsmSessionList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 1063 |
reinterpret_cast<TEnumSessionCallback>(wParam)(reinterpret_cast<HNsmSession>(it->get()), lParam); |
| 1064 |
|
| 1065 |
return 0; |
| 1066 |
} |
| 1067 |
|
| 1068 |
LONG_PTR Service::DoAddSessionMember(WPARAM wParam, LPARAM lParam) |
| 1069 |
{ |
| 1070 |
if(!lParam) |
| 1071 |
return 0; |
| 1072 |
|
| 1073 |
{ |
| 1074 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1075 |
const NsmSessionList &p = lock.List(); |
| 1076 |
|
| 1077 |
NsmSessionList::const_iterator it = |
| 1078 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1079 |
if(it == p.end()) |
| 1080 |
return 0; |
| 1081 |
|
| 1082 |
NsmMemberListSub q(new NsmMember(c2t(reinterpret_cast<char *>(lParam)))); |
| 1083 |
|
| 1084 |
if(!(*it)->Members.insert(NsmMemberList::value_type(q->Account, q)).second) |
| 1085 |
return 0; |
| 1086 |
} |
| 1087 |
|
| 1088 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionMembersAdd, wParam, lParam); |
| 1089 |
return 1; |
| 1090 |
} |
| 1091 |
|
| 1092 |
LONG_PTR Service::DoRemoveSessionMember(WPARAM wParam, LPARAM lParam) |
| 1093 |
{ |
| 1094 |
{ |
| 1095 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1096 |
const NsmSessionList &p = lock.List(); |
| 1097 |
|
| 1098 |
NsmSessionList::const_iterator it = |
| 1099 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1100 |
if(it == p.end()) |
| 1101 |
return 0; |
| 1102 |
|
| 1103 |
NsmMemberList &q = (*it)->Members; |
| 1104 |
|
| 1105 |
NsmMemberList::iterator it2 = q.find(c2t(reinterpret_cast<char *>(lParam))); |
| 1106 |
if(it2 != q.end()) |
| 1107 |
q.erase(it2); |
| 1108 |
} |
| 1109 |
|
| 1110 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionMembersRemove, wParam, lParam); |
| 1111 |
return 1; |
| 1112 |
} |
| 1113 |
|
| 1114 |
LONG_PTR Service::DoSetSessionMemberInfo(WPARAM wParam, LPARAM lParam) |
| 1115 |
{ |
| 1116 |
{ |
| 1117 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1118 |
const NsmSessionList &p = lock.List(); |
| 1119 |
|
| 1120 |
NsmSessionList::const_iterator it = |
| 1121 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1122 |
if(it == p.end()) |
| 1123 |
return 0; |
| 1124 |
|
| 1125 |
const TNsmMemberInfo &pin = *reinterpret_cast<PNsmMemberInfo>(lParam); |
| 1126 |
NsmMemberList::iterator it2 = (*it)->Members.find(c2t(pin.lpAccount)); |
| 1127 |
if(it2 == (*it)->Members.end()) |
| 1128 |
return 0; |
| 1129 |
|
| 1130 |
NsmMember &Member = *it2->second; |
| 1131 |
switch(pin.nInfoKey) |
| 1132 |
{ |
| 1133 |
case NMMI_ACCOUNT: |
| 1134 |
Member.Account = Common::NsmInfoUtility::NsmInfoToStr(pin.lpInfo); |
| 1135 |
break; |
| 1136 |
case NMMI_NAME: |
| 1137 |
Member.Name = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 1138 |
break; |
| 1139 |
case NMMI_STATUS: |
| 1140 |
Member.Status(Common::NsmInfoUtility::NsmInfoToInt(pin.lpInfo)); |
| 1141 |
break; |
| 1142 |
case NMMI_STATUSSTRING: |
| 1143 |
Member.StatusStr = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 1144 |
break; |
| 1145 |
case NMMI_BUSYNESS: |
| 1146 |
Member.Busyness = Common::NsmInfoUtility::NsmInfoToInt(pin.lpInfo); |
| 1147 |
break; |
| 1148 |
case NMMI_TYPING: |
| 1149 |
Member.Typing = Common::NsmInfoUtility::NsmInfoToBool(pin.lpInfo); |
| 1150 |
break; |
| 1151 |
case NMMI_COMMENT: |
| 1152 |
Member.Comment = Common::NsmInfoUtility::NsmInfoToStrW(pin.lpInfo); |
| 1153 |
} |
| 1154 |
} |
| 1155 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionMembersInfoChange, wParam, lParam); |
| 1156 |
return 1; |
| 1157 |
} |
| 1158 |
|
| 1159 |
LONG_PTR Service::DoGetSessionMemberInfo(WPARAM wParam, LPARAM lParam) |
| 1160 |
{ |
| 1161 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1162 |
const NsmSessionList &p = lock.List(); |
| 1163 |
|
| 1164 |
NsmSessionList::const_iterator it = |
| 1165 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1166 |
if(it == p.end()) |
| 1167 |
return 0; |
| 1168 |
|
| 1169 |
const PNsmMemberInfo pin = reinterpret_cast<PNsmMemberInfo>(lParam); |
| 1170 |
NsmMemberList::iterator it2 = (*it)->Members.find(c2t(pin->lpAccount)); |
| 1171 |
if(it2 == (*it)->Members.end()) |
| 1172 |
return 0; |
| 1173 |
|
| 1174 |
const NsmMember &Member = *it2->second; |
| 1175 |
switch(pin->nInfoKey) |
| 1176 |
{ |
| 1177 |
case NMMI_ACCOUNT: |
| 1178 |
//HACK:API 2.3 |
| 1179 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, t2c(Member.Account)); |
| 1180 |
case NMMI_NAME: |
| 1181 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.Name); |
| 1182 |
case NMMI_STATUS: |
| 1183 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, Member.Status()); |
| 1184 |
case NMMI_STATUSSTRING: |
| 1185 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.StatusStr); |
| 1186 |
case NMMI_BUSYNESS: |
| 1187 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, Member.Busyness); |
| 1188 |
case NMMI_TYPING: |
| 1189 |
return Common::NsmInfoUtility::BoolToNsmInfo(pin->lpInfo, Member.Typing); |
| 1190 |
case NMMI_COMMENT: |
| 1191 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, Member.Comment); |
| 1192 |
default: |
| 1193 |
assert(0); |
| 1194 |
return 0; |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
LONG_PTR Service::DoBeginSessionMembersUpdate(WPARAM /* wParam */, LPARAM /* lParam */ ) |
| 1199 |
{ |
| 1200 |
return 0; |
| 1201 |
} |
| 1202 |
|
| 1203 |
LONG_PTR Service::DoEndSessionMembersUpdate(WPARAM /* wParam */, LPARAM /* lParam */ ) |
| 1204 |
{ |
| 1205 |
return 0; |
| 1206 |
} |
| 1207 |
|
| 1208 |
LONG_PTR Service::DoEnumSessionMembers(WPARAM wParam, LPARAM lParam) |
| 1209 |
{ |
| 1210 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1211 |
const NsmSessionList &p = lock.List(); |
| 1212 |
|
| 1213 |
NsmSessionList::const_iterator it = |
| 1214 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1215 |
if(it == p.end()) |
| 1216 |
return 0; |
| 1217 |
|
| 1218 |
const NsmMemberList &ls = (*it)->Members; |
| 1219 |
const TEnumMemberInfo &pin = *reinterpret_cast<PEnumMemberInfo>(lParam); |
| 1220 |
for(NsmMemberList::const_iterator itr = ls.begin(); itr != ls.end(); ++itr) |
| 1221 |
{ |
| 1222 |
pin.lpCallBackProc(t2c(itr->second->Account).c_str(), pin.nData); |
| 1223 |
} |
| 1224 |
return 0; |
| 1225 |
} |
| 1226 |
|
| 1227 |
LONG_PTR Service::DoSendMessage(WPARAM wParam, LPARAM lParam) |
| 1228 |
{ |
| 1229 |
{ |
| 1230 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1231 |
const NsmSessionList &p = lock.List(); |
| 1232 |
|
| 1233 |
NsmSessionList::const_iterator it = |
| 1234 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1235 |
if(it == p.end()) |
| 1236 |
return 0; |
| 1237 |
|
| 1238 |
g_NsmCom.CallService(g_NsmCom.GetService(format(NMS_PROTOCOL_SESSION_SENDMESSAGE, (*it)->Protocol.c_str())), wParam, lParam); |
| 1239 |
} |
| 1240 |
|
| 1241 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionSendMessage, wParam, lParam); |
| 1242 |
return 1; |
| 1243 |
} |
| 1244 |
|
| 1245 |
LONG_PTR Service::DoReceiveMessage(WPARAM wParam, LPARAM lParam) |
| 1246 |
{ |
| 1247 |
{ |
| 1248 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1249 |
const NsmSessionList &p = lock.List(); |
| 1250 |
|
| 1251 |
NsmSessionList::const_iterator it = |
| 1252 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession *>(wParam))); |
| 1253 |
if(it == p.end()) |
| 1254 |
return 0; |
| 1255 |
} |
| 1256 |
|
| 1257 |
g_NsmCom.NotifyEvent(g_NsmSystem.HSessionReceiveMessage, wParam, lParam); |
| 1258 |
return 1; |
| 1259 |
} |
| 1260 |
|
| 1261 |
// FileSession --------------------------------------------------------------------- |
| 1262 |
|
| 1263 |
LONG_PTR Service::DoCreateFileSession(WPARAM wParam, LPARAM /* lParam */) |
| 1264 |
{ |
| 1265 |
NsmFileSessionListSub result; |
| 1266 |
{ |
| 1267 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 1268 |
const NsmSessionList &p = lock.List(); |
| 1269 |
|
| 1270 |
NsmSessionList::const_iterator it = |
| 1271 |
std::find_if(p.begin(), p.end(), NsmSession::FindByHandle(reinterpret_cast<NsmSession*>(wParam))); |
| 1272 |
|
| 1273 |
if(it == p.end()) |
| 1274 |
return 0; |
| 1275 |
|
| 1276 |
NsmThreadFileSessionList::AutoLock lock2(g_NsmSystem.FileSessions); |
| 1277 |
NsmFileSessionList &p2 = lock2.List(); |
| 1278 |
|
| 1279 |
result.reset(new NsmFileSession(it->get(), (*it)->Protocol)); |
| 1280 |
|
| 1281 |
p2.push_back(result); |
| 1282 |
} |
| 1283 |
|
| 1284 |
g_NsmCom.NotifyEvent(g_NsmSystem.HFileSessionOpen, reinterpret_cast<WPARAM>(result.get()), 0); |
| 1285 |
g_NsmSystem.DoFileSessionChange(); |
| 1286 |
|
| 1287 |
return reinterpret_cast<LONG_PTR>(result.get()); |
| 1288 |
} |
| 1289 |
|
| 1290 |
LONG_PTR Service::DoDeleteFileSession(WPARAM wParam, LPARAM /* lParam */) |
| 1291 |
{ |
| 1292 |
{ |
| 1293 |
NsmThreadFileSessionList::AutoLock lock(g_NsmSystem.FileSessions); |
| 1294 |
NsmFileSessionList &p = lock.List(); |
| 1295 |
NsmFileSessionList::iterator it |
| 1296 |
= std::find_if(p.begin(), p.end(), NsmFileSession::FindByHandle(reinterpret_cast<NsmFileSession *>(wParam))); |
| 1297 |
if(it == p.end()) |
| 1298 |
return -1; |
| 1299 |
|
| 1300 |
p.erase(it); |
| 1301 |
} |
| 1302 |
|
| 1303 |
g_NsmCom.NotifyEvent(g_NsmSystem.HFileSessionClose, wParam, 0); |
| 1304 |
g_NsmSystem.DoFileSessionChange(); |
| 1305 |
return 1; |
| 1306 |
} |
| 1307 |
|
| 1308 |
LONG_PTR Service::DoGetFileSessionInfo(WPARAM wParam, LPARAM lParam) |
| 1309 |
{ |
| 1310 |
NsmThreadFileSessionList::ConstAutoLock lock(g_NsmSystem.FileSessions); |
| 1311 |
const NsmFileSessionList &p = lock.List(); |
| 1312 |
NsmFileSessionList::const_iterator it = |
| 1313 |
std::find_if(p.begin(), p.end(), NsmFileSession::FindByHandle(reinterpret_cast<NsmFileSession *>(wParam))); |
| 1314 |
if(it == p.end()) |
| 1315 |
return 0; |
| 1316 |
|
| 1317 |
const NsmFileSession &session = *reinterpret_cast<NsmFileSession *>(wParam); |
| 1318 |
const PNsmFileSessionInfo pin = reinterpret_cast<PNsmFileSessionInfo>(lParam); |
| 1319 |
switch(pin->nInfoKey) |
| 1320 |
{ |
| 1321 |
//TODO:PtrToNsmInfoŞKvH |
| 1322 |
case NMFI_SESSION: |
| 1323 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, reinterpret_cast<INT32>(session.Session)); |
| 1324 |
case NMFI_PROTOCOL: |
| 1325 |
//HACK:API 2.3 |
| 1326 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, t2c(session.Protocol)); |
| 1327 |
case NMFI_FILENAME: |
| 1328 |
//HACK:API 2.3 |
| 1329 |
return Common::NsmInfoUtility::StrToNsmInfo(pin->lpInfo, t2c(session.FileName)); |
| 1330 |
case NMFI_FILESIZE: |
| 1331 |
return Common::NsmInfoUtility::Int64ToNsmInfo(pin->lpInfo, session.FileSize); |
| 1332 |
case NMFI_CURRENTSIZE: |
| 1333 |
return Common::NsmInfoUtility::Int64ToNsmInfo(pin->lpInfo, session.CurrentFileSize); |
| 1334 |
case NMFI_ISSENDER: |
| 1335 |
return Common::NsmInfoUtility::BoolToNsmInfo(pin->lpInfo, session.IsSender); |
| 1336 |
case NMFI_STATUS: |
| 1337 |
return Common::NsmInfoUtility::IntToNsmInfo(pin->lpInfo, session.Status); |
| 1338 |
default: |
| 1339 |
assert(0); |
| 1340 |
return 0; |
| 1341 |
} |
| 1342 |
} |
| 1343 |
|
| 1344 |
LONG_PTR Service::DoSetFileSessionInfo(WPARAM wParam, LPARAM lParam) |
| 1345 |
{ |
| 1346 |
{ |
| 1347 |
NsmThreadFileSessionList::ConstAutoLock lock(g_NsmSystem.FileSessions); |
| 1348 |
const NsmFileSessionList &p = lock.List(); |
| 1349 |
|
| 1350 |
NsmFileSessionList::const_iterator it = |
| 1351 |
std::find_if(p.begin(), p.end(), NsmFileSession::FindByHandle(reinterpret_cast<NsmFileSession *>(wParam))); |
| 1352 |
if(it == p.end()) |
| 1353 |
return 0; |
| 1354 |
|
| 1355 |
NsmFileSession &session = *reinterpret_cast<NsmFileSession *>(wParam); |
| 1356 |
const TNsmFileSessionInfo &pin = *reinterpret_cast<PNsmFileSessionInfo>(lParam); |
| 1357 |
switch(pin.nInfoKey) |
| 1358 |
{ |
| 1359 |
case NMFI_SESSION: |
| 1360 |
//ReadOnly |
| 1361 |
//ASession.Session = TNsmConnection(NsmInfoToInt(PNsmFileSessionInfo(lParam)->lpInfo)); |
| 1362 |
break; |
| 1363 |
case NMFI_PROTOCOL: |
| 1364 |
//ReadOnly |
| 1365 |
//ASession.Protocol = NsmInfoUtility::NsmInfoToTStr(pin->lpInfo); |
| 1366 |
break; |
| 1367 |
case NMFI_FILENAME: |
| 1368 |
session.FileName = Common::NsmInfoUtility::NsmInfoToStr(pin.lpInfo); |
| 1369 |
break; |
| 1370 |
case NMFI_FILESIZE: |
| 1371 |
session.FileSize = Common::NsmInfoUtility::NsmInfoToInt64(pin.lpInfo); |
| 1372 |
break; |
| 1373 |
case NMFI_CURRENTSIZE: |
| 1374 |
session.CurrentFileSize = Common::NsmInfoUtility::NsmInfoToInt64(pin.lpInfo); |
| 1375 |
break; |
| 1376 |
case NMFI_ISSENDER: |
| 1377 |
session.IsSender = Common::NsmInfoUtility::NsmInfoToBool(pin.lpInfo); |
| 1378 |
break; |
| 1379 |
case NMFI_STATUS: |
| 1380 |
session.Status = Common::NsmInfoUtility::NsmInfoToInt(pin.lpInfo); |
| 1381 |
break; |
| 1382 |
} |
| 1383 |
} |
| 1384 |
g_NsmCom.NotifyEvent(g_NsmSystem.HFileSessionInfoChange, wParam, lParam); |
| 1385 |
g_NsmSystem.DoFileSessionChange(); |
| 1386 |
return 1; |
| 1387 |
} |
| 1388 |
|
| 1389 |
LONG_PTR Service::DoEnumFileSessions(WPARAM wParam, LPARAM lParam) |
| 1390 |
{ |
| 1391 |
NsmThreadFileSessionList::ConstAutoLock lock(g_NsmSystem.FileSessions); |
| 1392 |
const NsmFileSessionList &p = lock.List(); |
| 1393 |
|
| 1394 |
for(NsmFileSessionList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 1395 |
reinterpret_cast<TEnumFileSessionCallback>(wParam)(reinterpret_cast<HNsmFileSession>(it->get()), lParam); |
| 1396 |
|
| 1397 |
return 0; |
| 1398 |
} |
| 1399 |
|
| 1400 |
// UIService --------------------------------------------------------------------- |
| 1401 |
|
| 1402 |
void Service::DoEnumService(const tstring &requiredService, const TEnumUIServiceInfo* pin) |
| 1403 |
{ |
| 1404 |
NsmThreadServiceList::ConstAutoLock lock(g_NsmCom.ServiceList); |
| 1405 |
const NsmServiceList &p = lock.List(); |
| 1406 |
|
| 1407 |
for(NsmServiceList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 1408 |
{ |
| 1409 |
const tstring serviceName = it->first; |
| 1410 |
|
| 1411 |
tstring::size_type pos = serviceName.rfind(TEXT('/')); |
| 1412 |
if(pos == tstring::npos) |
| 1413 |
continue; |
| 1414 |
|
| 1415 |
if(requiredService != serviceName.substr(0, pos)) |
| 1416 |
continue; |
| 1417 |
|
| 1418 |
pin->lpCallBackProc(t2c(serviceName).c_str(), pin->nData); |
| 1419 |
} |
| 1420 |
} |
| 1421 |
|
| 1422 |
//----------------------------------------------------------------------------------------------- |
| 1423 |
|
| 1424 |
LONG_PTR Service::DoEnumConnectionUIService(const tstring &wParam, LPARAM lParam, LPCTSTR main) |
| 1425 |
{ |
| 1426 |
const tstring requiredService = format(main, wParam.c_str()); |
| 1427 |
DoEnumService(requiredService, reinterpret_cast<PEnumUIServiceInfo>(lParam)); |
| 1428 |
return 0; |
| 1429 |
} |
| 1430 |
|
| 1431 |
LONG_PTR Service::DoEnumConnectionUIServiceMain(WPARAM wParam, LPARAM lParam) |
| 1432 |
{ |
| 1433 |
return DoEnumConnectionUIService(reinterpret_cast<NsmConnection *>(wParam)->Protocol, lParam, NMD_PROTOCOL_CONNECTION_UISERVICE_MAIN); |
| 1434 |
} |
| 1435 |
|
| 1436 |
LONG_PTR Service::DoEnumConnectionUIServiceMember(WPARAM wParam, LPARAM lParam) |
| 1437 |
{ |
| 1438 |
return DoEnumConnectionUIService(reinterpret_cast<NsmConnection *>(wParam)->Protocol, lParam, NMD_PROTOCOL_CONNECTION_UISERVICE_MEMBER); |
| 1439 |
} |
| 1440 |
|
| 1441 |
LONG_PTR Service::DoEnumConnectionUIServiceGroup(WPARAM wParam, LPARAM lParam) |
| 1442 |
{ |
| 1443 |
return DoEnumConnectionUIService(reinterpret_cast<NsmConnection *>(wParam)->Protocol, lParam, NMD_PROTOCOL_CONNECTION_UISERVICE_GROUP); |
| 1444 |
} |
| 1445 |
|
| 1446 |
LONG_PTR Service::DoEnumSessionUIServiceMain(WPARAM wParam, LPARAM lParam) |
| 1447 |
{ |
| 1448 |
return DoEnumConnectionUIService(reinterpret_cast<NsmSession *>(wParam)->Protocol, lParam, NMD_PROTOCOL_SESSION_UISERVICE_MAIN); |
| 1449 |
} |
| 1450 |
|
| 1451 |
LONG_PTR Service::DoEnumSessionUIServiceMember(WPARAM wParam, LPARAM lParam) |
| 1452 |
{ |
| 1453 |
return DoEnumConnectionUIService(reinterpret_cast<NsmSession *>(wParam)->Protocol, lParam, NMD_PROTOCOL_SESSION_UISERVICE_MEMBER); |
| 1454 |
} |
| 1455 |
|
| 1456 |
LONG_PTR Service::DoEnumFileSessionUIServiceMain(WPARAM wParam, LPARAM lParam) |
| 1457 |
{ |
| 1458 |
return DoEnumConnectionUIService(reinterpret_cast<NsmFileSession *>(wParam)->Protocol, lParam, NMD_PROTOCOL_FILESESSION_UISERVICE_MAIN); |
| 1459 |
} |
| 1460 |
|
| 1461 |
//----------------------------------------------------------------------------------------------- |
| 1462 |
|
| 1463 |
LONG_PTR Service::DoEnumAddInUIService(WPARAM /* wParam */, LPARAM lParam, LPCTSTR main) |
| 1464 |
{ |
| 1465 |
const TEnumUIServiceInfo *const pin = reinterpret_cast<PEnumUIServiceInfo>(lParam); |
| 1466 |
|
| 1467 |
const NsmPluginList &p = g_NsmSystem.Plugins; |
| 1468 |
for(NsmPluginList::const_iterator it = p.begin(); it != p.end(); ++it) |
| 1469 |
{ |
| 1470 |
const tstring moduleName = (*it)->PluginInfo.ModuleName; |
| 1471 |
if(Common::ModuleUtility::ExtractModuleType(moduleName) == NMM_ADDIN) |
| 1472 |
{ |
| 1473 |
const tstring requiredService = format(main, Common::ModuleUtility::ExtractAddInName(moduleName).c_str()); |
| 1474 |
DoEnumService(requiredService, pin); |
| 1475 |
} |
| 1476 |
} |
| 1477 |
|
| 1478 |
return 0; |
| 1479 |
} |
| 1480 |
|
| 1481 |
LONG_PTR Service::DoEnumAddInUIServiceMain(WPARAM wParam, LPARAM lParam) |
| 1482 |
{ |
| 1483 |
return DoEnumAddInUIService(wParam, lParam, NMD_ADDIN_UISERVICE_MAIN); |
| 1484 |
} |
| 1485 |
|
| 1486 |
LONG_PTR Service::DoEnumAddInUIServiceMember(WPARAM wParam, LPARAM lParam) |
| 1487 |
{ |
| 1488 |
return DoEnumAddInUIService(wParam, lParam, NMD_ADDIN_UISERVICE_MEMBER); |
| 1489 |
} |
| 1490 |
|
| 1491 |
LONG_PTR Service::DoEnumAddInUIServiceGroup(WPARAM wParam, LPARAM lParam) |
| 1492 |
{ |
| 1493 |
return DoEnumAddInUIService(wParam, lParam, NMD_ADDIN_UISERVICE_GROUP); |
| 1494 |
} |
| 1495 |
|
| 1496 |
LONG_PTR Service::DoEnumAddInUIServiceTab(WPARAM wParam, LPARAM lParam) |
| 1497 |
{ |
| 1498 |
return DoEnumAddInUIService(wParam, lParam, NMD_ADDIN_UISERVICE_TAB); |
| 1499 |
} |
| 1500 |
|
| 1501 |
LONG_PTR Service::DoEnumAddInUIServiceSessionMain(WPARAM wParam, LPARAM lParam) |
| 1502 |
{ |
| 1503 |
return DoEnumAddInUIService(wParam, lParam, NMD_ADDIN_UISERVICE_SESSION_MAIN); |
| 1504 |
} |
| 1505 |
|
| 1506 |
LONG_PTR Service::DoEnumAddInUIServiceSessionMember(WPARAM wParam, LPARAM lParam) |
| 1507 |
{ |
| 1508 |
return DoEnumAddInUIService(wParam, lParam, NMD_ADDIN_UISERVICE_SESSION_MEMBER); |
| 1509 |
} |
| 1510 |
|
| 1511 |
LONG_PTR Service::DoEnumAddInUIServiceFileSessionMain(WPARAM wParam, LPARAM lParam) |
| 1512 |
{ |
| 1513 |
return DoEnumAddInUIService(wParam, lParam, NMD_ADDIN_UISERVICE_FILESESSION_MAIN); |
| 1514 |
} |
| 1515 |
|
| 1516 |
//-------------------------------------------------------- |
| 1517 |
// UFrmNsmMainŠçÚŽ |
| 1518 |
//-------------------------------------------------------- |
| 1519 |
|
| 1520 |
// NMS_SYSTEM_MODULES_REINITIALIZEPLUGINS(wb_˘č`)Ö |
| 1521 |
// vOCĚÄÇÝÝžŠçłÄࢢŠČB |
| 1522 |
// dlŠĚŞŽIÇÝݡéć¤ÉĹŤÄȢľB |
| 1523 |
LONG_PTR Service::DoReInitializePlugins(WPARAM /* wParam */, LPARAM /* lParam */) |
| 1524 |
{ |
| 1525 |
if(!g_NsmSystem.HModulesLoaded) |
| 1526 |
return 0; |
| 1527 |
|
| 1528 |
const NsmEvent::HookProcsContainer &loaded = reinterpret_cast<NsmEvent*>(g_NsmSystem.HModulesLoaded)->HookProcs; |
| 1529 |
NsmEvent::HookProcsContainer::size_type loadedSize = loaded.size(); |
| 1530 |
|
| 1531 |
NsmPluginList::size_type plugSize = g_NsmSystem.Plugins.size(); |
| 1532 |
|
| 1533 |
g_NsmSystem.SearchPlugin(ExtractFilePath(Application::ExeName()) + (TEXT("Plugins") FILESEP TEXT("*") DLLSUFFIX)); |
| 1534 |
TNsmPluginInitInfo initInfo = NsmComHelper::GetPluginInitInfo(); |
| 1535 |
|
| 1536 |
// W
[Ěúť |
| 1537 |
for(NsmPluginList::const_iterator it = g_NsmSystem.Plugins.begin() + plugSize; it != g_NsmSystem.Plugins.end(); ++it) |
| 1538 |
(*it)->Initialize(&initInfo); |
| 1539 |
|
| 1540 |
// SW
[ÇIšCxg |
| 1541 |
for(NsmEvent::HookProcsContainer::const_iterator it = loaded.begin() + loadedSize; it != loaded.end(); ++it) |
| 1542 |
(*it)(0, 0); |
| 1543 |
|
| 1544 |
NsmEvent* evt = reinterpret_cast<NsmEvent*>(g_NsmCom.GetEvent(NME_SYSTEM_MODULESRELOADED)); |
| 1545 |
if(evt) |
| 1546 |
{ |
| 1547 |
const NsmEvent::HookProcsContainer &reloaded = evt->HookProcs; |
| 1548 |
|
| 1549 |
for(NsmEvent::HookProcsContainer::const_iterator it = reloaded.begin(); it != reloaded.end(); ++it) |
| 1550 |
(*it)(0, 0); |
| 1551 |
} |
| 1552 |
|
| 1553 |
return 0; |
| 1554 |
} |
| 1555 |
|
| 1556 |
// NMS_SYSTEM_RESTART(wb_˘č`)Ö |
| 1557 |
// ąÁżÍÄNŽÖB |
| 1558 |
// ĆŠgŁžľŘÁÄࢢĆv¤B |
| 1559 |
LONG_PTR Service::DoRestart(WPARAM /* wParam */, LPARAM /* lParam */) |
| 1560 |
{ |
| 1561 |
std::array<TCHAR, MAX_PATH> currentDir; |
| 1562 |
GetCurrentDirectory(std::tuple_size<decltype(currentDir)>::value, currentDir.data()); |
| 1563 |
|
| 1564 |
ShellExecute(NULL, NULL, Application::ExeName().c_str(), CommandLineOption::Restart, currentDir.data(), SW_SHOWDEFAULT); |
| 1565 |
DoExit(0, 0); |
| 1566 |
|
| 1567 |
return 0; |
| 1568 |
} |
| 1569 |
} |
| 1570 |
} |