OpendTect  6.6
servicemgrbase.h
Go to the documentation of this file.
1 #pragma once
2 /*+
3 * ________________________________________________________________________
4 *
5 * (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6 * Author: A. Huck
7 * Date: Oct 2020
8 * RCS: $Id$
9 * ________________________________________________________________________
10 *
11 * -*/
12 
13 #include "netservice.h"
14 
15 #include "ptrman.h"
16 
17 namespace Network {
18  class RequestConnection;
19  class RequestPacket;
20  class RequestServer;
21 };
22 
23 namespace OD { namespace JSON { class Object; }; };
24 
25 
30 public:
31 
32  virtual ~ServiceMgrBase();
33 
34  bool isOK(bool islocal) const;
35 
36  Network::Authority getAuthority(bool islocal) const;
37  virtual void stopServer(bool islocal);
38 
39  static const char* sKeyStatusEv() { return "status"; }
40  static const char* sKeyCloseEv() { return "close"; }
41  static const char* sKeySurveyChangeEv() { return "surveychange"; }
42  static const char* sKeyPyEnvChangeEv() { return "pyenvchange"; }
43 
44  static const char* sKeyEvent() { return "event"; }
45  static const char* sKeyRegister() { return "register"; }
46  static const char* sKeyDeregister() { return "deregister"; }
47 
48  static const char* sKeyODServer() { return "odserver"; }
49 
50 protected:
51  ServiceMgrBase(const char* servicenm);
52  /* Main constructor returns a local service */
53  ServiceMgrBase(const char* servicenm,bool assignport,
55  /* Constructor for a TCP-based server */
56 
57  bool isMainService() const;
59  bool addTCPServer(bool assignport=true,
61 
63  const char* servicenm,const char* action);
65  const char* servicenm,const char* reqkey,
66  const OD::JSON::Object&);
67 
71  virtual bool canParseAction(const char*,uiRetVal&);
72  virtual bool canParseRequest(const OD::JSON::Object&,
73  uiRetVal&);
74 
77 
78  virtual uiRetVal doHandleAction(const char* action);
80 
82 
83  void sendOK();
84  void sendErr(uiRetVal&);
85 
86  virtual void doPyEnvChange(CallBacker*) {}
87  virtual void doSurveyChanged(CallBacker*) {}
88 
89  virtual void doAppClosing(CallBacker*);
90  /*<! Must be re-implemented to delete all
91  important objects before the application
92  is closed.
93  Must end by calling the base class
94  implementation */
95 
96  virtual void closeApp();
97 
98  static bool addApplicationAuthority(bool local,OS::MachineCommand&);
99  static const ServiceMgrBase* theMain();
100 
101  static void debugMsg(const char*); // Not implemented
102 
103  static const char* sKeyClientAppCloseEv() { return "clientapp-closing"; }
104 
105 private:
106 
107  mStruct(Network) packetData
108  {
109  packetData( const Network::RequestConnection* conn )
110  : conn_(conn)
111  {}
112  ~packetData();
113 
114  const Network::RequestConnection* conn_;
115  ServiceMgrBase* servicemgr_ = nullptr;
116  BufferString action_;
117  OD::JSON::Object* request_ = nullptr;
118  mutable uiRetVal msg_;
119  };
120  ServiceMgrBase(const ServiceMgrBase&) = delete;
122 
125 
126  void init(bool islocal,bool assignport=true,
128  bool useServer(Network::RequestServer*,bool islocal);
130  const char* servicenm,
131  const OD::JSON::Object&);
132 
133  bool canDoAction(const OD::JSON::Object&,packetData&);
134  bool canDoRequest(const OD::JSON::Object&,packetData&);
135  uiRetVal applyInOtherThread(const packetData&);
138 
139  bool isServerOK(bool local) const;
140  bool& serverIsMine(bool islocal);
141 
147 
151 
152  Network::RequestServer* tcpserver_ = nullptr;
153  Network::RequestServer* localserver_ = nullptr;
154  bool tcpserverismine_ = true;
155  bool localserverismine_ = true;
156  Network::RequestConnection* tcpconn_ = nullptr;
157  Network::RequestConnection* localconn_ = nullptr;
160 
161  static const char* sKeyAction() { return "action"; }
162  static const char* sKeyError() { return "error"; }
163  static const char* sKeyOK() { return "ok"; }
164 
166 
167 };
ServiceMgrBase::applydata_
ObjectSet< packetData > applydata_
Definition: servicemgrbase.h:159
ServiceMgrBase::appClosingCB
void appClosingCB(CallBacker *)
ServiceMgrBase::sKeyClientAppCloseEv
static const char * sKeyClientAppCloseEv()
Definition: servicemgrbase.h:103
ServiceMgrBase::ServiceMgrBase
ServiceMgrBase(const char *servicenm)
ServiceMgrBase::sendRequest_
static uiRetVal sendRequest_(const Network::Authority &, const char *servicenm, const OD::JSON::Object &)
NamedCallBacker
CallBacker object with a name. Use if you want your object to be able to send and receive CallBack's,...
Definition: namedobj.h:72
ServiceMgrBase::sKeyStatusEv
static const char * sKeyStatusEv()
Definition: servicemgrbase.h:39
ServiceMgrBase::sendOK
void sendOK()
ObjectSet< packetData >
ServiceMgrBase::isServerOK
bool isServerOK(bool local) const
ServiceMgrBase::theMain
static const ServiceMgrBase * theMain()
OD
OpendTect.
Definition: commontypes.h:28
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
ServiceMgrBase::canParseRequest
virtual bool canParseRequest(const OD::JSON::Object &, uiRetVal &)
ServiceMgrBase::init
void init(bool islocal, bool assignport=true, Network::SpecAddr=Network::Any)
ServiceMgrBase::sKeyError
static const char * sKeyError()
Definition: servicemgrbase.h:162
Network
Definition: jobcommunic.h:22
Network::Authority
Definition: networkcommon.h:56
ServiceMgrBase::addTCPServer
bool addTCPServer(bool assignport=true, Network::SpecAddr=Network::Any)
ServiceMgrBase::sKeyPyEnvChangeEv
static const char * sKeyPyEnvChangeEv()
Definition: servicemgrbase.h:42
ServiceMgrBase::startHandleAction
CNotifier< ServiceMgrBase, BufferString > startHandleAction
Definition: servicemgrbase.h:75
uiRetVal
Definition: uistringset.h:105
ServiceMgrBase::ServiceMgrBase
ServiceMgrBase(const char *servicenm, bool assignport, Network::SpecAddr=Network::Any)
CallBacker
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:185
ServiceMgrBase::packetArrivedCB
void packetArrivedCB(CallBacker *)
ServiceMgrBase::handleActionRequestInThread
uiRetVal handleActionRequestInThread(const packetData &)
mODTextTranslationClass
#define mODTextTranslationClass(clss)
Definition: uistring.h:40
Network::RequestConnection
Definition: netreqconnection.h:43
ServiceMgrBase::getPythEnvRequestInfo
static void getPythEnvRequestInfo(OD::JSON::Object &)
ServiceMgrBase::pyenvChangeCB
void pyenvChangeCB(CallBacker *)
ServiceMgrBase::ServiceMgrBase
ServiceMgrBase(const ServiceMgrBase &)=delete
ServiceMgrBase::closeApp
virtual void closeApp()
ServiceMgrBase::operator=
ServiceMgrBase & operator=(const ServiceMgrBase &)=delete
ServiceMgrBase::pythEnvChangedReq
uiRetVal pythEnvChangedReq(const OD::JSON::Object &)
ServiceMgrBase::sKeyOK
static const char * sKeyOK()
Definition: servicemgrbase.h:163
ServiceMgrBase::getAuthority
Network::Authority getAuthority(bool islocal) const
ptrman.h
ServiceMgrBase::sKeyAction
static const char * sKeyAction()
Definition: servicemgrbase.h:161
sKey::Object
FixedString Object()
Definition: keystrs.h:112
ServiceMgrBase::debugMsg
static void debugMsg(const char *)
ServiceMgrBase::doAppClosing
virtual void doAppClosing(CallBacker *)
mStruct
#define mStruct(module)
Definition: commondefs.h:182
ServiceMgrBase::surveyChangedCB
void surveyChangedCB(CallBacker *)
ServiceMgrBase::sKeyCloseEv
static const char * sKeyCloseEv()
Definition: servicemgrbase.h:40
ServiceMgrBase::sKeyEvent
static const char * sKeyEvent()
Definition: servicemgrbase.h:44
ServiceMgrBase::doHandleActionRequest
void doHandleActionRequest(CallBacker *)
Network::SpecAddr
SpecAddr
Definition: networkcommon.h:33
ServiceMgrBase::newConnectionCB
void newConnectionCB(CallBacker *)
ServiceMgrBase::applyInOtherThread
uiRetVal applyInOtherThread(const packetData &)
ServiceMgrBase::sendRequest
static uiRetVal sendRequest(const Network::Authority &, const char *servicenm, const char *reqkey, const OD::JSON::Object &)
ServiceMgrBase::addApplicationAuthority
static bool addApplicationAuthority(bool local, OS::MachineCommand &)
ServiceMgrBase
Base class for OpendTect Service Manager and external services/apps.
Definition: servicemgrbase.h:29
Network::Any
@ Any
Definition: networkcommon.h:33
ServiceMgrBase::addLocalServer
bool addLocalServer()
ServiceMgrBase::isOK
mODTextTranslationClass(ServiceMgrBase) public bool isOK(bool islocal) const
ServiceMgrBase::sKeyODServer
static const char * sKeyODServer()
Definition: servicemgrbase.h:48
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
ServiceMgrBase::stopServer
virtual void stopServer(bool islocal)
ServiceMgrBase::isMainService
bool isMainService() const
ServiceMgrBase::sendAction
static uiRetVal sendAction(const Network::Authority &, const char *servicenm, const char *action)
ServiceMgrBase::survChangedReq
uiRetVal survChangedReq(const OD::JSON::Object &)
ServiceMgrBase::serverIsMine
bool & serverIsMine(bool islocal)
ServiceMgrBase::theNewMain
static ServiceMgrBase * theNewMain(ServiceMgrBase *)
Network::RequestServer
Definition: netreqconnection.h:137
ServiceMgrBase::canParseAction
virtual bool canParseAction(const char *, uiRetVal &)
ServiceMgrBase::useServer
bool useServer(Network::RequestServer *, bool islocal)
ServiceMgrBase::sKeyDeregister
static const char * sKeyDeregister()
Definition: servicemgrbase.h:46
OS::MachineCommand
Encapsulates an actual command to execute + the machine to run it on.
Definition: oscommand.h:94
ServiceMgrBase::doSurveyChanged
virtual void doSurveyChanged(CallBacker *)
Definition: servicemgrbase.h:87
ServiceMgrBase::sKeyRegister
static const char * sKeyRegister()
Definition: servicemgrbase.h:45
ServiceMgrBase::canDoRequest
bool canDoRequest(const OD::JSON::Object &, packetData &)
ServiceMgrBase::ServiceMgrBase
ServiceMgrBase(ServiceMgrBase &&)=delete
ServiceMgrBase::packet_
RefMan< Network::RequestPacket > packet_
Definition: servicemgrbase.h:158
ServiceMgrBase::canDoAction
bool canDoAction(const OD::JSON::Object &, packetData &)
ServiceMgrBase::sendErr
void sendErr(uiRetVal &)
ServiceMgrBase::doHandleAction
virtual uiRetVal doHandleAction(const char *action)
ServiceMgrBase::doPyEnvChange
virtual void doPyEnvChange(CallBacker *)
Definition: servicemgrbase.h:86
ServiceMgrBase::connClosedCB
void connClosedCB(CallBacker *)
ServiceMgrBase::sKeySurveyChangeEv
static const char * sKeySurveyChangeEv()
Definition: servicemgrbase.h:41
ServiceMgrBase::doHandleRequest
virtual uiRetVal doHandleRequest(const OD::JSON::Object &)
ServiceMgrBase::operator=
ServiceMgrBase & operator=(ServiceMgrBase &&)=delete
netservice.h
CNotifier< ServiceMgrBase, BufferString >
ServiceMgrBase::startHandleRequest
CNotifier< ServiceMgrBase, const OD::JSON::Object * > startHandleRequest
Definition: servicemgrbase.h:76
OD::JSON::Object
ValueSet where the values and subsets have a key.
Definition: odjson.h:283
RefMan< Network::RequestPacket >

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021