[Spice-devel] [vdagent-win PATCH v5 4/6] Use destructor instead of cleanup function

Christophe Fergeau cfergeau at redhat.com
Wed Jul 18 09:26:52 UTC 2018


Acked-by: Christophe Fergeau <cfergeau at redhat.com>

On Mon, Jul 09, 2018 at 09:51:42AM +0100, Frediano Ziglio wrote:
> More C++ style.
> Also avoids missing cleanup calls.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
> ---
>  vdagent/vdagent.cpp | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
> index d603dda..9a40388 100644
> --- a/vdagent/vdagent.cpp
> +++ b/vdagent/vdagent.cpp
> @@ -116,7 +116,6 @@ private:
>      void load_display_setting();
>      bool send_announce_capabilities(bool request);
>      void cleanup_in_msg();
> -    void cleanup();
>      bool has_capability(unsigned int capability) const {
>          return VD_AGENT_HAS_CAPABILITY(_client_caps.begin(), _client_caps.size(),
>                                         capability);
> @@ -221,6 +220,7 @@ VDAgent::VDAgent()
>  
>  VDAgent::~VDAgent()
>  {
> +    close_vio_serial();
>      CloseHandle(_stop_event);
>      CloseHandle(_control_event);
>      delete _log;
> @@ -255,6 +255,8 @@ bool VDAgent::run()
>      HANDLE event_thread;
>      WNDCLASS wcls;
>  
> +    close_vio_serial();
> +
>      if (!ProcessIdToSessionId(GetCurrentProcessId(), &session_id)) {
>          vd_printf("ProcessIdToSessionId failed %lu", GetLastError());
>          return false;
> @@ -287,7 +289,6 @@ bool VDAgent::run()
>          _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
>      if (!_control_event) {
>          vd_printf("CreateEvent() failed: %lu", GetLastError());
> -        cleanup();
>          return false;
>      }
>      ResetEvent(_control_event);
> @@ -300,7 +301,6 @@ bool VDAgent::run()
>      wcls.lpszClassName = VD_AGENT_WINCLASS_NAME;
>      if (!RegisterClass(&wcls)) {
>          vd_printf("RegisterClass() failed: %lu", GetLastError());
> -        cleanup();
>          return false;
>      }
>      _desktop_layout.reset(new DesktopLayout());
> @@ -308,20 +308,17 @@ bool VDAgent::run()
>          vd_printf("No QXL devices!");
>      }
>      if (!init_vio_serial()) {
> -        cleanup();
>          return false;
>      }
>      if (!ReadFileEx(_vio_serial, _read_buf, sizeof(VDIChunk), &_read_overlapped, read_completion) &&
>              GetLastError() != ERROR_IO_PENDING) {
>          vd_printf("vio_serial read error %lu", GetLastError());
> -        cleanup();
>          return false;
>      }
>      _running = true;
>      event_thread = CreateThread(NULL, 0, event_thread_proc, this, 0, NULL);
>      if (!event_thread) {
>          vd_printf("CreateThread() failed: %lu", GetLastError());
> -        cleanup();
>          return false;
>      }
>      send_announce_capabilities(true);
> @@ -335,15 +332,9 @@ bool VDAgent::run()
>      }
>      vd_printf("Agent stopped");
>      CloseHandle(event_thread);
> -    cleanup();
>      return true;
>  }
>  
> -void VDAgent::cleanup()
> -{
> -    close_vio_serial();
> -}
> -
>  void VDAgent::set_control_event(control_command_t control_command)
>  {
>      MutexLocker lock(_control_mutex);
> -- 
> 2.17.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180718/6612861b/attachment-0001.sig>


More information about the Spice-devel mailing list