Changeset 209


Ignore:
Timestamp:
11/10/09 18:25:49 (2 years ago)
Author:
mickem
Message:

swaped the mutexes for the settings subsysytem to boost

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/NSClient++-2005.sln

    r208 r209  
    271271    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    272272    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|Win32.ActiveCfg = Debug|Win32 
    273     {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|Win32.Build.0 = Debug|Win32 
    274273    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|x64.ActiveCfg = Debug|x64 
    275274    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|x64.Build.0 = Debug|x64 
     
    306305    {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    307306    {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Win32.ActiveCfg = Debug|Win32 
    308     {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Win32.Build.0 = Debug|Win32 
    309307    {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|x64.ActiveCfg = Debug|x64 
    310308    {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|x64.Build.0 = Debug|x64 
     
    341339    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    342340    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|Win32.ActiveCfg = Debug|Win32 
    343     {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|Win32.Build.0 = Debug|Win32 
    344341    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|x64.ActiveCfg = Debug|x64 
    345342    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|x64.Build.0 = Debug|x64 
     
    442439    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    443440    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|Win32.ActiveCfg = Debug|Win32 
    444     {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|Win32.Build.0 = Debug|Win32 
    445441    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|x64.ActiveCfg = Debug|x64 
    446442    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|x64.Build.0 = Debug|x64 
     
    477473    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    478474    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|Win32.ActiveCfg = Debug|Win32 
    479     {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|Win32.Build.0 = Debug|Win32 
    480475    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|x64.ActiveCfg = Debug|x64 
    481476    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|x64.Build.0 = Debug|x64 
     
    512507    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    513508    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|Win32.ActiveCfg = Debug|Win32 
    514     {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|Win32.Build.0 = Debug|Win32 
    515509    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|x64.ActiveCfg = Debug|x64 
    516510    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|x64.Build.0 = Debug|x64 
     
    869863    {53FB9872-5E74-4E62-892D-AD82C2ED67CE}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    870864    {53FB9872-5E74-4E62-892D-AD82C2ED67CE}.Debug|Win32.ActiveCfg = Debug|Win32 
    871     {53FB9872-5E74-4E62-892D-AD82C2ED67CE}.Debug|Win32.Build.0 = Debug|Win32 
    872865    {53FB9872-5E74-4E62-892D-AD82C2ED67CE}.Debug|x64.ActiveCfg = Debug|x64 
    873866    {53FB9872-5E74-4E62-892D-AD82C2ED67CE}.Debug|x64.Build.0 = Debug|x64 
     
    10261019    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    10271020    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.ActiveCfg = Debug|Win32 
    1028     {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.Build.0 = Debug|Win32 
    10291021    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|x64.ActiveCfg = Debug|x64 
    10301022    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|x64.Build.0 = Debug|x64 
  • trunk/include/settings/Settings.h

    r205 r209  
    2424#include <string> 
    2525#include <map> 
    26 #include <Mutex.h> 
     26#include <boost/thread/thread.hpp> 
     27#include <boost/thread/locks.hpp> 
     28#include <strEx.h> 
    2729#define BUFF_LEN 4096 
    2830 
     
    615617    SettingsInterface* instance_; 
    616618    instance_list instances_; 
    617     MutexHandler mutexHandler_; 
     619    boost::timed_mutex mutexHandler_; 
    618620    /* 
    619621    struct key_description : public SettingsCore::key_description { 
     
    714716 
    715717    SettingsInterface* get() { 
    716       MutexLock mutex(mutexHandler_); 
    717       if (!mutex.hasMutex()) 
     718      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     719      if (!mutex.owns_lock()) 
    718720        throw SettingsException(_T("Failed to get mutext, cant get settings instance")); 
    719721      if (instance_ == NULL) 
     
    724726    } 
    725727    SettingsInterface* get(SettingsCore::settings_type type) { 
    726       MutexLock mutex(mutexHandler_); 
    727       if (!mutex.hasMutex()) 
     728      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     729      if (!mutex.owns_lock()) 
    728730        throw SettingsException(_T("Failed to get mutext, cant get settings instance")); 
    729731      return instance_unsafe(type); 
     
    783785        get_logger()->debug(__FILEW__, __LINE__, _T("Starting to migrate...")); 
    784786#endif 
    785         MutexLock mutex(mutexHandler_); 
    786         if (!mutex.hasMutex()) 
     787        boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     788        if (!mutex.owns_lock()) 
    787789          throw SettingsException(_T("migrate_type: Failed to get mutext, cant get settings instance")); 
    788790        SettingsInterface* iFrom = instance_unsafe(from); 
     
    803805    } 
    804806    SettingsCore::settings_type get_settings_type() { 
    805       MutexLock mutex(mutexHandler_); 
    806       if (!mutex.hasMutex()) 
     807      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     808      if (!mutex.owns_lock()) 
    807809        throw SettingsException(_T("Failed to get mutext, cant get load settings")); 
    808810      if (instance_ == NULL) 
     
    823825    } 
    824826    bool has_type(SettingsCore::settings_type type) { 
    825       MutexLock mutex(mutexHandler_); 
    826       if (!mutex.hasMutex()) 
     827      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     828      if (!mutex.owns_lock()) 
    827829        throw SettingsException(_T("has_type Failed to get mutext, cant get access settings")); 
    828830      instance_list::const_iterator cit = instances_.find(type); 
     
    830832    } 
    831833    void set_type(SettingsCore::settings_type type) { 
    832       MutexLock mutex(mutexHandler_); 
    833       if (!mutex.hasMutex()) 
     834      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     835      if (!mutex.owns_lock()) 
    834836        throw SettingsException(_T("set_type Failed to get mutext, cant get access settings")); 
    835837      instance_list::const_iterator cit = instances_.find(type); 
     
    839841    } 
    840842    void add_type_impl(SettingsCore::settings_type type, SettingsInterface* impl) { 
    841       MutexLock mutex(mutexHandler_); 
    842       if (!mutex.hasMutex()) 
     843      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     844      if (!mutex.owns_lock()) 
    843845        throw SettingsException(_T("add_type_impl Failed to get mutext, cant get access settings")); 
    844846      instance_list::iterator it = instances_.find(type); 
     
    11501152 
    11511153    void add_instance(SettingsInterface *instance) { 
    1152       MutexLock mutex(mutexHandler_); 
    1153       if (!mutex.hasMutex()) 
     1154      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1155      if (!mutex.owns_lock()) 
    11541156        throw SettingsException(_T("load_all_instance Failed to get mutext, cant get access settings")); 
    11551157      instance_list::iterator it = instances_.find(instance->get_type()); 
     
    11721174  private: 
    11731175    void destroy_all_instances() { 
    1174       MutexLock mutex(mutexHandler_); 
    1175       if (!mutex.hasMutex()) 
     1176      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1177      if (!mutex.owns_lock()) 
    11761178        throw SettingsException(_T("destroy_all_instances Failed to get mutext, cant get access settings")); 
    11771179      instance_ = NULL; 
     
    11861188    } 
    11871189    SettingsInterface *get_default_settings_instance_unsafe() { 
    1188       MutexLock mutex(mutexHandler_); 
    1189       if (!mutex.hasMutex()) 
     1190      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1191      if (!mutex.owns_lock()) 
    11901192        throw SettingsException(_T("destroy_all_instances Failed to get mutext, cant get access settings")); 
    11911193      instance_ = NULL; 
  • trunk/include/settings/settings_ini.hpp

    r202 r209  
    55#include <settings/Settings.h> 
    66#include <simpleini/SimpleIni.h> 
     7#include <error.hpp> 
    78 
    89namespace Settings { 
  • trunk/service/NSClient++.cpp

    r208 r209  
    8181  } 
    8282 
    83   static bool start(DWORD dwSessionId) { 
     83  static bool start(unsigned long dwSessionId) { 
    8484    std::wstring program = mainClient.getBasePath() +  _T("\\") +  
    8585      SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 
     
    8888  } 
    8989 
    90   static bool startTrayHelper(DWORD dwSessionId, std::wstring exe, std::wstring cmdline, bool startThread = true) { 
    91     HANDLE hToken = NULL; 
    92     if (!remote_processes::GetSessionUserToken(dwSessionId, &hToken)) { 
    93       LOG_ERROR_STD(_T("Failed to query user token: ") + error::lookup::last_error()); 
    94       return false; 
    95     } else { 
    96       STARTUPINFO          StartUPInfo; 
    97       PROCESS_INFORMATION  ProcessInfo; 
    98  
    99       ZeroMemory(&StartUPInfo,sizeof(STARTUPINFO)); 
    100       ZeroMemory(&ProcessInfo,sizeof(PROCESS_INFORMATION)); 
    101       StartUPInfo.wShowWindow = SW_HIDE; 
    102       StartUPInfo.lpDesktop = L"Winsta0\\Default"; 
    103       StartUPInfo.cb = sizeof(STARTUPINFO); 
    104  
    105       wchar_t *buffer = new wchar_t[cmdline.size()+10]; 
    106       wcscpy(buffer, cmdline.c_str()); 
    107       LOG_MESSAGE_STD(_T("Running: ") + exe); 
    108       LOG_MESSAGE_STD(_T("Running: ") + cmdline); 
    109  
    110       LPVOID pEnv =NULL; 
    111       DWORD dwCreationFlags = CREATE_NO_WINDOW; //0; //DETACHED_PROCESS 
    112  
    113       if(CreateEnvironmentBlock(&pEnv,hToken,TRUE)) { 
    114         dwCreationFlags|=CREATE_UNICODE_ENVIRONMENT; 
    115       } else { 
    116         LOG_ERROR_STD(_T("Failed to create enviornment: ") + error::lookup::last_error()); 
    117         pEnv=NULL; 
    118       } 
    119       /* 
    120       LOG_ERROR_STD(_T("Impersonating user: ")); 
    121       if (!ImpersonateLoggedOnUser(hToken)) { 
    122         LOG_ERROR_STD(_T("Failed to impersonate the user: ") + error::lookup::last_error()); 
    123       } 
    124  
    125       wchar_t pszUname[UNLEN + 1]; 
    126       ZeroMemory(pszUname,sizeof(pszUname)); 
    127       DWORD dwSize = UNLEN; 
    128       if (!GetUserName(pszUname,&dwSize)) { 
    129         DWORD dwErr = GetLastError(); 
    130         if (!RevertToSelf()) 
    131           LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
    132         LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 
    133         return false; 
    134       } 
    135        
    136  
    137       PROFILEINFO info; 
    138       info.dwSize = sizeof(PROFILEINFO); 
    139       info.lpUserName = pszUname; 
    140       if (!LoadUserProfile(hToken, &info)) { 
    141         DWORD dwErr = GetLastError(); 
    142         if (!RevertToSelf()) 
    143           LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
    144         LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 
    145         return false; 
    146       } 
    147       */ 
    148       if (!CreateProcessAsUser(hToken, exe.c_str(), buffer, NULL, NULL, FALSE, dwCreationFlags, pEnv, NULL, &StartUPInfo, &ProcessInfo)) { 
    149         DWORD dwErr = GetLastError(); 
    150         delete [] buffer; 
    151         /* 
    152         if (!RevertToSelf()) { 
    153           LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
    154         } 
    155         */ 
    156         if (startThread && dwErr == ERROR_PIPE_NOT_CONNECTED) { 
    157           LOG_MESSAGE(_T("Failed to start trayhelper: starting a background thread to do it instead...")); 
    158           Thread<tray_starter> *pThread = new Thread<tray_starter>(_T("tray-starter-thread")); 
    159           pThread->createThread(tray_starter::init(dwSessionId, exe, cmdline)); 
    160           return false; 
    161         } else if (dwErr == ERROR_PIPE_NOT_CONNECTED) { 
    162           LOG_ERROR_STD(_T("Thread failed to start trayhelper (will try again): ") + error::format::from_system(dwErr)); 
    163           return false; 
    164         } else { 
    165           LOG_ERROR_STD(_T("Failed to start trayhelper: ") + error::format::from_system(dwErr)); 
    166           return true; 
    167         } 
    168       } else { 
    169         delete [] buffer; 
    170         /* 
    171         if (!RevertToSelf()) { 
    172           LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
    173         } 
    174         */ 
    175         LOG_MESSAGE_STD(_T("Started tray in other user session: ") + strEx::itos(dwSessionId)); 
    176       } 
    177  
    178  
    179       CloseHandle(hToken); 
    180       return true; 
    181     } 
     90  static bool startTrayHelper(unsigned long dwSessionId, std::wstring exe, std::wstring cmdline, bool startThread = true) { 
     91//    HANDLE hToken = NULL; 
     92//    if (!remote_processes::GetSessionUserToken(dwSessionId, &hToken)) { 
     93//      LOG_ERROR_STD(_T("Failed to query user token: ") + error::lookup::last_error()); 
     94//      return false; 
     95//    } else { 
     96//      STARTUPINFO          StartUPInfo; 
     97//      PROCESS_INFORMATION  ProcessInfo; 
     98//  
     99//      ZeroMemory(&StartUPInfo,sizeof(STARTUPINFO)); 
     100//      ZeroMemory(&ProcessInfo,sizeof(PROCESS_INFORMATION)); 
     101//      StartUPInfo.wShowWindow = SW_HIDE; 
     102//      StartUPInfo.lpDesktop = L"Winsta0\\Default"; 
     103//      StartUPInfo.cb = sizeof(STARTUPINFO); 
     104//  
     105//      wchar_t *buffer = new wchar_t[cmdline.size()+10]; 
     106//      wcscpy(buffer, cmdline.c_str()); 
     107//      LOG_MESSAGE_STD(_T("Running: ") + exe); 
     108//      LOG_MESSAGE_STD(_T("Running: ") + cmdline); 
     109//  
     110//      LPVOID pEnv =NULL; 
     111//      DWORD dwCreationFlags = CREATE_NO_WINDOW; //0; //DETACHED_PROCESS 
     112//  
     113//      if(CreateEnvironmentBlock(&pEnv,hToken,TRUE)) { 
     114//        dwCreationFlags|=CREATE_UNICODE_ENVIRONMENT; 
     115//      } else { 
     116//        LOG_ERROR_STD(_T("Failed to create enviornment: ") + error::lookup::last_error()); 
     117//        pEnv=NULL; 
     118//      } 
     119//      /* 
     120//      LOG_ERROR_STD(_T("Impersonating user: ")); 
     121//      if (!ImpersonateLoggedOnUser(hToken)) { 
     122//        LOG_ERROR_STD(_T("Failed to impersonate the user: ") + error::lookup::last_error()); 
     123//      } 
     124//  
     125//      wchar_t pszUname[UNLEN + 1]; 
     126//      ZeroMemory(pszUname,sizeof(pszUname)); 
     127//      DWORD dwSize = UNLEN; 
     128//      if (!GetUserName(pszUname,&dwSize)) { 
     129//        DWORD dwErr = GetLastError(); 
     130//        if (!RevertToSelf()) 
     131//          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     132//        LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 
     133//        return false; 
     134//      } 
     135//       
     136//  
     137//      PROFILEINFO info; 
     138//      info.dwSize = sizeof(PROFILEINFO); 
     139//      info.lpUserName = pszUname; 
     140//      if (!LoadUserProfile(hToken, &info)) { 
     141//        DWORD dwErr = GetLastError(); 
     142//        if (!RevertToSelf()) 
     143//          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     144//        LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 
     145//        return false; 
     146//      } 
     147//      */ 
     148//      if (!CreateProcessAsUser(hToken, exe.c_str(), buffer, NULL, NULL, FALSE, dwCreationFlags, pEnv, NULL, &StartUPInfo, &ProcessInfo)) { 
     149//        DWORD dwErr = GetLastError(); 
     150//        delete [] buffer; 
     151//        /* 
     152//        if (!RevertToSelf()) { 
     153//          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     154//        } 
     155//        */ 
     156//        if (startThread && dwErr == ERROR_PIPE_NOT_CONNECTED) { 
     157//          LOG_MESSAGE(_T("Failed to start trayhelper: starting a background thread to do it instead...")); 
     158//          Thread<tray_starter> *pThread = new Thread<tray_starter>(_T("tray-starter-thread")); 
     159//          pThread->createThread(tray_starter::init(dwSessionId, exe, cmdline)); 
     160//          return false; 
     161//        } else if (dwErr == ERROR_PIPE_NOT_CONNECTED) { 
     162//          LOG_ERROR_STD(_T("Thread failed to start trayhelper (will try again): ") + error::format::from_system(dwErr)); 
     163//          return false; 
     164//        } else { 
     165//          LOG_ERROR_STD(_T("Failed to start trayhelper: ") + error::format::from_system(dwErr)); 
     166//          return true; 
     167//        } 
     168//      } else { 
     169//        delete [] buffer; 
     170//        /* 
     171//        if (!RevertToSelf()) { 
     172//          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     173//        } 
     174//        */ 
     175//        LOG_MESSAGE_STD(_T("Started tray in other user session: ") + strEx::itos(dwSessionId)); 
     176//      } 
     177//  
     178//  
     179//      CloseHandle(hToken); 
     180//      return true; 
     181//    } 
     182    return false; 
    182183  } 
    183184}; 
     
    746747    if (boot) { 
    747748      LOG_MESSAGE_STD(_T("Starting shared session...")); 
    748       try { 
    749         shared_server_.reset(new nsclient_session::shared_server_session(this)); 
    750         if (!shared_server_->session_exists()) { 
    751           shared_server_->create_new_session(); 
    752         } else { 
    753           LOG_ERROR_STD(_T("Session already exists cant create a new one!")); 
    754         } 
    755         startTrayIcons(); 
    756       } catch (nsclient_session::session_exception e) { 
    757         LOG_ERROR_STD(_T("Failed to create new session: ") + e.what()); 
    758         shared_server_.reset(NULL); 
    759       } catch (...) { 
    760         LOG_ERROR_STD(_T("Failed to create new session: Unknown exception")); 
    761         shared_server_.reset(NULL); 
    762       } 
     749//      try { 
     750//        shared_server_.reset(new nsclient_session::shared_server_session(this)); 
     751//        if (!shared_server_->session_exists()) { 
     752//          shared_server_->create_new_session(); 
     753//        } else { 
     754//          LOG_ERROR_STD(_T("Session already exists cant create a new one!")); 
     755//        } 
     756//        startTrayIcons(); 
     757//      } catch (nsclient_session::session_exception e) { 
     758//        LOG_ERROR_STD(_T("Failed to create new session: ") + e.what()); 
     759//        shared_server_.reset(NULL); 
     760//      } catch (...) { 
     761//        LOG_ERROR_STD(_T("Failed to create new session: Unknown exception")); 
     762//        shared_server_.reset(NULL); 
     763//      } 
    763764    } else { 
    764765      LOG_MESSAGE_STD(_T("Attaching to shared session...")); 
    765       try { 
    766         std::wstring id = _T("_attached_") + strEx::itos(GetCurrentProcessId()) + _T("_"); 
    767         shared_client_.reset(new nsclient_session::shared_client_session(id, this)); 
    768         if (shared_client_->session_exists()) { 
    769           shared_client_->attach_to_session(id); 
    770         } else { 
    771           LOG_ERROR_STD(_T("No session was found cant attach!")); 
    772         } 
    773         LOG_ERROR_STD(_T("Session is: ") + shared_client_->get_client_id()); 
    774       } catch (nsclient_session::session_exception e) { 
    775         LOG_ERROR_STD(_T("Failed to attach to session: ") + e.what()); 
    776         shared_client_.reset(NULL); 
    777       } catch (...) { 
    778         LOG_ERROR_STD(_T("Failed to attach to session: Unknown exception")); 
    779         shared_client_.reset(NULL); 
    780       } 
     766//      try { 
     767//        std::wstring id = _T("_attached_") + strEx::itos(GetCurrentProcessId()) + _T("_"); 
     768//        shared_client_.reset(new nsclient_session::shared_client_session(id, this)); 
     769//        if (shared_client_->session_exists()) { 
     770//          shared_client_->attach_to_session(id); 
     771//        } else { 
     772//          LOG_ERROR_STD(_T("No session was found cant attach!")); 
     773//        } 
     774//        LOG_ERROR_STD(_T("Session is: ") + shared_client_->get_client_id()); 
     775//      } catch (nsclient_session::session_exception e) { 
     776//        LOG_ERROR_STD(_T("Failed to attach to session: ") + e.what()); 
     777//        shared_client_.reset(NULL); 
     778//      } catch (...) { 
     779//        LOG_ERROR_STD(_T("Failed to attach to session: Unknown exception")); 
     780//        shared_client_.reset(NULL); 
     781//      } 
    781782    } 
    782783  } 
     
    863864 
    864865void NSClientT::startTrayIcons() { 
    865   if (shared_server_.get() == NULL) { 
    866     LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 
    867     return; 
    868   } 
    869   remote_processes::PWTS_SESSION_INFO list; 
    870   DWORD count; 
    871   if (!remote_processes::_WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE , 0, 1, &list, &count)) { 
    872     LOG_ERROR_STD(_T("Failed to enumerate sessions:" ) + error::lookup::last_error()); 
    873   } else { 
    874     LOG_DEBUG_STD(_T("Found ") + strEx::itos(count) + _T(" sessions")); 
    875     for (DWORD i=0;i<count;i++) { 
    876       LOG_DEBUG_STD(_T("Found session: ") + strEx::itos(list[i].SessionId) + _T(" state: ") + strEx::itos(list[i].State)); 
    877       if (list[i].State == remote_processes::_WTS_CONNECTSTATE_CLASS::WTSActive) { 
    878         startTrayIcon(list[i].SessionId); 
    879       } 
    880     } 
    881   } 
     866// if (shared_server_.get() == NULL) { 
     867//    LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 
     868//    return; 
     869// } 
     870// remote_processes::PWTS_SESSION_INFO list; 
     871// DWORD count; 
     872// if (!remote_processes::_WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE , 0, 1, &list, &count)) { 
     873//    LOG_ERROR_STD(_T("Failed to enumerate sessions:" ) + error::lookup::last_error()); 
     874// } else { 
     875//    LOG_DEBUG_STD(_T("Found ") + strEx::itos(count) + _T(" sessions")); 
     876//    for (DWORD i=0;i<count;i++) { 
     877//      LOG_DEBUG_STD(_T("Found session: ") + strEx::itos(list[i].SessionId) + _T(" state: ") + strEx::itos(list[i].State)); 
     878//      if (list[i].State == remote_processes::_WTS_CONNECTSTATE_CLASS::WTSActive) { 
     879//        startTrayIcon(list[i].SessionId); 
     880//      } 
     881//    } 
     882// } 
    882883} 
    883884void NSClientT::startTrayIcon(DWORD dwSessionId) { 
    884   if (shared_server_.get() == NULL) { 
    885     LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 
    886     return; 
    887   } 
    888   if (!shared_server_->re_attach_client(dwSessionId)) { 
    889     if (!tray_starter::start(dwSessionId)) { 
    890       LOG_ERROR_STD(_T("Failed to start session (") + strEx::itos(dwSessionId) + _T("): " ) + error::lookup::last_error()); 
    891     } 
    892   } 
     885// if (shared_server_.get() == NULL) { 
     886//    LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 
     887//    return; 
     888// } 
     889// if (!shared_server_->re_attach_client(dwSessionId)) { 
     890//    if (!tray_starter::start(dwSessionId)) { 
     891//      LOG_ERROR_STD(_T("Failed to start session (") + strEx::itos(dwSessionId) + _T("): " ) + error::lookup::last_error()); 
     892//    } 
     893// } 
    893894} 
    894895 
     
    926927  LOG_DEBUG_STD(_T("Stopping: Settings instance")); 
    927928  settings_manager::destroy_settings(); 
     929//  try { 
     930//    if (shared_client_.get() != NULL) { 
     931//      LOG_DEBUG_STD(_T("Stopping: shared client")); 
     932//      shared_client_->set_handler(NULL); 
     933//      shared_client_->close_session(); 
     934//    } 
     935//  } catch(nsclient_session::session_exception &e) { 
     936//    LOG_ERROR_STD(_T("Exception closing shared client session: ") + e.what()); 
     937//  } catch(...) { 
     938//    LOG_ERROR_STD(_T("Exception closing shared client session: Unknown exception!")); 
     939//  } 
    928940  try { 
    929     if (shared_client_.get() != NULL) { 
    930       LOG_DEBUG_STD(_T("Stopping: shared client")); 
    931       shared_client_->set_handler(NULL); 
    932       shared_client_->close_session(); 
    933     } 
    934   } catch(nsclient_session::session_exception &e) { 
    935     LOG_ERROR_STD(_T("Exception closing shared client session: ") + e.what()); 
    936   } catch(...) { 
    937     LOG_ERROR_STD(_T("Exception closing shared client session: Unknown exception!")); 
    938   } 
    939   try { 
    940     if (shared_server_.get() != NULL) { 
    941       LOG_DEBUG_STD(_T("Stopping: shared server")); 
    942       shared_server_->set_handler(NULL); 
    943       shared_server_->close_session(); 
    944     } 
     941//    if (shared_server_.get() != NULL) { 
     942//      LOG_DEBUG_STD(_T("Stopping: shared server")); 
     943//      shared_server_->set_handler(NULL); 
     944//      shared_server_->close_session(); 
     945//    } 
    945946  } catch(...) { 
    946947    LOG_ERROR_STD(_T("UNknown exception raised: When closing shared session")); 
     
    988989 * @param dwCtrlCode  
    989990 */ 
    990 void WINAPI NSClientT::service_ctrl_dispatch(DWORD dwCtrlCode) { 
     991void WINAPI NSClientT::service_ctrl_dispatch(unsigned long dwCtrlCode) { 
    991992  mainClient.service_ctrl_ex(dwCtrlCode, NULL, NULL, NULL); 
    992993} 
    993994 
    994995 
    995 void NSClientT::service_on_session_changed(DWORD dwSessionId, bool logon, DWORD dwEventType) { 
    996   if (shared_server_.get() == NULL) { 
    997     LOG_DEBUG_STD(_T("No shared session: ignoring change event!")); 
    998     return; 
    999   } 
     996void NSClientT::service_on_session_changed(unsigned long dwSessionId, bool logon, unsigned long dwEventType) { 
     997// if (shared_server_.get() == NULL) { 
     998//    LOG_DEBUG_STD(_T("No shared session: ignoring change event!")); 
     999//    return; 
     1000// } 
    10001001  LOG_DEBUG_STD(_T("Got session change: ") + strEx::itos(dwSessionId)); 
    10011002  if (!logon) { 
     
    12501251 
    12511252NSCAPI::nagiosReturn NSClientT::inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 
    1252   if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 
     1253  /*if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 
    12531254    try { 
    12541255      return shared_client_->inject(command, arguments, splitter, escape, msg, perf); 
     
    12601261      return NSCAPI::returnCRIT; 
    12611262    } 
    1262   } else { 
     1263  } else */{ 
    12631264    unsigned int aLen = 0; 
    12641265    TCHAR ** aBuf = arrayBuffer::split2arrayBuffer(arguments, splitter, aLen, escape); 
     
    12971298    LOG_DEBUG_STD(_T("Injecting: ") + (std::wstring) command + _T(": ") + arrayBuffer::arrayBuffer2string(argument, argLen, _T(", "))); 
    12981299  } 
    1299   if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 
     1300  /*if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 
    13001301    try { 
    13011302      std::wstring msg, perf; 
     
    13121313      return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 
    13131314    } 
    1314   } else { 
     1315  } else */{ 
    13151316    boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
    13161317    if (!readLock.owns_lock()) { 
     
    14061407      return; 
    14071408    } 
    1408     if (shared_server_.get() != NULL && shared_server_->hasClients()) { 
    1409       try { 
    1410         shared_server_->sendLogMessageToClients(msgType, file, line, message); 
    1411       } catch (nsclient_session::session_exception e) { 
    1412         log_broken_message(_T("Failed to send message to clients: ") + e.what()); 
    1413       } 
    1414     } 
     1409//    if (shared_server_.get() != NULL && shared_server_->hasClients()) { 
     1410//      try { 
     1411//        shared_server_->sendLogMessageToClients(msgType, file, line, message); 
     1412//      } catch (nsclient_session::session_exception e) { 
     1413//        log_broken_message(_T("Failed to send message to clients: ") + e.what()); 
     1414//      } 
     1415//    } 
    14151416    std::wstring file_stl = file; 
    14161417    std::wstring::size_type pos = file_stl.find_last_of(_T("\\")); 
  • trunk/service/NSClient++.h

    r208 r209  
    2929#include <map> 
    3030#include <com_helpers.hpp> 
    31 #include <nsclient_session.hpp> 
     31//#include <nsclient_session.hpp> 
    3232#include <boost/thread/thread.hpp> 
    3333#include <boost/thread/locks.hpp> 
     
    6060 * 
    6161 */ 
    62 class NSClientT : public nsclient_session::session_handler_interface { 
     62class NSClientT /*: public nsclient_session::session_handler_interface*/ { 
    6363 
    6464public: 
     
    109109  log_status debug_; 
    110110  com_helper::initialize_com com_helper_; 
     111  /* 
    111112  std::auto_ptr<nsclient_session::shared_client_session> shared_client_; 
    112113  std::auto_ptr<nsclient_session::shared_server_session> shared_server_; 
     114  */ 
    113115  log_cache_type log_cache_; 
    114116  bool plugins_loaded_; 
Note: See TracChangeset for help on using the changeset viewer.