source: nscp/service/tray_manager.hpp @ 291548e

0.4.00.4.10.4.2
Last change on this file since 291548e was f0eb62d, checked in by Michael Medin <michael@…>, 4 years ago

Refactored service into its own project

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#pragma once
2
3#include "NSCPlugin.h"
4
5namespace tray_manager {
6        class tray_exception {
7                std::wstring what_;
8        public:
9                tray_exception(std::wstring what) : what_(what) {
10#ifdef _DEBUG
11                        std::wcout << _T("TrayManager throw an exception: ") << what << std::endl;
12#endif
13
14                }
15                std::wstring what() { return what_; }
16        };
17
18        class tray_manager {
19                NSCPlugin *plugin_;
20                event_handler event_;
21        public:
22                tray_manager(NSCPlugin *plugin) : plugin_(plugin), event_(_T("NSCTrayWaitStop")) {}
23
24                boolean start_and_wait() {
25                        if (plugin_ == NULL)
26                                return false;
27                        try {
28                                plugin_->showTray();
29                        } catch (NSPluginException e) {
30                                throw tray_exception(_T("Systemtray manager failed to show tray: ") + e.error_);
31                        } catch (...) {
32                                throw tray_exception(_T("Systemtray manager failed to show tray: Unknown exception"));
33                        }
34                        event_.accuire(INFINITE);
35                        try {
36                                plugin_->hideTray();
37                        } catch (NSPluginException e) {
38                                throw tray_exception(_T("Systemtray manager failed to close tray: ") + e.error_);
39                        } catch (...) {
40                                throw tray_exception(_T("Systemtray manager failed to close tray: Unknown exception"));
41                        }
42                        return true;
43                }
44                void request_close() {
45                        event_.set();
46                }
47        };
48}
Note: See TracBrowser for help on using the repository browser.