ROOT logo
#ifndef HONLINEMONCLIENTMAIN_H
#define HONLINEMONCLIENTMAIN_H

#include "TList.h"
#include "TGButton.h"
#include "TApplication.h"
#include "TSocket.h"
#include "TMessage.h"
#include "TThread.h"
#include "TSystem.h"
#include "TGMsgBox.h"

#include <map>
#include <time.h>

#include "honlinemonhist.h"
#include "honlinemonstack.h"
#include "honlinehistarray.h"
#include "honlinetrendhist.h"


class HOnlineMonClientXML;
class HOnlineMonClientMainWin;
class HOnlineMonClientDet;
class HOnlineMonClientTabWin;
class HOnlineMonClientSimpleWin;
class HOnlineMonClientTab;
class HOnlineMonClientCanvas;
class HOnlineMonClientHist;


using namespace std;

class HOnlineMonClientMain {
public:
	
	HOnlineMonClientMain(TString filename="");
	virtual ~HOnlineMonClientMain();
	
	// if parameters are given, connect to specified server and send command and exit
	// else connect to server specified in configfile and start client
	void Init(Bool_t sendCmdOnly=kFALSE, TString host="", Int_t port=0, TString cmd="");

	void SetServerhost(TString host);
	TString GetServerhost();
	
	void SetServerport(Int_t port);
	Int_t GetServerport();
        Int_t GetUpdateInterval() { return UpdateInterval;}
 	
 	static void  SetAutoSaveInterval(Int_t minute) {AutoSaveInterval = minute;}
 	static void  SetAutoSaveIntervalOnline(Int_t minute) {AutoSaveIntervalOnline = minute;}
       
	// add / remove histos+canvases from the global lists/map
	void AddHist(HOnlineMonClientCanvas* canvas, HOnlineMonClientHist* hist);
	void RemoveHist(HOnlineMonClientCanvas* canvas, HOnlineMonClientHist* hist);
	
	// gui event handler, args must be char*
	void HandleControlbuttonClick(char *detectorname);
	void HandleSingleWindowClose(char *windowname, char* detectorname); 
	void HandleRefreshRateChange();
	void HandleAutoSaveRateChange();
	void HandleMainWindowClose();
	void HandleSendStopServer();      // send stop command to server
	void HandleSendResetHists();      // send rest all hists
	void HandleSnapshotSave();
	void HandleSnapshotSaveOnline();
	void HandleConnectionError();
	void HandleTryClose();
	TList listDetectors;		// list of all detectors
	HOnlineMonClientMainWin* clientmainwin;	// pointer to mainwindow class
	TThread* getMainThread() { return mainThread; }
	Int_t    IsMasterClient() { return isMasterClient <= 0 ? kFALSE : kTRUE ;}
	Int_t    GetMasterClient(){ return isMasterClient ;}
        void     SetIsMasterClient(Bool_t master) {  isMasterClient = master;}
        Int_t    GetReconnect(){ return doReconnect;}
        void     SetReconnect(Int_t recon) { doReconnect = recon;}

private:
	void CreateClientConfig(TString xmlfile);
	void CreateDetGui(HOnlineMonClientDet* detector);
	void DestroyDetGui(HOnlineMonClientDet* detector);
	void DestroySingleWindow(HOnlineMonClientSimpleWin* window);
	void DestroySingleWindow(HOnlineMonClientTabWin* window);
	
	// global hist lists/map
	map <TString, TString> pad2hist;	// provide mapping between subpadname and histogram name
	TList listHists;			// global list to store the opened histograms.
						// all histos in this list will be updated
	TList listPads;				// global list to store the canvas subpads
						// all subpads in this list will be updated
	
	// network, histograms
	Bool_t Connect(TString host, Int_t port);
	Bool_t ReConnect(TString host, Int_t port);
	HOnlineMonHistAddon* GetHist(TString histoname); // get histogram from network
	Bool_t UpdateHist(HOnlineMonClientHist* hist); // update a single histogram, calls GetHist to get new histo
	void UpdateHists(); // update all hists: iterates over visible histos and calls UpdateHist for each hist
	
	// thread
	static TThread* mainThread  ; // thread for the client program
	TThread* updateThread; // thread to update histograms
	static void* ThreadUpdateHists(void* arg); // thread function, runs into the updateThread
	
	// network vars
	TSocket* socket;		// socket for network communication
	TString serverhost;
	Int_t serverport;
	
	// send commands to server
	TList*  GetListOfHistograms(); // get list of all available histograms from server
	TString SendCmdToServer(TString cmd); // send command to server and get a TString from server back
	
	
	void SetUpdateInterval(Int_t msec);
	Int_t UpdateInterval; // update interval in secs.

	static Int_t AutoSaveInterval;        // auto save interval in minutes.
	static Int_t AutoSaveIntervalOnline;  // auto save interval in minutes.
        static time_t lastSaved;        // remember the time when last saved (in seconds since 1970)
        static time_t lastSavedOnline;  // remember the time when last saved (in seconds since 1970)
	static ULong64_t lastSumBytes ; // remember last number of bytes recieved

	static Int_t isMasterClient;    // remember if it was a master client
        Int_t  doReconnect;             // 0 = stop at crash, 1 = ask for reconnect (default), 2 = auto reconnect

	TString configfile; // name of the xml config file
	
