Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
webwindow.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_webgui
3/// \ingroup webwidgets
4/// Minimal server/client code for working with RWebWindow class.
5///
6/// File webwindow.cxx shows how RWebWindow can be created and used
7/// In webwindow.html simple client code is provided.
8///
9/// \macro_code
10///
11/// \author Sergey Linev
12
13#include <ROOT/RWebWindow.hxx>
14
15std::shared_ptr<ROOT::RWebWindow> window;
16
17int counter = 0;
18
19void ProcessData(unsigned connid, const std::string &arg)
20{
21 printf("Get msg %s \n", arg.c_str());
22
23 counter++;
24
25 if (arg == "get_text") {
26 // send arbitrary text message
27 window->Send(connid, TString::Format("Message%d", counter).Data());
28 } else if (arg == "get_binary") {
29 // send float array as binary
30 float arr[10];
31 for (int n = 0; n < 10; ++n)
32 arr[n] = counter;
33 window->SendBinary(connid, arr, sizeof(arr));
34 } else if (arg == "halt") {
35 // terminate ROOT
36 window->TerminateROOT();
37 }
38}
39
40void webwindow()
41{
42 // create window
43 window = ROOT::RWebWindow::Create();
44
45 // configure default html page
46 // either HTML code can be specified or just name of file after 'file:' prefix
47 std::string fdir = __FILE__;
48 auto pos = fdir.find("webwindow.cxx");
49 if (pos > 0)
50 fdir.resize(pos);
51 else
52 fdir = gROOT->GetTutorialsDir() + std::string("/webgui/webwindow/");
53 window->SetDefaultPage("file:" + fdir + "webwindow.html");
54
55 // this is call-back, invoked when message received from client
56 window->SetDataCallBack(ProcessData);
57
58 window->SetGeometry(300, 500); // configure predefined geometry
59
60 window->Show();
61}
#define gROOT
Definition TROOT.h:406
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
const Int_t n
Definition legend1.C:16