[Spice-commits] 4 commits - vdagent/vdagent.cpp vdservice/vdservice.cpp
Frediano Ziglio
fziglio at kemper.freedesktop.org
Tue Aug 16 14:44:40 UTC 2016
vdagent/vdagent.cpp | 14 +++++++-------
vdservice/vdservice.cpp | 36 +++++++++++-------------------------
2 files changed, 18 insertions(+), 32 deletions(-)
New commits:
commit efcd07af8b2e872fd2ec7df6917f367329c52d0d
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Aug 11 17:03:18 2016 +0100
Avoid to use _singleton for VDService
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index ef1ed9f..d2bedaa 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -59,14 +59,13 @@ typedef std::queue<int> VDControlQueue;
class VDService {
public:
- static VDService* get();
- ~VDService();
- bool run();
- bool install();
- bool uninstall();
+ static bool run();
+ static bool install();
+ static bool uninstall();
private:
VDService();
+ ~VDService();
bool execute();
void stop();
static DWORD WINAPI control_handler(DWORD control, DWORD event_type,
@@ -87,7 +86,6 @@ private:
}
}
private:
- static VDService* _singleton;
SERVICE_STATUS _status;
SERVICE_STATUS_HANDLE _status_handle;
PROCESS_INFORMATION _agent_proc_info;
@@ -109,16 +107,6 @@ private:
unsigned _events_count;
};
-VDService* VDService::_singleton = NULL;
-
-VDService* VDService::get()
-{
- if (!_singleton) {
- _singleton = new VDService();
- }
- return (VDService*)_singleton;
-}
-
VDService::VDService()
: _status_handle (0)
, _events (NULL)
@@ -138,7 +126,6 @@ VDService::VDService()
_agent_path[0] = wchar_t('\0');
MUTEX_INIT(_agent_mutex);
MUTEX_INIT(_control_mutex);
- _singleton = this;
}
VDService::~VDService()
@@ -322,7 +309,7 @@ DWORD WINAPI VDService::control_handler(DWORD control, DWORD event_type, LPVOID
VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
{
- VDService* s = _singleton;
+ VDService* s = new VDService;
SERVICE_STATUS* status;
TCHAR log_path[MAX_PATH];
TCHAR full_path[MAX_PATH];
@@ -382,6 +369,7 @@ VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
SetServiceStatus(s->_status_handle, status);
#endif //DEBUG_VDSERVICE
vd_printf("***Service stopped***");
+ delete s;
}
bool VDService::execute()
@@ -839,18 +827,16 @@ int _tmain(int argc, TCHAR* argv[])
printf("vdservice is not supported in this system version\n");
return -1;
}
- VDService* vdservice = VDService::get();
if (argc > 1) {
if (lstrcmpi(argv[1], TEXT("install")) == 0) {
- success = vdservice->install();
+ success = VDService::install();
} else if (lstrcmpi(argv[1], TEXT("uninstall")) == 0) {
- success = vdservice->uninstall();
+ success = VDService::uninstall();
} else {
printf("Use: vdservice install / uninstall\n");
}
} else {
- success = vdservice->run();
+ success = VDService::run();
}
- delete vdservice;
return (success ? 0 : -1);
}
commit f96d57565948e3aa74fef8df38f2fd0197956cfe
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Aug 11 17:01:10 2016 +0100
Pass class pointer using thread parameter
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index ad0d7cd..b4a3426 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -247,16 +247,17 @@ VDAgent::~VDAgent()
DWORD WINAPI VDAgent::event_thread_proc(LPVOID param)
{
+ VDAgent *agent = static_cast<VDAgent *>(param);
HANDLE desktop_event = OpenEvent(SYNCHRONIZE, FALSE, L"WinSta0_DesktopSwitch");
if (!desktop_event) {
vd_printf("OpenEvent() failed: %lu", GetLastError());
return 1;
}
- while (_singleton->_running) {
+ while (agent->_running) {
DWORD wait_ret = WaitForSingleObject(desktop_event, INFINITE);
switch (wait_ret) {
case WAIT_OBJECT_0:
- _singleton->set_control_event(CONTROL_DESKTOP_SWITCH);
+ agent->set_control_event(CONTROL_DESKTOP_SWITCH);
break;
case WAIT_TIMEOUT:
default:
@@ -332,7 +333,7 @@ bool VDAgent::run()
return false;
}
_running = true;
- event_thread = CreateThread(NULL, 0, event_thread_proc, NULL, 0, &event_thread_id);
+ event_thread = CreateThread(NULL, 0, event_thread_proc, this, 0, &event_thread_id);
if (!event_thread) {
vd_printf("CreateThread() failed: %lu", GetLastError());
cleanup();
commit 2ab513267be50ade56d876e61bd052b496937b71
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Aug 11 17:00:51 2016 +0100
Don't use _singleton if we already have the right this pointer
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 2b63267..ad0d7cd 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -639,13 +639,12 @@ bool VDAgent::handle_mouse_event(VDAgentMouseState* state)
bool VDAgent::handle_mon_config(VDAgentMonitorsConfig* mon_config, uint32_t port)
{
- VDAgent* a = _singleton;
VDIChunk* reply_chunk;
VDAgentMessage* reply_msg;
VDAgentReply* reply;
size_t display_count;
- a->_updating_display_config = true;
+ _updating_display_config = true;
display_count = _desktop_layout->get_display_count();
for (uint32_t i = 0; i < display_count; i++) {
@@ -676,9 +675,9 @@ bool VDAgent::handle_mon_config(VDAgentMonitorsConfig* mon_config, uint32_t port
_desktop_layout->set_displays();
}
- a->_updating_display_config = false;
+ _updating_display_config = false;
/* refresh again, in case something else changed */
- a->_desktop_layout->get_displays();
+ _desktop_layout->get_displays();
DWORD msg_size = VD_MESSAGE_HEADER_SIZE + sizeof(VDAgentReply);
reply_chunk = new_chunk(msg_size);
commit 2a2390df7e4dcc1c778812863a5767594dc66290
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Aug 11 16:28:46 2016 +0100
Pass class pointer using control context
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index 12f7644..ef1ed9f 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -284,7 +284,7 @@ void VDService::handle_control_event()
DWORD WINAPI VDService::control_handler(DWORD control, DWORD event_type, LPVOID event_data,
LPVOID context)
{
- VDService* s = _singleton;
+ VDService* s = static_cast<VDService *>(context);
DWORD ret = NO_ERROR;
ASSERT(s);
@@ -352,7 +352,7 @@ VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
status->dwWaitHint = 0;
#ifndef DEBUG_VDSERVICE
s->_status_handle = RegisterServiceCtrlHandlerEx(VD_SERVICE_NAME, &VDService::control_handler,
- NULL);
+ s);
if (!s->_status_handle) {
vd_printf("RegisterServiceCtrlHandler failed\n");
return;
More information about the Spice-commits
mailing list