crabmeat 1.0
Loading...
Searching...
No Matches
cbm_servreg.h
1
16
17#ifndef CRABMEAT_SERVICEREGISTRY_H_
18#define CRABMEAT_SERVICEREGISTRY_H_
19
20#include "crabmeat-common.h"
21#include "json/cbm_json.h"
22#include "string/cbm_string.h"
23
24#include <list>
25
26namespace cbm {
27
28enum sreg_e
29{
30 SREG_NONE, SREG_MIN
31};
32
33typedef std::string service_name_t;
34
35struct entity_t
36{
37 std::string name;
38 std::string id;
39};
40
41template < typename _T >
42struct _cbm_vector
43{
44 std::list< _T > v;
45 typedef typename std::list< _T >::iterator iterator;
46 typedef typename std::list< _T >::const_iterator const_iterator;
47
48 size_t size() const
49 { return this->v.size(); }
50 bool empty() const
51 { return this->v.empty(); }
52 void clear()
53 { this->v.clear(); }
54 void push_back( _T const & _elem)
55 {
56 for ( iterator elem = this->begin();
57 elem != this->end(); ++elem)
58 {
59 if ( elem->id == _elem.id)
60 { return; }
61 }
62 this->v.push_back( _elem);
63 }
64
65 _T & front()
66 { return this->v.front(); }
67 void pop_front()
68 { this->v.pop_front(); }
69
70 iterator begin()
71 { return this->v.begin(); }
72 iterator end()
73 { return this->v.end(); }
74 const_iterator begin() const
75 { return this->v.begin(); }
76 const_iterator end() const
77 { return this->v.end(); }
78
79};
80
81struct entities_t : public _cbm_vector< cbm::entity_t >
82 { };
83
84typedef rapidjson::Value service_properties_t;
85struct service_t
86{
87 service_t()
88 : m( NULL) { }
89
90 std::string name;
91 std::string id;
92
93 cbm::service_properties_t const * m;
94};
95
96struct services_t : public _cbm_vector< cbm::service_t >
97 { };
98
99struct service_registry_t
100{
101 service_registry_t();
102 ~service_registry_t();
103
104 lerr_t connect( char const *
105 /*registry URL (e.g., JSON file) */);
106 lerr_t disconnect();
107
108 cbm::string_t serialize();
109
110 cbm::services_t query_providers( std::string const & /*entity name*/,
111 lflags_t = SREG_NONE, int * = NULL /*rc*/) const;
112
113 service_properties_t const * query_service_properties(
114 std::string /*service*/, int * /*rc*/) const;
115
116
117 private:
118 std::string m_regurl;
119 rapidjson::Document m_reg;
120 int m_isconnected;
121};
122
123struct service_discover_t
124{
125 service_discover_t( cbm::service_registry_t const * = NULL);
126
127 cbm::service_t discover( std::string const & /*entity*/,
128 cbm::services_t const & /*explicitly requested*/,
129 int * = NULL /*rc*/) const;
130 cbm::service_properties_t const * service_properties(
131 cbm::service_t const &) const;
132
133 private:
134 cbm::service_registry_t const * m_reg;
135};
136
137struct workflow_compositer_t
138{
139 workflow_compositer_t( service_registry_t const *);
140
141 cbm::services_t resolve(
142 cbm::entities_t const & /*target variables*/,
143 cbm::services_t const & /*requested services*/, int * /*rc*/);
144
145 private:
146 cbm::service_discover_t m_servd;
147};
148
149} /* namespace cbm */
150
151#endif /* ! CRABMEAT_SERVICEREGISTRY_H_ */
152
The "Service Registry" holds information about available services (e.g., models, readers,...
Definition Lresources.h:51