[Spice-devel] [PATCH 5/5] Avoid to use _singleton for VDService
Frediano Ziglio
fziglio at redhat.com
Tue Aug 16 14:49:00 UTC 2016
>
> Hi,
>
> Sorry for taking some time with the other patches ;)
> Remaining patches are good to go!
>
> Acked-by: Victor Toso <victortoso at redhat.com>
>
Thanks
Frediano
> On Fri, Aug 12, 2016 at 12:02:09PM +0100, Frediano Ziglio wrote:
> > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> > vdservice/vdservice.cpp | 32 +++++++++-----------------------
> > 1 file changed, 9 insertions(+), 23 deletions(-)
> >
> > 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);
> > }
> > --
More information about the Spice-devel
mailing list