DABC (Data Acquisition Backbone Core)  2.9.9
Factory.cxx
Go to the documentation of this file.
1 // $Id: Factory.cxx 4481 2020-04-15 14:46:54Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #include "http/Factory.h"
17 
18 #include "dabc/Manager.h"
19 #include "dabc/Configuration.h"
20 #include "http/Civetweb.h"
21 #include "http/FastCgi.h"
22 
24 
25 
27 {
28  if (dabc::mgr.null()) return;
29 
30  // if dabc started without config file, do not automatically start http server
31  if ((dabc::mgr()->cfg()==0) || (dabc::mgr()->cfg()->GetVersion()<=0)) return;
32 
33  dabc::XMLNodePointer_t node = 0;
34 
35  while (dabc::mgr()->cfg()->NextCreationNode(node, "HttpServer", true)) {
36 
37  const char* name = dabc::Xml::GetAttr(node, dabc::xmlNameAttr);
38  const char* thrdname = dabc::Xml::GetAttr(node, dabc::xmlThreadAttr);
39 
40 // DOUT0("Found HttpServer node name = %s!!!", name ? name : "---");
41 
42  std::string objname;
43  if (name!=0) objname = name;
44  if (objname.length()==0) objname = "/http";
45  if (objname[0]!='/') objname = std::string("/") + objname;
46  if ((thrdname==0) || (*thrdname==0)) thrdname = "HttpThread";
47 
48  dabc::WorkerRef serv = new http::Civetweb(objname);
49  serv.MakeThreadForWorker(thrdname);
51  }
52 
53 #ifndef DABC_WITHOUT_FASTCGI
54 
55  while (dabc::mgr()->cfg()->NextCreationNode(node, "FastCgiServer", true)) {
56 
57  const char* name = dabc::Xml::GetAttr(node, dabc::xmlNameAttr);
58  const char* thrdname = dabc::Xml::GetAttr(node, dabc::xmlThreadAttr);
59 
60 // DOUT0("Found FastCgiServer node name = %s!!!", name ? name : "---");
61 
62  std::string objname;
63  if (name!=0) objname = name;
64  if (objname.length()==0) objname = "/fastcgi";
65  if (objname[0]!='/') objname = std::string("/") + objname;
66  if ((thrdname==0) || (*thrdname==0)) thrdname = "HttpThread";
67 
68  dabc::WorkerRef serv = new http::FastCgi(objname);
69  serv.MakeThreadForWorker(thrdname);
71  }
72 
73 #endif
74 
75 }
76 
77 dabc::Reference http::Factory::CreateObject(const std::string &classname, const std::string &objname, dabc::Command cmd)
78 {
79  if (classname == "http::Server")
80  return new http::Server(objname, cmd);
81 
82  if (classname == "http::Civetweb")
83  return new http::Civetweb(objname, cmd);
84 
85  if (classname == "http::FastCgi")
86  return new http::FastCgi(objname, cmd);
87 
88  return dabc::Factory::CreateObject(classname, objname, cmd);
89 }
Represents command with its arguments.
Definition: Command.h:99
Small helper class to correctly instantiate user-specific factories.
Definition: Factory.h:106
virtual Reference CreateObject(const std::string &classname, const std::string &objname, Command cmd)
Factory method to create object.
Definition: Factory.h:58
bool CreatePublisher()
Create publisher, which manage all published hierarchies.
Definition: Manager.cxx:2315
Reference on the arbitrary object
Definition: Reference.h:73
Reference on dabc::Worker
Definition: Worker.h:466
bool MakeThreadForWorker(const std::string &thrdname="")
Definition: Worker.h:498
Server provides http access to DABC
Definition: Civetweb.h:31
Factory for HTTP-related classes in DABC
Definition: Factory.h:29
virtual dabc::Reference CreateObject(const std::string &classname, const std::string &objname, dabc::Command cmd)
Factory method to create object.
Definition: Factory.cxx:77
virtual void Initialize()
Method called by the manager during application start.
Definition: Factory.cxx:26
Server provides fastcgi access to DABC
Definition: FastCgi.h:33
Server provides http access to DABC
Definition: Server.h:31
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
Definition: XmlEngine.cxx:411
void * XMLNodePointer_t
Definition: XmlEngine.h:25
ManagerRef mgr
Definition: Manager.cxx:42
const char * xmlThreadAttr
Definition: ConfigBase.cxx:38
const char * xmlNameAttr
Definition: ConfigBase.cxx:33
dabc::FactoryPlugin httpfactory(new http::Factory("http"))