	Bool_t updateComplete;	// after complete update of histograms, thread sets this to true
				// thread checks updateComplete before calling the update function to
				// ensure that the last update was completed. So no call to update function is possible,
				// if update function has not finished yet.

	ClassDef(HOnlineMonClientMain, 1);

};

#endif

 honlinemonclientmain.h:1
 honlinemonclientmain.h:2
 honlinemonclientmain.h:3
 honlinemonclientmain.h:4
 honlinemonclientmain.h:5
 honlinemonclientmain.h:6
 honlinemonclientmain.h:7
 honlinemonclientmain.h:8
 honlinemonclientmain.h:9
 honlinemonclientmain.h:10
 honlinemonclientmain.h:11
 honlinemonclientmain.h:12
 honlinemonclientmain.h:13
 honlinemonclientmain.h:14
 honlinemonclientmain.h:15
 honlinemonclientmain.h:16
 honlinemonclientmain.h:17
 honlinemonclientmain.h:18
 honlinemonclientmain.h:19
 honlinemonclientmain.h:20
 honlinemonclientmain.h:21
 honlinemonclientmain.h:22
 honlinemonclientmain.h:23
 honlinemonclientmain.h:24
 honlinemonclientmain.h:25
 honlinemonclientmain.h:26
 honlinemonclientmain.h:27
 honlinemonclientmain.h:28
 honlinemonclientmain.h:29
 honlinemonclientmain.h:30
 honlinemonclientmain.h:31
 honlinemonclientmain.h:32
 honlinemonclientmain.h:33
 honlinemonclientmain.h:34
 honlinemonclientmain.h:35
 honlinemonclientmain.h:36
 honlinemonclientmain.h:37
 honlinemonclientmain.h:38
 honlinemonclientmain.h:39
 honlinemonclientmain.h:40
 honlinemonclientmain.h:41
 honlinemonclientmain.h:42
 honlinemonclientmain.h:43
 honlinemonclientmain.h:44
 honlinemonclientmain.h:45
 honlinemonclientmain.h:46
 honlinemonclientmain.h:47
 honlinemonclientmain.h:48
 honlinemonclientmain.h:49
 honlinemonclientmain.h:50
 honlinemonclientmain.h:51
 honlinemonclientmain.h:52
 honlinemonclientmain.h:53
 honlinemonclientmain.h:54
 honlinemonclientmain.h:55
 honlinemonclientmain.h:56
 honlinemonclientmain.h:57
 honlinemonclientmain.h:58
 honlinemonclientmain.h:59
 honlinemonclientmain.h:60
 honlinemonclientmain.h:61
 honlinemonclientmain.h:62
 honlinemonclientmain.h:63
 honlinemonclientmain.h:64
 honlinemonclientmain.h:65
 honlinemonclientmain.h:66
 honlinemonclientmain.h:67
 honlinemonclientmain.h:68
 honlinemonclientmain.h:69
 honlinemonclientmain.h:70
 honlinemonclientmain.h:71
 honlinemonclientmain.h:72
 honlinemonclientmain.h:73
 honlinemonclientmain.h:74
 honlinemonclientmain.h:75
 honlinemonclientmain.h:76
 honlinemonclientmain.h:77
 honlinemonclientmain.h:78
 honlinemonclientmain.h:79
 honlinemonclientmain.h:80
 honlinemonclientmain.h:81
 honlinemonclientmain.h:82
 honlinemonclientmain.h:83
 honlinemonclientmain.h:84
 honlinemonclientmain.h:85
 honlinemonclientmain.h:86
 honlinemonclientmain.h:87
 honlinemonclientmain.h:88
 honlinemonclientmain.h:89
 honlinemonclientmain.h:90
 honlinemonclientmain.h:91
 honlinemonclientmain.h:92
 honlinemonclientmain.h:93
 honlinemonclientmain.h:94
 honlinemonclientmain.h:95
 honlinemonclientmain.h:96
 honlinemonclientmain.h:97
 honlinemonclientmain.h:98
 honlinemonclientmain.h:99
 honlinemonclientmain.h:100
 honlinemonclientmain.h:101
 honlinemonclientmain.h:102
 honlinemonclientmain.h:103
 honlinemonclientmain.h:104
 honlinemonclientmain.h:105
 honlinemonclientmain.h:106
 honlinemonclientmain.h:107
 honlinemonclientmain.h:108
 honlinemonclientmain.h:109
 honlinemonclientmain.h:110
 honlinemonclientmain.h:111
 honlinemonclientmain.h:112
 honlinemonclientmain.h:113
 honlinemonclientmain.h:114
 honlinemonclientmain.h:115
 honlinemonclientmain.h:116
 honlinemonclientmain.h:117
 honlinemonclientmain.h:118
 honlinemonclientmain.h:119
 honlinemonclientmain.h:120
 honlinemonclientmain.h:121
 honlinemonclientmain.h:122
 honlinemonclientmain.h:123
 honlinemonclientmain.h:124
 honlinemonclientmain.h:125
 honlinemonclientmain.h:126
 honlinemonclientmain.h:127
 honlinemonclientmain.h:128
 honlinemonclientmain.h:129
 honlinemonclientmain.h:130
 honlinemonclientmain.h:131
 honlinemonclientmain.h:132
 honlinemonclientmain.h:133
 honlinemonclientmain.h:134
 honlinemonclientmain.h:135
 honlinemonclientmain.h:136
 honlinemonclientmain.h:137
 honlinemonclientmain.h:138
 honlinemonclientmain.h:139