DABC (Data Acquisition Backbone Core)  2.9.9
Factory.cxx
Go to the documentation of this file.
1 // $Id: Factory.cxx 4476 2020-04-15 14:12:38Z 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 "dabc/Factory.h"
17 
18 #include <dlfcn.h>
19 
20 #include "dabc/Manager.h"
21 #include "dabc/DataTransport.h"
22 
23 
24 // std::vector<dabc::Factory::LibEntry> dabc::Factory::fLibs;
25 
26 bool dabc::Factory::LoadLibrary(const std::string &fname)
27 {
28  void* lib = dlopen(fname.c_str(), RTLD_NOW | RTLD_GLOBAL);
29 
30  if (lib==0) {
31  EOUT("Cannot load library %s err:%s", fname.c_str(), dlerror());
32  return false;
33  }
34 
35  DOUT1("Library loaded %s", fname.c_str());
36 
37  return true;
38 }
39 
40 bool dabc::Factory::CreateManager(const std::string &name, Configuration* cfg)
41 {
42  if (dabc::mgr.null())
43  new dabc::Manager(name.c_str(), cfg);
44 
45  return true;
46 }
47 
48 
49 void* dabc::Factory::FindSymbol(const std::string &symbol)
50 {
51  return symbol.empty() ? 0 : dlsym(RTLD_DEFAULT, symbol.c_str());
52 }
53 
54 dabc::Factory::Factory(const std::string &name) :
55  Object(0, name)
56 {
57  DOUT2("Factory %s is created", GetName());
58 }
59 
60 
61 dabc::Module* dabc::Factory::CreateTransport(const Reference& port, const std::string &typ, dabc::Command cmd)
62 {
63  dabc::PortRef portref = port;
64 
65  if (portref.IsInput()) {
66  dabc::DataInput* inp = CreateDataInput(typ);
67  if (inp==0) return 0;
68  if (!inp->Read_Init(portref, cmd)) {
69  EOUT("Input object %s cannot be initialized", typ.c_str());
70  delete inp;
71  return 0;
72  }
73 
74  dabc::InputTransport* tr = new dabc::InputTransport(cmd, portref, inp, true);
75 
76  dabc::Url url(typ);
77  if (url.HasOption("reconnect")) tr->EnableReconnect(typ);
78 
79  return tr;
80  }
81 
82  if (portref.IsOutput()) {
84  if (out==0) return 0;
85  if (!out->Write_Init()) {
86  EOUT("Output object %s cannot be initialized", typ.c_str());
87  delete out;
88  return 0;
89  }
90  DOUT3("Creating output transport for port %p", portref());
91  return new dabc::OutputTransport(cmd, portref, out, true);
92  }
93 
94  return 0;
95 }
96 
97 
98 // ================================================
99 
100 
102 {
103  // for the moment do nothing, later list will be managed here
104 
106 }
Represents command with its arguments.
Definition: Command.h:99
Interface for implementing any kind of data input.
Definition: DataIO.h:61
virtual bool Read_Init(const WorkerRef &wrk, const Command &cmd)
Initialize data input, using port and command.
Definition: DataIO.h:82
Interface for implementing any kind of data output.
Definition: DataIO.h:158
virtual bool Write_Init()
This is generic virtual method to initialize output before real work is started.
Definition: DataIO.h:186
FactoryPlugin(dabc::Factory *f)
Definition: Factory.cxx:101
static void * FindSymbol(const std::string &symbol)
Definition: Factory.cxx:49
virtual Module * CreateTransport(const Reference &port, const std::string &typ, Command cmd)
Factory method to create transport.
Definition: Factory.cxx:61
virtual DataOutput * CreateDataOutput(const std::string &typ)
Factory method to create data output.
Definition: Factory.h:76
static bool LoadLibrary(const std::string &fname)
Definition: Factory.cxx:26
virtual DataInput * CreateDataInput(const std::string &typ)
Factory method to create data input.
Definition: Factory.h:73
Factory(const std::string &name)
Definition: Factory.cxx:54
static bool CreateManager(const std::string &name="mgr", Configuration *cfg=nullptr)
Definition: Factory.cxx:40
void EnableReconnect(const std::string &reconn)
Set URL, use to reconnect data input.
Manager of everything in DABC
Definition: Manager.h:291
static void ProcessFactory(Factory *factory)
Definition: Manager.cxx:1561
Base for dabc::ModuleSync and dabc::ModuleAsync classes.
Definition: Module.h:42
Base class for output transport implementations.
Reference on the dabc::Port class
Definition: Port.h:195
bool IsOutput() const
Returns true if it is output port.
Definition: Port.h:202
bool IsInput() const
Returns true if it is input port.
Definition: Port.h:199
Uniform Resource Locator interpreter.
Definition: Url.h:33
#define DOUT2(args ...)
Definition: logging.h:170
#define DOUT3(args ...)
Definition: logging.h:176
#define EOUT(args ...)
Definition: logging.h:150
#define DOUT1(args ...)
Definition: logging.h:162
ManagerRef mgr
Definition: Manager.cxx:42