Skip to content

Commit

Permalink
webgui: use unique_ptr where it make sense
Browse files Browse the repository at this point in the history
Move constructor/destructor into implementation part, where contained
classes are defined.
  • Loading branch information
linev authored and couet committed Nov 9, 2017
1 parent 5464ef8 commit 640419c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions gui/webdisplay/inc/ROOT/TWebWindow.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private:
std::string fDefaultPage; ///<! HTML page (or file name) returned when window URL is opened
std::string fPanelName; ///<! panel name which should be shown in the window
unsigned fId{0}; ///<! unique identifier
std::shared_ptr<TWebWindowWSHandler> fWSHandler; ///<! specialize websocket handler for all incoming connections
std::unique_ptr<TWebWindowWSHandler> fWSHandler; ///<! specialize websocket handler for all incoming connections
bool fShown{false}; ///<! true when window was shown at least once
unsigned fConnCnt{0}; ///<! counter of new connections to assign ids
std::list<WebConn> fConn; ///<! list of all accepted connections
Expand Down Expand Up @@ -98,7 +98,7 @@ private:
public:

/// default constructor
TWebWindow() = default;
TWebWindow();

/// destructor
~TWebWindow();
Expand Down
6 changes: 3 additions & 3 deletions gui/webdisplay/inc/ROOT/TWebWindowsManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <memory>
#include <string>
#include <list>
// #include <list>

#include "THttpEngine.h"

Expand All @@ -35,7 +35,7 @@ class TWebWindowsManager {
friend class TWebWindow;

private:
THttpServer *fServer{0}; ///<! central communication with the all used displays
std::unique_ptr<THttpServer> fServer; ///<! central communication with the all used displays
std::string fAddr; ///<! HTTP address of the server
// std::list<std::shared_ptr<TWebWindow>> fDisplays; ///<! list of existing displays (not used at the moment)
unsigned fIdCnt{0}; ///<! counter for identifiers
Expand All @@ -51,7 +51,7 @@ private:

public:
/// Default constructor
TWebWindowsManager() = default;
TWebWindowsManager();

/// Destructor
~TWebWindowsManager();
Expand Down
11 changes: 9 additions & 2 deletions gui/webdisplay/src/TWebWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ using TWebWindow::Send() method and call-back function assigned via TWebWindow::
*/

//////////////////////////////////////////////////////////////////////////////////////////
/// TWebWindow constructor
/// Should be here defined here because of std::unique_ptr<TWebWindowWSHandler>

ROOT::Experimental::TWebWindow::TWebWindow() = default;


//////////////////////////////////////////////////////////////////////////////////////////
/// destructor - closed all connections and remove window from manager
/// TWebWindow destructor
/// Closes all connections and remove window from manager

ROOT::Experimental::TWebWindow::~TWebWindow()
{
Expand Down Expand Up @@ -101,7 +108,7 @@ void ROOT::Experimental::TWebWindow::SetPanelName(const std::string &name)
void ROOT::Experimental::TWebWindow::CreateWSHandler()
{
if (!fWSHandler)
fWSHandler = std::make_shared<TWebWindowWSHandler>(*this, Form("win%u", GetId()));
fWSHandler = std::make_unique<TWebWindowWSHandler>(*this, Form("win%u", GetId()));
}

//////////////////////////////////////////////////////////////////////////////////////////
Expand Down
19 changes: 11 additions & 8 deletions gui/webdisplay/src/TWebWindowsManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ std::shared_ptr<ROOT::Experimental::TWebWindowsManager> &ROOT::Experimental::TWe
return sInstance;
}


//////////////////////////////////////////////////////////////////////////////////////////
/// window manager constructor
/// Required here for correct usage of unique_ptr<THttpServer>

ROOT::Experimental::TWebWindowsManager::TWebWindowsManager() = default;

//////////////////////////////////////////////////////////////////////////////////////////
/// window manager destructor
/// Closes THttpServer instance
/// Required here for correct usage of unique_ptr<THttpServer>

ROOT::Experimental::TWebWindowsManager::~TWebWindowsManager()
{
if (fServer) {
delete fServer;
fServer = 0;
}
}

//////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -67,7 +70,7 @@ ROOT::Experimental::TWebWindowsManager::~TWebWindowsManager()
bool ROOT::Experimental::TWebWindowsManager::CreateHttpServer(bool with_http)
{
if (!fServer)
fServer = new THttpServer("dummy");
fServer = std::make_unique<THttpServer>("dummy");

if (!with_http || (fAddr.length() > 0))
return true;
Expand Down Expand Up @@ -217,7 +220,7 @@ bool ROOT::Experimental::TWebWindowsManager::Show(ROOT::Experimental::TWebWindow
printf("Show canvas in Qt5 window: %s\n", addr.Data());

FunctionQt5 func = (FunctionQt5)symbol_qt5;
func(addr.Data(), fServer, batch_mode, win.GetWidth(), win.GetHeight());
func(addr.Data(), fServer.get(), batch_mode, win.GetWidth(), win.GetHeight());
return false;
}

Expand All @@ -232,7 +235,7 @@ bool ROOT::Experimental::TWebWindowsManager::Show(ROOT::Experimental::TWebWindow
printf("Show canvas in CEF window: %s\n", addr.Data());

FunctionCef3 func = (FunctionCef3)symbol_cef;
func(addr.Data(), fServer, batch_mode, rootsys, cef_path, win.GetWidth(), win.GetHeight());
func(addr.Data(), fServer.get(), batch_mode, rootsys, cef_path, win.GetWidth(), win.GetHeight());

return true;
}
Expand Down

0 comments on commit 640419c

Please sign in to comment.