crabmeat 1.0
Loading...
Searching...
No Matches
io-kcomm.h
1
9
10#ifndef CBM_IO_KCOMM_H_
11#define CBM_IO_KCOMM_H_
12
13#include "crabmeat-common.h"
14
15#include "io/sink-handle.h"
16
17#include "kernel/kmount.h"
18#include "kernel/ksched.h"
19#include "kernel/kscratch.h"
20#include "kernel/kcomm.h"
21
22#include "cpl/cbm_cpl.h"
23
24#define CBM_Error(obj) !CBM_HandleOk(obj)
25
26namespace ldndc {
27 class input_class_client_base_t;
28 class input_class_srv_base_t;
29}
30
31namespace cbm {
32 class resources_statistics_t;
33
34 class kernel_t;
35 class io_dcomm_t;
36}
37namespace cbm {
38class CBM_API io_kcomm_t : public client_object_t
39{
40 LDNDC_CLIENT_OBJECT(io_kcomm_t)
41 public:
42 io_kcomm_t();
43 io_kcomm_t( lid_t const &);
44 ~io_kcomm_t();
45
46 kcomm_t peer_communicator(
47 char const * /*name*/, lid_t const & /*object id*/);
48 kmount_t spatial_controller(
49 kernel_t * /*request source*/);
50 ksched_t temporal_controller(
51 kernel_t * /*request source*/);
52
53 public:
54 template < typename _T >
55 CBM_Handle publish_port( char const * _name, char const * _unit,
56 _T * _data, size_t _data_sz, int _flags = 0)
57 { return this->publish_port(
58 _name, _unit, this->object_id(), _data, _data_sz, _flags); }
59 template < typename _T >
60 CBM_Handle publish_port( char const * _name, char const * _unit,
61 lid_t const & _part_id,
62 _T * _data, size_t _data_sz, int _flags = 0)
63 { return this->publish_port_priv( _name, _unit, _part_id,
64 _data, _data_sz, cbm_type< _T >::type, _flags); }
65 lerr_t unpublish_port( CBM_Handle);
66
67 CBM_Handle subscribe_port( char const * _name, char const * _unit,
68 CBM_Transform * _transform = 0, int _flags = 0)
69 { return this->subscribe_port( _name, _unit,
70 this->object_id(), _transform, _flags); }
71 CBM_Handle subscribe_port( char const * _name, char const * _unit,
72 lid_t const & _part_id, CBM_Transform * _transform = 0, int _flags = 0)
73 { return this->subscribe_port_priv( _name, _unit,
74 _part_id, _transform, CBM_CallbackNone, _flags); }
75 lerr_t unsubscribe_port( CBM_Handle);
76
77 char const * port_uri( CBM_Handle) const;
78 char const * port_unit( CBM_Handle,
79 char * /*buffer*/, size_t /*buffer size*/) const;
80 /* test for data on availability (size, type, ..) */
81 int ping_port( CBM_Handle /*handle*/, CBM_FieldPingInfo * = NULL);
82
83 template < typename _T >
84 size_t send_port( CBM_Handle _handle,
85 _T const * _data, size_t _data_sz, int _flags = 0)
86 { return this->send_port_priv( _handle, _data,
87 _data_sz, cbm_type< _T >::type, _flags); }
88 template < typename _T >
89 size_t recv_port( CBM_Handle _handle,
90 _T * _data, size_t _data_sz, int _flags = 0)
91 { return this->recv_port_priv( _handle, _data,
92 _data_sz, cbm_type< _T >::type, _flags); }
93 template < typename _T >
94 size_t recv_dynport( CBM_Handle _handle, void ** _data, int _flags = 0)
95 { return this->recv_dynport_priv( _handle, _data,
96 cbm_type< _T >::type, _flags); }
97 void free_dyndata( void *);
98
99 private:
100 CBM_Handle publish_port_priv( char const * /*name*/,
101 char const * /*unit*/, lid_t const & /*part id*/,
102 void * /*data*/, size_t /*datasize*/, CBM_Datatype, int /*flags*/);
103 CBM_Handle subscribe_port_priv( char const * /*name*/,
104 char const * /*unit*/, lid_t const & /*part id*/,
105 CBM_Transform * = 0, CBM_Callback = CBM_CallbackNone, int = 0 /*flags*/);
106 size_t send_port_priv( CBM_Handle,
107 void const *, size_t, CBM_Datatype, int /*flags*/);
108 size_t recv_port_priv( CBM_Handle,
109 void *, size_t, CBM_Datatype, int /*flags*/);
110 size_t recv_dynport_priv( CBM_Handle,
111 void ** /*data*/, CBM_Datatype, int /*flags*/);
112
113 public:
114 CBM_Handle publish_event( char const * _name, int _flags = 0)
115 { return this->publish_port<char>( _name,
116 CBM_NoUnit, NULL, CBM_DynamicSize, _flags); }
117 lerr_t unpublish_event( CBM_Handle _handle)
118 { return this->unpublish_port( _handle); }
119 CBM_Handle subscribe_event( char const * _name,
120 CBM_Callback _callback, int _flags = 0)
121 { return this->subscribe_port_priv( _name, CBM_NoUnit,
122 this->object_id(), NULL, _callback, _flags); }
123 lerr_t unsubscribe_event( CBM_Handle _handle)
124 { return this->unsubscribe_port( _handle); }
125
126 size_t send_event( CBM_Handle _handle,
127 char const * _data, size_t _data_sz, int _flags = 0)
128 { return this->send_port_priv( _handle,
129 _data, _data_sz, CBM_CHAR, _flags); }
130
131 public:
132 void set_io_service(
133 io_dcomm_t * /*region communicator*/,
134 cbm::source_descriptor_t const * = NULL /*region element source descriptor*/);
135 void set_io_service(
136 io_kcomm_t * /*kernel communicator*/,
137 cbm::source_descriptor_t const * = NULL /*region element source descriptor*/);
138
139 /*** input stream interface ***/
140
141 template < typename _I >
142 _I const * get_input_class();
143 template < typename _I >
144 _I const & get_input_class_ref();
145
146 template < typename _I >
147 _I const * acquire_input(
148 cbm::source_descriptor_t const *);
149 ldndc::input_class_client_base_t const * acquire_input(
150 char const * /*type*/,
151 cbm::source_descriptor_t const *);
152 void release_input(
153 ldndc::input_class_client_base_t const *) const;
154
155 /* more low-level */
156 ldndc::input_class_srv_base_t * fetch_input(
157 char const * /*type*/, cbm::source_descriptor_t const *);
158 ldndc::input_class_srv_base_t const * fetch_input(
159 char const * /*type*/, cbm::source_descriptor_t const *) const;
160
161 /* helper */
162 lid_t resolve_source( char const * /*type*/,
163 cbm::source_descriptor_t * /*buffer*/) const;
164 template < typename _I >
165 lid_t get_source_descriptor(
166 cbm::source_descriptor_t * _kd) const
167 { return this->resolve_source( _I::iclassname(), _kd); }
168 template < typename _I >
169 lid_t get_input_class_source_info(
170 cbm::source_descriptor_t * _kd) const
171 { return this->get_source_descriptor< _I >( _kd); }
172
173 /*** output stream interface ***/
174 ldndc::sink_handle_t sink_handle_acquire(
175 char const * /*sink identifier*/, int = 0/*sink index*/);
176 lerr_t sink_handle_release(
177 ldndc::sink_handle_t *);
178
179 public:
180 void set_scratch( state_scratch_t *);
181 state_scratch_t * get_scratch();
182#ifdef CRABMEAT_DEBUG
183 cbm::source_descriptor_t const & cbmdebug__kdesc()
184 const { return this->m_kdesc; }
185#endif
186
187 private:
188 io_dcomm_t * m_iodcomm;
189 cbm::source_descriptor_t m_kdesc;
190
191 /*
192 * note that this scratch object is not
193 * copied during kernel migration.
194 */
195 state_scratch_t * m_scratch;
196
197 /* holds client input class objects (for previously requested types) */
198 std::vector < ldndc::input_class_client_base_t const * > m_ic;
199};
200} /* namespace cbm */
201
202
203template < typename _I >
204_I const *
205cbm::io_kcomm_t::get_input_class()
206 { return this->acquire_input< _I >( NULL); }
207
208#include <stdexcept>
209template < typename _I >
210_I const &
211cbm::io_kcomm_t::get_input_class_ref()
212{
213 _I const * ic = this->acquire_input< _I >( NULL);
214 if ( ic)
215 { return static_cast< _I const & >( *ic); }
216 throw std::runtime_error( "failed to get input class");
217}
218
219template < typename _I >
220_I const *
221cbm::io_kcomm_t::acquire_input(
222 cbm::source_descriptor_t const * _source_info)
223{
224 return static_cast< _I const * >(
225 this->acquire_input( _I::iclassname(), _source_info));
226}
227
228
229#endif /* !CBM_IO_KCOMM_H_ */
230
The "Service Registry" holds information about available services (e.g., models, readers,...
Definition Lresources.h:51
declare common types related to air chemistry input
Definition airchemistrytypes.cpp:9