1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local ConfigAdmin= {} |
11 |
|
12 |
|
13 |
local Properties = require "openrtm.Properties" |
14 |
local ConfigurationListener = require "openrtm.ConfigurationListener" |
15 |
local ConfigurationListeners = ConfigurationListener.ConfigurationListeners |
16 |
local StringUtil = require "openrtm.StringUtil" |
17 |
|
18 |
local ConfigurationParamListenerType = ConfigurationListener.ConfigurationParamListenerType |
19 |
local ConfigurationSetListenerType = ConfigurationListener.ConfigurationSetListenerType |
20 |
local ConfigurationSetNameListenerType = ConfigurationListener.ConfigurationSetNameListenerType |
21 |
|
22 |
|
23 |
local Config = {} |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
Config.new = function(name, var, def_val, trans) |
33 |
local obj = {} |
34 |
obj.name = name |
35 |
obj.default_value = def_val |
36 |
obj.string_value = "" |
37 |
obj.callback = nil |
38 |
obj._var = var |
39 |
if trans ~= nil then |
40 |
obj._trans = trans |
41 |
else |
42 |
obj._trans = StringUtil.stringTo |
43 |
end |
44 |
|
45 |
|
46 |
function obj:setCallback(cbf) |
47 |
self.callback = cbf |
48 |
end |
49 |
|
50 |
|
51 |
|
52 |
function obj:notifyUpdate(key, val) |
53 |
self.callback(key, val) |
54 |
end |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
function obj:update(val) |
60 |
if self.string_value == val then |
61 |
return true |
62 |
end |
63 |
|
64 |
self.string_value = val |
65 |
|
66 |
|
67 |
local ret, value = self._trans(self._var._value, val) |
68 |
if ret then |
69 |
self._var._value = value |
70 |
self:notifyUpdate(self.name, val) |
71 |
return true |
72 |
end |
73 |
local ret, value = self._trans(self._var._value, self.default_value) |
74 |
self._var._value = value |
75 |
self:notifyUpdate(self.name, val) |
76 |
return false |
77 |
end |
78 |
|
79 |
|
80 |
return obj |
81 |
end |
82 |
|
83 |
|
84 |
|
85 |
ConfigAdmin.new = function(configsets) |
86 |
local obj = {} |
87 |
obj._configsets = configsets |
88 |
obj._activeId = "default" |
89 |
obj._active = true |
90 |
obj._changed = false |
91 |
obj._params = {} |
92 |
obj._emptyconf = Properties.new() |
93 |
obj._newConfig = {} |
94 |
obj._listeners = ConfigurationListeners.new() |
95 |
obj._changedParam = {} |
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
function obj:bindParameter(param_name, var, def_val, trans) |
104 |
if trans == nil then |
105 |
trans = StringUtil.stringTo |
106 |
end |
107 |
|
108 |
if param_name == "" or def_val == "" then |
109 |
return false |
110 |
end |
111 |
|
112 |
|
113 |
if self:isExist(param_name) then |
114 |
return false |
115 |
end |
116 |
|
117 |
local ret, value = trans(var._value, def_val) |
118 |
|
119 |
|
120 |
|
121 |
var._value = value |
122 |
if not ret then |
123 |
return false |
124 |
end |
125 |
local conf_ = Config.new(param_name, var, def_val, trans) |
126 |
table.insert(self._params, conf_) |
127 |
|
128 |
conf_:setCallback(function(config_param, config_value)self:onUpdateParam(config_param, config_value) end) |
129 |
|
130 |
self:update(self:getActiveId(), param_name) |
131 |
|
132 |
return true |
133 |
end |
134 |
|
135 |
|
136 |
|
137 |
|
138 |
function obj:unbindParameter(param_name) |
139 |
local ret_param = nil |
140 |
local ret_index = -1 |
141 |
for find_idx, param in ipairs(self._params) do |
142 |
if param.name == param_name then |
143 |
ret_param = param |
144 |
ret_index = find_idx |
145 |
end |
146 |
end |
147 |
|
148 |
if ret_index == -1 then |
149 |
return false |
150 |
end |
151 |
|
152 |
table.remove(self._params, ret_index) |
153 |
|
154 |
|
155 |
local leaf = self._configsets:getLeaf() |
156 |
for i, v in ipairs(leaf) do |
157 |
if v:hasKey(param_name) then |
158 |
v:removeNode(param_name) |
159 |
end |
160 |
end |
161 |
|
162 |
return true |
163 |
end |
164 |
|
165 |
|
166 |
|
167 |
|
168 |
function obj:haveConfig(config_id) |
169 |
if self._configsets:hasKey(config_id) == nil then |
170 |
return false |
171 |
else |
172 |
return true |
173 |
end |
174 |
end |
175 |
|
176 |
|
177 |
|
178 |
|
179 |
function obj:activateConfigurationSet(config_id) |
180 |
if config_id == "" then |
181 |
return false |
182 |
end |
183 |
if string.sub(config_id,1,1) == '_' then |
184 |
return false |
185 |
end |
186 |
if not self._configsets:hasKey(config_id) then |
187 |
return false |
188 |
end |
189 |
self._activeId = config_id |
190 |
self._active = true |
191 |
self._changed = true |
192 |
self:onActivateSet(config_id) |
193 |
return true |
194 |
end |
195 |
|
196 |
|
197 |
function obj:onActivateSet(config_id) |
198 |
self._listeners.configsetname_[ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET]:notify(config_id) |
199 |
end |
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
function obj:update(config_set, config_param) |
207 |
|
208 |
if config_set ~= nil and config_param == nil then |
209 |
if self._configsets:hasKey(config_set) == false then |
210 |
return |
211 |
end |
212 |
self._changedParam = {} |
213 |
local prop = self._configsets:getNode(config_set) |
214 |
for i, param in ipairs(self._params) do |
215 |
if prop:hasKey(param.name) then |
216 |
|
217 |
|
218 |
param:update(prop:getProperty(param.name)) |
219 |
end |
220 |
end |
221 |
self:onUpdate(config_set) |
222 |
end |
223 |
|
224 |
|
225 |
if config_set ~= nil and config_param ~= nil then |
226 |
self._changedParam = {} |
227 |
local key = config_set |
228 |
key = key.."."..config_param |
229 |
for i, conf in ipairs(self._params) do |
230 |
|
231 |
if conf.name == config_param then |
232 |
|
233 |
conf:update(self._configsets:getProperty(key)) |
234 |
end |
235 |
end |
236 |
end |
237 |
|
238 |
if config_set == nil and config_param == nil then |
239 |
self._changedParam = {} |
240 |
if self._changed and self._active then |
241 |
self:update(self._activeId) |
242 |
self._changed = false |
243 |
end |
244 |
end |
245 |
|
246 |
end |
247 |
|
248 |
|
249 |
|
250 |
|
251 |
function obj:isExist(param_name) |
252 |
if #self._params == 0 then |
253 |
return false |
254 |
end |
255 |
|
256 |
for i, conf in ipairs(self._params) do |
257 |
if conf.name == param_name then |
258 |
return true |
259 |
end |
260 |
end |
261 |
|
262 |
return false |
263 |
end |
264 |
|
265 |
|
266 |
|
267 |
function obj:isChanged() |
268 |
return self._changed |
269 |
end |
270 |
|
271 |
|
272 |
|
273 |
|
274 |
function obj:changedParameters() |
275 |
return self._changedParam |
276 |
end |
277 |
|
278 |
|
279 |
|
280 |
function obj:getActiveId() |
281 |
return self._activeId |
282 |
end |
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
function obj:isActive() |
290 |
return self._active |
291 |
end |
292 |
|
293 |
|
294 |
|
295 |
function obj:getConfigurationSets() |
296 |
return self._configsets:getLeaf() |
297 |
end |
298 |
|
299 |
|
300 |
|
301 |
|
302 |
function obj:getConfigurationSet(config_id) |
303 |
|
304 |
local prop = self._configsets:findNode(config_id) |
305 |
if prop == nil then |
306 |
return self._emptyconf |
307 |
end |
308 |
return prop |
309 |
end |
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
function obj:setConfigurationSetValues(config_set) |
316 |
local node_ = config_set:getName() |
317 |
if node_ == "" or node_ == nil then |
318 |
return false |
319 |
end |
320 |
|
321 |
if not self._configsets:hasKey(node_) then |
322 |
return false |
323 |
end |
324 |
|
325 |
local p = self._configsets:getNode(node_) |
326 |
|
327 |
|
328 |
p:mergeProperties(config_set) |
329 |
self._changed = true |
330 |
self._active = false |
331 |
self:onSetConfigurationSet(config_set) |
332 |
return true |
333 |
end |
334 |
|
335 |
|
336 |
|
337 |
function obj:getActiveConfigurationSet() |
338 |
local p = self._configsets:getNode(self._activeId) |
339 |
|
340 |
|
341 |
return p |
342 |
end |
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
function obj:addConfigurationSet(configset) |
349 |
if self._configsets:hasKey(configset:getName()) then |
350 |
return false |
351 |
end |
352 |
local node = configset:getName() |
353 |
|
354 |
|
355 |
self._configsets:createNode(node) |
356 |
|
357 |
local p = self._configsets:getNode(node) |
358 |
|
359 |
|
360 |
p:mergeProperties(configset) |
361 |
table.insert(self._newConfig, node) |
362 |
|
363 |
self._changed = true |
364 |
self._active = false |
365 |
self:onAddConfigurationSet(configset) |
366 |
return true |
367 |
end |
368 |
|
369 |
|
370 |
|
371 |
|
372 |
function obj:removeConfigurationSet(config_id) |
373 |
if config_id == "default" then |
374 |
return false |
375 |
end |
376 |
if self._activeId == config_id then |
377 |
return false |
378 |
end |
379 |
|
380 |
local find_flg = false |
381 |
|
382 |
local ret_idx = -1 |
383 |
for idx, conf in ipairs(self._newConfig) do |
384 |
if conf == config_id then |
385 |
ret_idx = idx |
386 |
break |
387 |
end |
388 |
end |
389 |
|
390 |
|
391 |
if ret_idx == -1 then |
392 |
return false |
393 |
end |
394 |
|
395 |
local p = self._configsets:getNode(config_id) |
396 |
if p ~= nil then |
397 |
p:getRoot():removeNode(config_id) |
398 |
end |
399 |
|
400 |
table.remove(self._newConfig, ret_idx) |
401 |
|
402 |
|
403 |
|
404 |
self._changed = true |
405 |
self._active = false |
406 |
self:onRemoveConfigurationSet(config_id) |
407 |
return true |
408 |
end |
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
function obj:setOnUpdate(cb) |
415 |
print("setOnUpdate function is obsolete.") |
416 |
print("Use addConfigurationSetNameListener instead.") |
417 |
self._listeners.configsetname_[ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET]:addListener(cb, false) |
418 |
end |
419 |
|
420 |
|
421 |
|
422 |
function obj:setOnUpdateParam(cb) |
423 |
print("setOnUpdateParam function is obsolete.") |
424 |
print("Use addConfigurationParamListener instead.") |
425 |
self._listeners.configparam_[ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM]:addListener(cb, false) |
426 |
end |
427 |
|
428 |
|
429 |
|
430 |
function obj:setOnSetConfigurationSet(cb) |
431 |
print("setOnSetConfigurationSet function is obsolete.") |
432 |
print("Use addConfigurationSetListener instead.") |
433 |
self._listeners.configset_[ConfigurationSetListenerType.ON_SET_CONFIG_SET]:addListener(cb, false) |
434 |
end |
435 |
|
436 |
|
437 |
|
438 |
function obj:setOnAddConfigurationSet(cb) |
439 |
print("setOnAddConfigurationSet function is obsolete.") |
440 |
print("Use addConfigurationSetListener instead.") |
441 |
self._listeners.configset_[ConfigurationSetListenerType.ON_ADD_CONFIG_SET]:addListener(cb, false) |
442 |
end |
443 |
|
444 |
|
445 |
|
446 |
function obj:setOnRemoveConfigurationSet(cb) |
447 |
print("setOnRemoveConfigurationSet function is obsolete.") |
448 |
print("Use addConfigurationSetNameListener instead.") |
449 |
self._listeners.configsetname_[ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET]:addListener(cb, False) |
450 |
end |
451 |
|
452 |
|
453 |
|
454 |
function obj:setOnActivateSet(cb) |
455 |
print("setOnActivateSet function is obsolete.") |
456 |
print("Use addConfigurationSetNameListener instead.") |
457 |
self._listeners.configsetname_[ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET]:addListener(cb, false) |
458 |
end |
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
function obj:addConfigurationParamListener(_type, listener, autoclean) |
465 |
if autoclean == nil then |
466 |
autoclean = true |
467 |
end |
468 |
self._listeners.configparam_[_type]:addListener(listener, autoclean) |
469 |
end |
470 |
|
471 |
|
472 |
|
473 |
|
474 |
function obj:removeConfigurationParamListener(_type, listener) |
475 |
self._listeners.configparam_[_type]:removeListener(listener) |
476 |
end |
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
function obj:addConfigurationSetListener(_type, listener, autoclean) |
483 |
if autoclean == nil then |
484 |
autoclean = true |
485 |
end |
486 |
self._listeners.configset_[_type]:addListener(listener, autoclean) |
487 |
end |
488 |
|
489 |
|
490 |
|
491 |
|
492 |
function obj:removeConfigurationSetListener(_type, listener) |
493 |
self._listeners.configset_[_type]:removeListener(listener) |
494 |
end |
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
function obj:addConfigurationSetNameListener(_type, listener, autoclean) |
501 |
if autoclean == nil then |
502 |
autoclean = true |
503 |
end |
504 |
self._listeners.configsetname_[_type]:addListener(listener, autoclean) |
505 |
end |
506 |
|
507 |
|
508 |
|
509 |
|
510 |
function obj:removeConfigurationSetNameListener(_type, listener) |
511 |
self._listeners.configsetname_[_type]:removeListener(listener) |
512 |
end |
513 |
|
514 |
|
515 |
|
516 |
function obj:onUpdate(config_set) |
517 |
self._listeners.configsetname_[ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET]:notify(config_set) |
518 |
end |
519 |
|
520 |
|
521 |
|
522 |
|
523 |
function obj:onUpdateParam(config_param, config_value) |
524 |
table.insert(self._changedParam, config_param) |
525 |
self._listeners.configparam_[ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM]:notify(config_param, config_value) |
526 |
end |
527 |
|
528 |
|
529 |
|
530 |
function obj:onSetConfigurationSet(config_set) |
531 |
self._listeners.configset_[ConfigurationSetListenerType.ON_SET_CONFIG_SET]:notify(config_set) |
532 |
end |
533 |
|
534 |
|
535 |
|
536 |
function obj:onAddConfigurationSet(config_set) |
537 |
self._listeners.configset_[ConfigurationSetListenerType.ON_ADD_CONFIG_SET]:notify(config_set) |
538 |
end |
539 |
|
540 |
|
541 |
function obj:onRemoveConfigurationSet(config_id) |
542 |
self._listeners.configsetname_[ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET]:notify(config_id) |
543 |
end |
544 |
|
545 |
|
546 |
|
547 |
function obj:onActivateSet(config_id) |
548 |
self._listeners.configsetname_[ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET]:notify(config_id) |
549 |
end |
550 |
|
551 |
|
552 |
|
553 |
return obj |
554 |
end |
555 |
|
556 |
|
557 |
return ConfigAdmin |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local CorbaPort= {} |
11 |
|
12 |
|
13 |
local oil = require "oil" |
14 |
local PortBase = require "openrtm.PortBase" |
15 |
local Properties = require "openrtm.Properties" |
16 |
local StringUtil = require "openrtm.StringUtil" |
17 |
local NVUtil = require "openrtm.NVUtil" |
18 |
local CORBA_SeqUtil = require "openrtm.CORBA_SeqUtil" |
19 |
|
20 |
|
21 |
local CorbaProviderHolder = {} |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
CorbaProviderHolder.new = function(type_name, instance_name, servant) |
29 |
local obj = {} |
30 |
|
31 |
|
32 |
|
33 |
function obj:instanceName() |
34 |
return self._instanceName |
35 |
end |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
function obj:itypeName() |
41 |
return self._typeName |
42 |
end |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
function obj:ior() |
48 |
return self._ior |
49 |
end |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
function obj:descriptor() |
55 |
return self._typeName.."."..self._instanceName |
56 |
end |
57 |
|
58 |
|
59 |
|
60 |
function obj:activate() |
61 |
end |
62 |
|
63 |
|
64 |
|
65 |
function obj:deactivate() |
66 |
end |
67 |
|
68 |
|
69 |
obj._typeName = type_name |
70 |
obj._instanceName = instance_name |
71 |
obj._servant = servant |
72 |
local Manager = require "openrtm.Manager" |
73 |
local _mgr = Manager:instance() |
74 |
|
75 |
|
76 |
obj._ior = _mgr:getORB():tostring(obj._servant) |
77 |
|
78 |
return obj |
79 |
end |
80 |
|
81 |
|
82 |
local CorbaConsumerHolder = {} |
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
CorbaConsumerHolder.new = function(type_name, instance_name, consumer, owner) |
91 |
local obj = {} |
92 |
|
93 |
|
94 |
|
95 |
function obj:instanceName() |
96 |
return self._instanceName |
97 |
end |
98 |
|
99 |
|
100 |
function obj:typeName() |
101 |
return self._typeName |
102 |
end |
103 |
|
104 |
|
105 |
function obj:descriptor() |
106 |
return self._typeName.."."..self._instanceName |
107 |
end |
108 |
|
109 |
|
110 |
|
111 |
|
112 |
function obj:setObject(ior) |
113 |
self._ior = ior |
114 |
|
115 |
return self._consumer:setIOR(ior) |
116 |
|
117 |
end |
118 |
|
119 |
|
120 |
function obj:releaseObject() |
121 |
self._consumer:releaseObject() |
122 |
end |
123 |
|
124 |
|
125 |
|
126 |
function obj:getIor() |
127 |
return self._ior |
128 |
end |
129 |
|
130 |
|
131 |
obj._typeName = type_name |
132 |
obj._instanceName = instance_name |
133 |
obj._consumer = consumer |
134 |
obj._owner = owner |
135 |
obj._ior = "" |
136 |
|
137 |
return obj |
138 |
end |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
CorbaPort.new = function(name) |
145 |
local obj = {} |
146 |
setmetatable(obj, {__index=PortBase.new(name)}) |
147 |
local Manager = require "openrtm.Manager" |
148 |
obj._PortInterfacePolarity = Manager:instance():getORB().types:lookup("::RTC::PortInterfacePolarity").labelvalue |
149 |
obj._ReturnCode_t = Manager:instance():getORB().types:lookup("::RTC::ReturnCode_t").labelvalue |
150 |
|
151 |
|
152 |
|
153 |
function obj:init(prop) |
154 |
self._rtcout:RTC_TRACE("init()") |
155 |
self:createRef() |
156 |
|
157 |
self._properties:mergeProperties(prop) |
158 |
|
159 |
local num = tonumber(self._properties:getProperty("connection_limit","-1")) |
160 |
if num == nil then |
161 |
self._rtcout:RTC_ERROR("invalid connection_limit value: ".. |
162 |
self._properties:getProperty("connection_limit")) |
163 |
end |
164 |
|
165 |
self:setConnectionLimit(num) |
166 |
end |
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
function obj:registerProvider(instance_name, type_name, provider, idl_file, interface_type) |
176 |
self._rtcout:RTC_TRACE("registerProvider(instance="..instance_name..", type_name="..type_name..")") |
177 |
if interface_type ~= nil and idl_file ~= nil then |
178 |
local Manager = require "openrtm.Manager" |
179 |
Manager:instance():getORB():loadidlfile(idl_file) |
180 |
provider = Manager:instance():getORB():newservant(provider, nil, interface_type) |
181 |
end |
182 |
local success, exception = oil.pcall( |
183 |
function() |
184 |
table.insert(self._providers, CorbaProviderHolder.new(type_name, |
185 |
instance_name, |
186 |
provider)) |
187 |
end) |
188 |
if not success then |
189 |
self._rtcout:RTC_ERROR("appending provider interface failed") |
190 |
self._rtcout:RTC_ERROR(exception) |
191 |
return false |
192 |
end |
193 |
|
194 |
|
195 |
if not self:appendInterface(instance_name, type_name, self._PortInterfacePolarity.PROVIDED) then |
196 |
return false |
197 |
end |
198 |
|
199 |
return true |
200 |
end |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
function obj:registerConsumer(instance_name, type_name, consumer, idl_file) |
208 |
self._rtcout:RTC_TRACE("registerConsumer()") |
209 |
if idl_file ~= nil then |
210 |
local Manager = require "openrtm.Manager" |
211 |
Manager:instance():getORB():loadidlfile(idl_file) |
212 |
end |
213 |
if not self:appendInterface(instance_name, type_name, self._PortInterfacePolarity.REQUIRED) then |
214 |
return false |
215 |
end |
216 |
|
217 |
table.insert(self._consumers,CorbaConsumerHolder.new(type_name, |
218 |
instance_name, |
219 |
consumer, |
220 |
self)) |
221 |
return true |
222 |
end |
223 |
|
224 |
|
225 |
|
226 |
function obj:activateInterfaces() |
227 |
self._rtcout:RTC_TRACE("activateInterfaces()") |
228 |
for i, provider in ipairs(self._providers) do |
229 |
provider:activate() |
230 |
end |
231 |
end |
232 |
|
233 |
|
234 |
|
235 |
function obj:deactivateInterfaces() |
236 |
self._rtcout:RTC_TRACE("deactivateInterfaces()") |
237 |
for i, provider in ipairs(self._providers) do |
238 |
provider:deactivate() |
239 |
end |
240 |
end |
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
function obj:publishInterfaces(connector_profile) |
250 |
self._rtcout:RTC_TRACE("publishInterfaces()") |
251 |
|
252 |
local returnvalue = self:_publishInterfaces() |
253 |
|
254 |
if returnvalue ~= self._ReturnCode_t.RTC_OK then |
255 |
return returnvalue |
256 |
end |
257 |
|
258 |
local properties = {} |
259 |
|
260 |
for i, provider in ipairs(self._providers) do |
261 |
local newdesc = string.sub(self._profile.name, 1, #self._ownerInstanceName).. |
262 |
".port"..string.sub(self._profile.name, #self._ownerInstanceName+1) |
263 |
newdesc = newdesc..".provided."..provider:descriptor() |
264 |
|
265 |
table.insert(properties, NVUtil.newNV(newdesc, provider:ior())) |
266 |
|
267 |
|
268 |
local olddesc = "port."..provider:descriptor() |
269 |
table.insert(properties, NVUtil.newNV(olddesc, provider:ior())) |
270 |
|
271 |
end |
272 |
|
273 |
CORBA_SeqUtil.push_back_list(connector_profile.properties, properties) |
274 |
|
275 |
return self._ReturnCode_t.RTC_OK |
276 |
end |
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
function obj:subscribeInterfaces(connector_profile) |
288 |
self._rtcout:RTC_TRACE("subscribeInterfaces()") |
289 |
local nv = connector_profile.properties |
290 |
|
291 |
local strict = false |
292 |
local index = NVUtil.find_index(nv, "port.connection.strictness") |
293 |
if index >= 0 then |
294 |
local strictness = NVUtil.any_from_any(nv[index].value) |
295 |
if "best_effort" == strictness then |
296 |
strict = false |
297 |
elseif "strict" == strictness then |
298 |
strict = true |
299 |
end |
300 |
|
301 |
self._rtcout:RTC_DEBUG("Connetion strictness is: "..strictness) |
302 |
end |
303 |
|
304 |
for i, consumer in ipairs(self._consumers) do |
305 |
local ior = {} |
306 |
|
307 |
|
308 |
if self:findProvider(nv, consumer, ior) and #ior > 0 then |
309 |
|
310 |
self:setObject(ior[1], consumer) |
311 |
|
312 |
else |
313 |
ior = {} |
314 |
|
315 |
if self:findProviderOld(nv, consumer, ior) and #ior > 0 then |
316 |
|
317 |
self:setObject(ior[1], consumer) |
318 |
else |
319 |
|
320 |
if strict then |
321 |
self._rtcout:RTC_ERROR("subscribeInterfaces() failed.") |
322 |
return self._ReturnCode_t.RTC_ERROR |
323 |
end |
324 |
end |
325 |
end |
326 |
end |
327 |
|
328 |
self._rtcout:RTC_TRACE("subscribeInterfaces() successfully finished.") |
329 |
|
330 |
return self._ReturnCode_t.RTC_OK |
331 |
end |
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
function obj:unsubscribeInterfaces(connector_profile) |
339 |
self._rtcout:RTC_TRACE("unsubscribeInterfaces()") |
340 |
local nv = connector_profile.properties |
341 |
|
342 |
for i, consumer in ipairs(self._consumers) do |
343 |
local ior = {} |
344 |
if self:findProvider(nv, consumer, ior) and #ior > 0 then |
345 |
self._rtcout:RTC_DEBUG("Correspoinding consumer found.") |
346 |
self:releaseObject(ior[1], consumer) |
347 |
else |
348 |
ior = {} |
349 |
if self:findProviderOld(nv, consumer, ior) and #ior > 0 then |
350 |
self._rtcout:RTC_DEBUG("Correspoinding consumer found.") |
351 |
self:releaseObject(ior[1], consumer) |
352 |
end |
353 |
end |
354 |
end |
355 |
|
356 |
|
357 |
end |
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
function obj:findProvider(nv, cons, iorstr) |
367 |
|
368 |
local newdesc = string.sub(self._profile.name,1,#self._ownerInstanceName).. |
369 |
".port"..string.sub(self._profile.name,#self._ownerInstanceName+1) |
370 |
newdesc = newdesc..".required."..cons:descriptor() |
371 |
|
372 |
|
373 |
|
374 |
|
375 |
local cons_index = NVUtil.find_index(nv, newdesc) |
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
if cons_index < 0 then |
382 |
return false |
383 |
end |
384 |
|
385 |
local provider = NVUtil.any_from_any(nv[cons_index].value) |
386 |
|
387 |
if provider == "" then |
388 |
self._rtcout:RTC_WARN("Cannot extract Provider interface descriptor") |
389 |
return false |
390 |
end |
391 |
|
392 |
|
393 |
local prov_index = NVUtil.find_index(nv, provider) |
394 |
if prov_index < 0 then |
395 |
return false |
396 |
end |
397 |
|
398 |
local ior_ = NVUtil.any_from_any(nv[prov_index].value) |
399 |
if ior_ == "" then |
400 |
self._rtcout:RTC_WARN("Cannot extract Provider IOR string") |
401 |
return false |
402 |
end |
403 |
|
404 |
if type(iorstr) == "table" then |
405 |
table.insert(iorstr, ior_) |
406 |
end |
407 |
|
408 |
self._rtcout:RTC_ERROR("interface matched with new descriptor: "..newdesc) |
409 |
|
410 |
return true |
411 |
end |
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
function obj:findProviderOld(nv, cons, iorstr) |
421 |
local olddesc = "port."..cons:descriptor() |
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
local index = NVUtil.find_index(nv, olddesc) |
430 |
|
431 |
|
432 |
if index < 0 then |
433 |
return false |
434 |
end |
435 |
|
436 |
|
437 |
|
438 |
local ior_ = NVUtil.any_from_any(nv[index].value) |
439 |
|
440 |
|
441 |
if ior_ == "" then |
442 |
self._rtcout:RTC_WARN("Cannot extract Provider IOR string") |
443 |
return false |
444 |
end |
445 |
|
446 |
if type(iorstr) == "table" then |
447 |
table.insert(iorstr, ior_) |
448 |
end |
449 |
|
450 |
self._rtcout:RTC_ERROR("interface matched with old descriptor: "..olddesc) |
451 |
|
452 |
return true |
453 |
end |
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
function obj:setObject(ior, cons) |
460 |
if "null" == ior then |
461 |
return true |
462 |
end |
463 |
|
464 |
if "nil" == ior then |
465 |
return true |
466 |
end |
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
if not cons:setObject(ior) then |
475 |
self._rtcout:RTC_ERROR("Cannot narrow reference") |
476 |
return false |
477 |
end |
478 |
|
479 |
self._rtcout:RTC_TRACE("setObject() done") |
480 |
return true |
481 |
end |
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
function obj:releaseObject(ior, cons) |
488 |
if ior == cons:getIor() then |
489 |
cons:releaseObject() |
490 |
self._rtcout:RTC_DEBUG("Consumer "..cons:descriptor().." released.") |
491 |
return true |
492 |
end |
493 |
|
494 |
self._rtcout:RTC_WARN("IORs between Consumer and Connector are different.") |
495 |
return false |
496 |
end |
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
obj:addProperty("port.port_type", "CorbaPort") |
503 |
obj._properties = Properties.new() |
504 |
obj._providers = {} |
505 |
obj._consumers = {} |
506 |
|
507 |
return obj |
508 |
end |
509 |
|
510 |
|
511 |
return CorbaPort |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local CORBA_RTCUtil = {} |
11 |
|
12 |
|
13 |
local oil = require "oil" |
14 |
local RTObject = require "openrtm.RTObject" |
15 |
local NVUtil = require "openrtm.NVUtil" |
16 |
local Properties = require "openrtm.Properties" |
17 |
local StringUtil = require "openrtm.StringUtil" |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
CORBA_RTCUtil.get_component_profile = function(rtc) |
26 |
local prop = Properties.new() |
27 |
if rtc == oil.corba.idl.null then |
28 |
return prop |
29 |
end |
30 |
local prof = rtc:get_component_profile() |
31 |
NVUtil.copyToProperties(prop, prof.properties) |
32 |
return prop |
33 |
end |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
CORBA_RTCUtil.is_existing = function(rtc) |
40 |
local ret = true |
41 |
if NVUtil._non_existent(rtc) then |
42 |
ret = false |
43 |
end |
44 |
return ret |
45 |
end |
46 |
|
47 |
|
48 |
|
49 |
|
50 |
CORBA_RTCUtil.is_alive_in_default_ec = function(rtc) |
51 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc) |
52 |
if ec == oil.corba.idl.null then |
53 |
return false |
54 |
end |
55 |
return rtc:is_alive(ec) |
56 |
end |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
CORBA_RTCUtil.get_actual_ec = function(rtc, ec_id) |
67 |
local Manager = require "openrtm.Manager" |
68 |
local ReturnCode_t = Manager._ReturnCode_t |
69 |
if ec_id == nil then |
70 |
ec_id = 0 |
71 |
end |
72 |
if ec_id < 0 then |
73 |
return oil.corba.idl.null |
74 |
end |
75 |
|
76 |
|
77 |
if rtc == oil.corba.idl.null then |
78 |
return oil.corba.idl.null |
79 |
end |
80 |
|
81 |
if ec_id < RTObject.ECOTHER_OFFSET then |
82 |
local eclist = rtc:get_owned_contexts() |
83 |
if ec_id >= #eclist then |
84 |
return oil.corba.idl.null |
85 |
end |
86 |
|
87 |
if eclist[ec_id+1] == nil then |
88 |
return oil.corba.idl.null |
89 |
end |
90 |
return eclist[ec_id+1] |
91 |
elseif ec_id >= RTObject.ECOTHER_OFFSET then |
92 |
local pec_id = ec_id - RTObject.ECOTHER_OFFSET |
93 |
local eclist = rtc:get_participating_contexts() |
94 |
|
95 |
if pec_id >= #eclist then |
96 |
return oil.corba.idl.null |
97 |
end |
98 |
if eclist[pec_id+1] == nil then |
99 |
return oil.corba.idl.null |
100 |
end |
101 |
return eclist[pec_id+1] |
102 |
end |
103 |
end |
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
CORBA_RTCUtil.get_ec_id = function(rtc, ec) |
112 |
if rtc == oil.corba.idl.null then |
113 |
return -1 |
114 |
end |
115 |
if ec == oil.corba.idl.null then |
116 |
return -1 |
117 |
end |
118 |
|
119 |
local eclist_own = rtc:get_owned_contexts() |
120 |
|
121 |
local count = 0 |
122 |
for k,e in ipairs(eclist_own) do |
123 |
if e ~= oil.corba.idl.null then |
124 |
if NVUtil._is_equivalent(e, ec, e.getObjRef, ec.getObjRef) then |
125 |
return count |
126 |
end |
127 |
end |
128 |
count = count+1 |
129 |
end |
130 |
local eclist_pec = rtc:get_participating_contexts() |
131 |
count = 0 |
132 |
for k, e in pairs(eclist_pec) do |
133 |
if e ~= oil.corba.idl.null then |
134 |
if NVUtil._is_equivalent(e, ec, e.getObjRef, ec.getObjRef) then |
135 |
return count+RTObject.ECOTHER_OFFSET |
136 |
end |
137 |
end |
138 |
count = count+1 |
139 |
end |
140 |
return -1 |
141 |
end |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
CORBA_RTCUtil.activate = function(rtc, ec_id) |
151 |
local Manager = require "openrtm.Manager" |
152 |
local ReturnCode_t = Manager._ReturnCode_t |
153 |
if ec_id == nil then |
154 |
ec_id = 0 |
155 |
end |
156 |
if rtc == oil.corba.idl.null then |
157 |
return ReturnCode_t.BAD_PARAMETER |
158 |
end |
159 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc, ec_id) |
160 |
if ec == oil.corba.idl.null then |
161 |
return ReturnCode_t.BAD_PARAMETER |
162 |
end |
163 |
return NVUtil.getReturnCode(ec:activate_component(rtc)) |
164 |
end |
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
CORBA_RTCUtil.deactivate = function(rtc, ec_id) |
172 |
local Manager = require "openrtm.Manager" |
173 |
local ReturnCode_t = Manager._ReturnCode_t |
174 |
if ec_id == nil then |
175 |
ec_id = 0 |
176 |
end |
177 |
if rtc == oil.corba.idl.null then |
178 |
return ReturnCode_t.BAD_PARAMETER |
179 |
end |
180 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc, ec_id) |
181 |
if ec == oil.corba.idl.null then |
182 |
return ReturnCode_t.BAD_PARAMETER |
183 |
end |
184 |
return NVUtil.getReturnCode(ec:deactivate_component(rtc)) |
185 |
end |
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
CORBA_RTCUtil.reset = function(rtc, ec_id) |
194 |
local Manager = require "openrtm.Manager" |
195 |
local ReturnCode_t = Manager._ReturnCode_t |
196 |
if ec_id == nil then |
197 |
ec_id = 0 |
198 |
end |
199 |
if rtc == oil.corba.idl.null then |
200 |
return ReturnCode_t.BAD_PARAMETER |
201 |
end |
202 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc, ec_id) |
203 |
if ec == oil.corba.idl.null then |
204 |
return ReturnCode_t.BAD_PARAMETER |
205 |
end |
206 |
return NVUtil.getReturnCode(ec:reset_component(rtc)) |
207 |
end |
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
CORBA_RTCUtil.get_state = function(rtc, ec_id) |
217 |
local Manager = require "openrtm.Manager" |
218 |
local LifeCycleState = Manager:instance():getORB().types:lookup("::RTC::LifeCycleState").labelvalue |
219 |
if ec_id == nil then |
220 |
ec_id = 0 |
221 |
end |
222 |
if rtc == oil.corba.idl.null then |
223 |
return false, LifeCycleState.CREATED_STATE |
224 |
end |
225 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc, ec_id) |
226 |
|
227 |
if ec == oil.corba.idl.null then |
228 |
return false, LifeCycleState.CREATED_STATE |
229 |
end |
230 |
local state = ec:get_component_state(rtc) |
231 |
|
232 |
return true, NVUtil.getLifeCycleState(state) |
233 |
end |
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
CORBA_RTCUtil.is_in_inactive = function(rtc, ec_id) |
241 |
local Manager = require "openrtm.Manager" |
242 |
local LifeCycleState = Manager:instance():getORB().types:lookup("::RTC::LifeCycleState").labelvalue |
243 |
|
244 |
if ec_id == nil then |
245 |
ec_id = 0 |
246 |
end |
247 |
local ret, state = CORBA_RTCUtil.get_state(rtc, ec_id) |
248 |
if ret then |
249 |
if state == LifeCycleState.INACTIVE_STATE then |
250 |
return true |
251 |
end |
252 |
end |
253 |
|
254 |
return false |
255 |
end |
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
CORBA_RTCUtil.is_in_active = function(rtc, ec_id) |
262 |
local Manager = require "openrtm.Manager" |
263 |
local LifeCycleState = Manager:instance():getORB().types:lookup("::RTC::LifeCycleState").labelvalue |
264 |
|
265 |
if ec_id == nil then |
266 |
ec_id = 0 |
267 |
end |
268 |
local ret, state = CORBA_RTCUtil.get_state(rtc, ec_id) |
269 |
if ret then |
270 |
if state == LifeCycleState.ACTIVE_STATE then |
271 |
return true |
272 |
end |
273 |
end |
274 |
|
275 |
return false |
276 |
end |
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
CORBA_RTCUtil.is_in_error = function(rtc, ec_id) |
283 |
local Manager = require "openrtm.Manager" |
284 |
local LifeCycleState = Manager:instance():getORB().types:lookup("::RTC::LifeCycleState").labelvalue |
285 |
|
286 |
if ec_id == nil then |
287 |
ec_id = 0 |
288 |
end |
289 |
local ret, state = CORBA_RTCUtil.get_state(rtc, ec_id) |
290 |
if ret then |
291 |
if state == LifeCycleState.ERROR_STATE then |
292 |
return true |
293 |
end |
294 |
end |
295 |
|
296 |
return false |
297 |
end |
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
CORBA_RTCUtil.get_default_rate = function(rtc) |
304 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc) |
305 |
return ec:get_rate() |
306 |
end |
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
CORBA_RTCUtil.set_default_rate = function(rtc, rate) |
314 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc) |
315 |
return ec:set_rate(rate) |
316 |
end |
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
CORBA_RTCUtil.get_current_rate = function(rtc, ec_id) |
323 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc, ec_id) |
324 |
return ec:get_rate() |
325 |
end |
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
CORBA_RTCUtil.set_current_rate = function(rtc, ec_id, rate) |
334 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc, ec_id) |
335 |
return ec:set_rate(rate) |
336 |
end |
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
CORBA_RTCUtil.add_rtc_to_default_ec = function(localcomp, othercomp) |
344 |
local Manager = require "openrtm.Manager" |
345 |
local ReturnCode_t = Manager._ReturnCode_t |
346 |
if othercomp == oil.corba.idl.null then |
347 |
return ReturnCode_t.BAD_PARAMETER |
348 |
end |
349 |
local ec = CORBA_RTCUtil.get_actual_ec(localcomp) |
350 |
if ec == oil.corba.idl.null then |
351 |
return ReturnCode_t.BAD_PARAMETER |
352 |
end |
353 |
return NVUtil.getReturnCode(ec:add_component(othercomp)) |
354 |
end |
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
CORBA_RTCUtil.remove_rtc_to_default_ec = function(localcomp, othercomp) |
362 |
local Manager = require "openrtm.Manager" |
363 |
local ReturnCode_t = Manager._ReturnCode_t |
364 |
if othercomp == oil.corba.idl.null then |
365 |
return ReturnCode_t.BAD_PARAMETER |
366 |
end |
367 |
local ec = CORBA_RTCUtil.get_actual_ec(localcomp) |
368 |
if ec == oil.corba.idl.null then |
369 |
return ReturnCode_t.BAD_PARAMETER |
370 |
end |
371 |
return NVUtil.getReturnCode(ec:remove_component(othercomp)) |
372 |
end |
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
CORBA_RTCUtil.get_participants_rtc = function(rtc) |
379 |
local ec = CORBA_RTCUtil.get_actual_ec(rtc) |
380 |
if ec == oil.corba.idl.null then |
381 |
return {} |
382 |
end |
383 |
local profile = ec:get_profile() |
384 |
return profile.participants |
385 |
end |
386 |
|
387 |
|
388 |
|
389 |
|
390 |
CORBA_RTCUtil.get_port_names = function(rtc) |
391 |
local names = {} |
392 |
if rtc == oil.corba.idl.null then |
393 |
return names |
394 |
end |
395 |
local ports = rtc:get_ports() |
396 |
for k,p in ipairs(ports) do |
397 |
local pp = p:get_port_profile() |
398 |
local s = pp.name |
399 |
table.insert(names, s) |
400 |
end |
401 |
return names |
402 |
end |
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
CORBA_RTCUtil.get_inport_names = function(rtc) |
409 |
local names = {} |
410 |
if rtc == oil.corba.idl.null then |
411 |
return names |
412 |
end |
413 |
local ports = rtc:get_ports() |
414 |
for k,p in ipairs(ports) do |
415 |
local pp = p:get_port_profile() |
416 |
local prop = Properties.new() |
417 |
NVUtil.copyToProperties(prop, pp.properties) |
418 |
if prop:getProperty("port.port_type") == "DataInPort" then |
419 |
local s = pp.name |
420 |
table.insert(names, s) |
421 |
end |
422 |
end |
423 |
return names |
424 |
end |
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
CORBA_RTCUtil.get_outport_names = function(rtc) |
431 |
local names = {} |
432 |
if rtc == oil.corba.idl.null then |
433 |
return names |
434 |
end |
435 |
local ports = rtc:get_ports() |
436 |
for k,p in ipairs(ports) do |
437 |
local pp = p:get_port_profile() |
438 |
local prop = Properties.new() |
439 |
NVUtil.copyToProperties(prop, pp.properties) |
440 |
if prop:getProperty("port.port_type") == "DataOutPort" then |
441 |
local s = pp.name |
442 |
table.insert(names, s) |
443 |
end |
444 |
end |
445 |
return names |
446 |
end |
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
CORBA_RTCUtil.get_svcport_names = function(rtc) |
453 |
local names = {} |
454 |
if rtc == oil.corba.idl.null then |
455 |
return names |
456 |
end |
457 |
local ports = rtc:get_ports() |
458 |
for k,p in ipairs(ports) do |
459 |
local pp = p:get_port_profile() |
460 |
local prop = Properties.new() |
461 |
NVUtil.copyToProperties(prop, pp.properties) |
462 |
if prop:getProperty("port.port_type") == "CorbaPort" then |
463 |
local s = pp.name |
464 |
table.insert(names, s) |
465 |
end |
466 |
end |
467 |
return names |
468 |
end |
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
CORBA_RTCUtil.get_port_by_name = function(rtc, port_name) |
484 |
if rtc == oil.corba.idl.null then |
485 |
return oil.corba.idl.null |
486 |
end |
487 |
local ports = rtc:get_ports() |
488 |
for k,p in ipairs(ports) do |
489 |
pp = p:get_port_profile() |
490 |
s = pp.name |
491 |
|
492 |
if port_name == s then |
493 |
return p |
494 |
end |
495 |
end |
496 |
|
497 |
return oil.corba.idl.null |
498 |
end |
499 |
|
500 |
|
501 |
|
502 |
|
503 |
CORBA_RTCUtil.get_connector_names_by_portref = function(port) |
504 |
local names = {} |
505 |
if port == oil.corba.idl.null then |
506 |
return names |
507 |
end |
508 |
local conprof = port:get_connector_profiles() |
509 |
for k,c in ipairs(conprof) do |
510 |
table.insert(names, c.name) |
511 |
end |
512 |
return names |
513 |
end |
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
CORBA_RTCUtil.get_connector_names = function(rtc, port_name) |
520 |
local names = {} |
521 |
local port = CORBA_RTCUtil.get_port_by_name(rtc, port_name) |
522 |
if port == oil.corba.idl.null then |
523 |
return names |
524 |
end |
525 |
local conprof = port:get_connector_profiles() |
526 |
for k,c in ipairs(conprof) do |
527 |
table.insert(names, c.name) |
528 |
end |
529 |
return names |
530 |
end |
531 |
|
532 |
|
533 |
|
534 |
|
535 |
CORBA_RTCUtil.get_connector_ids_by_portref = function(port) |
536 |
local ids = {} |
537 |
if port == oil.corba.idl.null then |
538 |
return ids |
539 |
end |
540 |
local conprof = port:get_connector_profiles() |
541 |
for k,c in ipairs(conprof) do |
542 |
table.insert(ids, c.connector_id) |
543 |
end |
544 |
return ids |
545 |
end |
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
CORBA_RTCUtil.get_connector_ids = function(rtc, port_name) |
552 |
local ids = {} |
553 |
local port = CORBA_RTCUtil.get_port_by_name(rtc, port_name) |
554 |
if port == oil.corba.idl.null then |
555 |
return ids |
556 |
end |
557 |
local conprof = port:get_connector_profiles() |
558 |
for k,c in ipairs(conprof) do |
559 |
table.insert(ids, c.connector_id) |
560 |
end |
561 |
return ids |
562 |
end |
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
CORBA_RTCUtil.create_connector = function(name, prop_arg, port0, port1) |
575 |
local prop = prop_arg |
576 |
local conn_prof = {name=name, connector_id="", ports={}, properties={}} |
577 |
if port1 == oil.corba.idl.null then |
578 |
conn_prof.ports = {port0} |
579 |
else |
580 |
conn_prof.ports = {port0, port1} |
581 |
end |
582 |
|
583 |
|
584 |
if tostring(prop:getProperty("dataport.dataflow_type")) == "" then |
585 |
prop:setProperty("dataport.dataflow_type","push") |
586 |
end |
587 |
|
588 |
|
589 |
|
590 |
if tostring(prop:getProperty("dataport.interface_type")) == "" then |
591 |
prop:setProperty("dataport.interface_type","data_service") |
592 |
end |
593 |
|
594 |
|
595 |
conn_prof.properties = {} |
596 |
NVUtil.copyFromProperties(conn_prof.properties, prop) |
597 |
|
598 |
return conn_prof |
599 |
end |
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
CORBA_RTCUtil.already_connected = function(localport, otherport) |
606 |
local conprof = localport:get_connector_profiles() |
607 |
for k,c in ipairs(conprof) do |
608 |
for k,p in ipairs(c.ports) do |
609 |
if NVUtil._is_equivalent(p, otherport, p.getPortRef, otherport.getPortRef) then |
610 |
return true |
611 |
end |
612 |
end |
613 |
end |
614 |
|
615 |
return false |
616 |
end |
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
CORBA_RTCUtil.connect = function(name, prop, port0, port1) |
627 |
local Manager = require "openrtm.Manager" |
628 |
local ReturnCode_t = Manager._ReturnCode_t |
629 |
if port0 == oil.corba.idl.null then |
630 |
return ReturnCode_t.BAD_PARAMETER |
631 |
end |
632 |
if port1 ~= oil.corba.idl.null then |
633 |
if NVUtil._is_equivalent(port0, port1, port0.getPortRef, port1.getPortRef) then |
634 |
return ReturnCode_t.BAD_PARAMETER |
635 |
end |
636 |
end |
637 |
|
638 |
local cprof = CORBA_RTCUtil.create_connector(name, prop, port0, port1) |
639 |
|
640 |
local ret, prof = port0:connect(cprof) |
641 |
ret = NVUtil.getReturnCode(ret) |
642 |
|
643 |
|
644 |
return ret |
645 |
end |
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
CORBA_RTCUtil.connect_multi = function(name, prop, port, target_ports) |
657 |
local Manager = require "openrtm.Manager" |
658 |
local ReturnCode_t = Manager._ReturnCode_t |
659 |
local ret = ReturnCode_t.RTC_OK |
660 |
if port == oil.corba.idl.null then |
661 |
return ReturnCode_t.BAD_PARAMETER |
662 |
end |
663 |
for k,p in ipairs(target_ports) do |
664 |
if p == oil.corba.idl.null then |
665 |
ret = ReturnCode_t.BAD_PARAMETER |
666 |
else |
667 |
if NVUtil._is_equivalent(p, port, p.getPortRef, port.getPortRef) then |
668 |
ret = ReturnCode_t.BAD_PARAMETER |
669 |
else |
670 |
if CORBA_RTCUtil.already_connected(port, p) then |
671 |
ret = ReturnCode_t.BAD_PARAMETER |
672 |
else |
673 |
if ReturnCode_t.RTC_OK ~= CORBA_RTCUtil.connect(name, prop, port, p) then |
674 |
ret = ReturnCode_t.BAD_PARAMETER |
675 |
end |
676 |
end |
677 |
end |
678 |
end |
679 |
end |
680 |
|
681 |
|
682 |
return ret |
683 |
end |
684 |
|
685 |
|
686 |
|
687 |
|
688 |
CORBA_RTCUtil.find_port = function(name) |
689 |
local obj = {} |
690 |
obj._name = name |
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
local call_func = function(self, p) |
698 |
local prof = p:get_port_profile() |
699 |
local c = prof.name |
700 |
|
701 |
return (self._name == c) |
702 |
end |
703 |
setmetatable(obj, {__call=call_func}) |
704 |
|
705 |
return obj |
706 |
end |
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
CORBA_RTCUtil.connect_by_name = function(name, prop, rtc0, port_name0, rtc1, port_name1) |
720 |
local Manager = require "openrtm.Manager" |
721 |
local ReturnCode_t = Manager._ReturnCode_t |
722 |
if rtc0 == oil.corba.idl.null then |
723 |
return ReturnCode_t.BAD_PARAMETER |
724 |
end |
725 |
if rtc1 == oil.corba.idl.null then |
726 |
return ReturnCode_t.BAD_PARAMETER |
727 |
end |
728 |
|
729 |
local port0 = CORBA_RTCUtil.get_port_by_name(rtc0, port_name0) |
730 |
if port0 == oil.corba.idl.null then |
731 |
return ReturnCode_t.BAD_PARAMETER |
732 |
end |
733 |
|
734 |
local port1 = CORBA_RTCUtil.get_port_by_name(rtc1, port_name1) |
735 |
if port1 == oil.corba.idl.null then |
736 |
return ReturnCode_t.BAD_PARAMETER |
737 |
end |
738 |
|
739 |
return CORBA_RTCUtil.connect(name, prop, port0, port1) |
740 |
end |
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
CORBA_RTCUtil.disconnect = function(connector_prof) |
747 |
local ports = connector_prof.ports |
748 |
return CORBA_RTCUtil.disconnect_by_portref_connector_id(ports[1], connector_prof.connector_id) |
749 |
end |
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
CORBA_RTCUtil.disconnect_by_portref_connector_name = function(port_ref, conn_name) |
759 |
local Manager = require "openrtm.Manager" |
760 |
local ReturnCode_t = Manager._ReturnCode_t |
761 |
if port_ref == oil.corba.idl.null then |
762 |
return ReturnCode_t.BAD_PARAMETER |
763 |
end |
764 |
local conprof = port_ref:get_connector_profiles() |
765 |
for k,c in ipairs(conprof) do |
766 |
if c.name == conn_name then |
767 |
return CORBA_RTCUtil.disconnect(c) |
768 |
end |
769 |
end |
770 |
return ReturnCode_t.BAD_PARAMETER |
771 |
end |
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
CORBA_RTCUtil.disconnect_by_portname_connector_name = function(port_name, conn_name) |
783 |
local Manager = require "openrtm.Manager" |
784 |
local ReturnCode_t = Manager._ReturnCode_t |
785 |
local port_ref = CORBA_RTCUtil.get_port_by_url(port_name) |
786 |
if port_ref == oil.corba.idl.null then |
787 |
return ReturnCode_t.BAD_PARAMETER |
788 |
end |
789 |
|
790 |
|
791 |
local conprof = port_ref:get_connector_profiles() |
792 |
for k,c in pairs(conprof) do |
793 |
if c.name == conn_name then |
794 |
return CORBA_RTCUtil.disconnect(c) |
795 |
end |
796 |
end |
797 |
|
798 |
return ReturnCode_t.BAD_PARAMETER |
799 |
end |
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
CORBA_RTCUtil.disconnect_by_portref_connector_id = function(port_ref, conn_id) |
808 |
local Manager = require "openrtm.Manager" |
809 |
local ReturnCode_t = Manager._ReturnCode_t |
810 |
if port_ref == oil.corba.idl.null then |
811 |
return ReturnCode_t.BAD_PARAMETER |
812 |
end |
813 |
return NVUtil.getReturnCode(port_ref:disconnect(conn_id)) |
814 |
end |
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
CORBA_RTCUtil.disconnect_by_portname_connector_id = function(port_name, conn_id) |
825 |
local Manager = require "openrtm.Manager" |
826 |
local ReturnCode_t = Manager._ReturnCode_t |
827 |
local port_ref = CORBA_RTCUtil.get_port_by_url(port_name) |
828 |
if port_ref == oil.corba.idl.null then |
829 |
return ReturnCode_t.BAD_PARAMETER |
830 |
end |
831 |
|
832 |
return NVUtil.getReturnCode(port_ref:disconnect(conn_id)) |
833 |
end |
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
CORBA_RTCUtil.disconnect_all_by_ref = function(port_ref) |
840 |
local Manager = require "openrtm.Manager" |
841 |
local ReturnCode_t = Manager._ReturnCode_t |
842 |
if port_ref == oil.corba.idl.null then |
843 |
return ReturnCode_t.BAD_PARAMETER |
844 |
end |
845 |
return NVUtil.getReturnCode(port_ref:disconnect_all()) |
846 |
end |
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
CORBA_RTCUtil.disconnect_all_by_name = function(port_name) |
855 |
local Manager = require "openrtm.Manager" |
856 |
local ReturnCode_t = Manager._ReturnCode_t |
857 |
local port_ref = CORBA_RTCUtil.get_port_by_url(port_name) |
858 |
if port_ref == oil.corba.idl.null then |
859 |
return ReturnCode_t.BAD_PARAMETER |
860 |
end |
861 |
return NVUtil.getReturnCode(port_ref:disconnect_all()) |
862 |
end |
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
CORBA_RTCUtil.get_port_by_url = function(port_name) |
871 |
local Manager = require "openrtm.Manager" |
872 |
local mgr = Manager:instance() |
873 |
local nm = mgr:getNaming() |
874 |
local p = StringUtil.split(port_name, "%.") |
875 |
if #p < 2 then |
876 |
return oil.corba.idl.null |
877 |
end |
878 |
|
879 |
local tmp = StringUtil.split(port_name, "%.") |
880 |
tmp[#tmp] = nil |
881 |
|
882 |
|
883 |
local rtcs = nm:string_to_component(StringUtil.flatten(tmp, "%.")) |
884 |
|
885 |
if #rtcs < 1 then |
886 |
return oil.corba.idl.null |
887 |
end |
888 |
local pn = StringUtil.split(port_name, "/") |
889 |
|
890 |
return CORBA_RTCUtil.get_port_by_name(rtcs[1],pn[#pn]) |
891 |
end |
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
CORBA_RTCUtil.disconnect_by_port_name = function(localport, othername) |
901 |
local Manager = require "openrtm.Manager" |
902 |
local ReturnCode_t = Manager._ReturnCode_t |
903 |
if localport == oil.corba.idl.null then |
904 |
return ReturnCode_t.BAD_PARAMETER |
905 |
end |
906 |
local prof = localport:get_port_profile() |
907 |
if prof.name == othername then |
908 |
|
909 |
return ReturnCode_t.BAD_PARAMETER |
910 |
end |
911 |
|
912 |
local conprof = localport:get_connector_profiles() |
913 |
for k,c in ipairs(conprof) do |
914 |
for k2,p in ipairs(c.ports) do |
915 |
if p ~= oil.corba.idl.null then |
916 |
local pp = p:get_port_profile() |
917 |
|
918 |
if pp.name == othername then |
919 |
return CORBA_RTCUtil.disconnect(c) |
920 |
end |
921 |
end |
922 |
end |
923 |
end |
924 |
return ReturnCode_t.BAD_PARAMETER |
925 |
end |
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
CORBA_RTCUtil.get_configuration = function(rtc, conf_name) |
932 |
local conf = rtc:get_configuration() |
933 |
|
934 |
local confset = conf:get_configuration_set(conf_name) |
935 |
local confData = confset.configuration_data |
936 |
local prop = Properties.new() |
937 |
NVUtil.copyToProperties(prop, confData) |
938 |
return prop |
939 |
end |
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
CORBA_RTCUtil.get_parameter_by_key = function(rtc, confset_name, value_name) |
947 |
local conf = rtc:get_configuration() |
948 |
|
949 |
|
950 |
local confset = conf:get_configuration_set(confset_name) |
951 |
local confData = confset.configuration_data |
952 |
local prop = Properties.new() |
953 |
NVUtil.copyToProperties(prop, confData) |
954 |
return prop:getProperty(value_name) |
955 |
end |
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
CORBA_RTCUtil.get_active_configuration_name = function(rtc) |
962 |
local conf = rtc:get_configuration() |
963 |
local confset = conf:get_active_configuration_set() |
964 |
return confset.id |
965 |
end |
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
CORBA_RTCUtil.get_active_configuration = function(rtc) |
972 |
local conf = rtc:get_configuration() |
973 |
|
974 |
local confset = conf:get_active_configuration_set() |
975 |
local confData = confset.configuration_data |
976 |
local prop = Properties.new() |
977 |
NVUtil.copyToProperties(prop, confData) |
978 |
return prop |
979 |
end |
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
CORBA_RTCUtil.set_configuration = function(rtc, confset_name, value_name, value) |
989 |
local conf = rtc:get_configuration() |
990 |
|
991 |
local confset = conf:get_configuration_set(confset_name) |
992 |
|
993 |
CORBA_RTCUtil.set_configuration_parameter(conf, confset, value_name, value) |
994 |
|
995 |
conf:activate_configuration_set(confset_name) |
996 |
return true |
997 |
end |
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
CORBA_RTCUtil.set_active_configuration = function(rtc, value_name, value) |
1006 |
local conf = rtc:get_configuration() |
1007 |
|
1008 |
local confset = conf:get_active_configuration_set() |
1009 |
CORBA_RTCUtil.set_configuration_parameter(conf, confset, value_name, value) |
1010 |
|
1011 |
conf:activate_configuration_set(confset.id) |
1012 |
return true |
1013 |
end |
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
CORBA_RTCUtil.set_configuration_parameter = function(conf, confset, value_name, value) |
1023 |
local confData = confset.configuration_data |
1024 |
local prop = Properties.new() |
1025 |
NVUtil.copyToProperties(prop, confData) |
1026 |
prop:setProperty(value_name,value) |
1027 |
NVUtil.copyFromProperties(confData,prop) |
1028 |
confset.configuration_data = confData |
1029 |
conf:set_configuration_set_values(confset) |
1030 |
return true |
1031 |
end |
1032 |
|
1033 |
|
1034 |
return CORBA_RTCUtil |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
local ExecutionContextBase= {} |
12 |
|
13 |
|
14 |
|
15 |
local TimeValue = require "openrtm.TimeValue" |
16 |
local ExecutionContextWorker = require "openrtm.ExecutionContextWorker" |
17 |
local ExecutionContextProfile = require "openrtm.ExecutionContextProfile" |
18 |
local GlobalFactory = require "openrtm.GlobalFactory" |
19 |
local NVUtil = require "openrtm.NVUtil" |
20 |
local Properties = require "openrtm.Properties" |
21 |
|
22 |
|
23 |
local DEFAULT_EXECUTION_RATE = 1000 |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
ExecutionContextBase.new = function(name) |
29 |
local obj = {} |
30 |
local Manager = require "openrtm.Manager" |
31 |
obj._ReturnCode_t = Manager:instance():getORB().types:lookup("::RTC::ReturnCode_t").labelvalue |
32 |
obj._LifeCycleState = Manager:instance():getORB().types:lookup("::RTC::LifeCycleState").labelvalue |
33 |
|
34 |
obj._rtcout = Manager:instance():getLogbuf("ec_base") |
35 |
obj._activationTimeout = TimeValue.new(0.5) |
36 |
obj._degetConfigvationTimeout = TimeValue.new(0.5) |
37 |
obj._resetTimeout = TimeValue.new(0.5) |
38 |
obj._syncActivation = true |
39 |
obj._syncDeactivation = true |
40 |
obj._syncReset = true |
41 |
obj._worker = ExecutionContextWorker.new() |
42 |
obj._profile = ExecutionContextProfile.new() |
43 |
|
44 |
|
45 |
|
46 |
function obj:init(props) |
47 |
self._rtcout:RTC_TRACE("init()") |
48 |
self._rtcout:RTC_DEBUG(props) |
49 |
|
50 |
self:setExecutionRate(props) |
51 |
self:setProperties(props) |
52 |
|
53 |
self._syncActivation = false |
54 |
self._syncDeactivation = false |
55 |
self._syncReset = false |
56 |
end |
57 |
|
58 |
function obj:exit() |
59 |
self._rtcout:RTC_TRACE("exit()") |
60 |
self._profile:exit() |
61 |
self._worker:exit() |
62 |
end |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
function obj:setExecutionRate(props) |
69 |
if props:findNode("rate") then |
70 |
local rate_ = tonumber(props:getProperty("rate")) |
71 |
if rate_ ~= nil then |
72 |
self:setRate(rate_) |
73 |
return true |
74 |
end |
75 |
end |
76 |
return false |
77 |
end |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
function obj:setRate(rate) |
85 |
self._rtcout:RTC_TRACE("setRate("..rate..")") |
86 |
local ret_ = self._profile:setRate(self:onSettingRate(rate)) |
87 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
88 |
self._rtcout:RTC_ERROR("Setting execution rate failed. "..rate) |
89 |
return ret_ |
90 |
end |
91 |
|
92 |
ret_ = self._worker:rateChanged() |
93 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
94 |
self._rtcout:RTC_ERROR("Invoking on_rate_changed() for each RTC failed.") |
95 |
return ret_ |
96 |
end |
97 |
|
98 |
ret_ = self:onSetRate(rate) |
99 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
100 |
self._rtcout:RTC_ERROR("onSetRate("..rate..") failed.") |
101 |
return ret_ |
102 |
end |
103 |
self._rtcout:RTC_INFO("setRate("..rate..") done") |
104 |
return ret_ |
105 |
end |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
function obj:setProperties(props) |
113 |
self._profile:setProperties(props) |
114 |
end |
115 |
|
116 |
|
117 |
|
118 |
function obj:setObjRef(ec_ptr) |
119 |
self._worker:setECRef(ec_ptr) |
120 |
self._profile:setObjRef(ec_ptr) |
121 |
end |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
function obj:setKind(kind) |
129 |
return self._profile:setKind(kind) |
130 |
end |
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
function obj:bindComponent(rtc) |
139 |
self:setOwner(rtc:getObjRef()) |
140 |
return self._worker:bindComponent(rtc) |
141 |
end |
142 |
|
143 |
|
144 |
|
145 |
function obj:getObjRef() |
146 |
return self._profile:getObjRef() |
147 |
end |
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
function obj:start() |
154 |
self._rtcout:RTC_TRACE("start()") |
155 |
local ret_ = self:onStarting() |
156 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
157 |
self._rtcout:RTC_ERROR("onStarting() failed. Starting EC aborted.") |
158 |
return ret_ |
159 |
end |
160 |
|
161 |
ret_ = self._worker:start() |
162 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
163 |
self._rtcout:RTC_ERROR("Invoking on_startup() for each RTC failed.") |
164 |
return ret_ |
165 |
end |
166 |
|
167 |
ret_ = self:onStarted() |
168 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
169 |
self._rtcout:RTC_ERROR("onStartted() failed. Started EC aborted..") |
170 |
self._worker:stop() |
171 |
self._rtcout:RTC_ERROR("on_shutdown() was invoked, because of onStarted") |
172 |
return ret_ |
173 |
end |
174 |
|
175 |
return ret_ |
176 |
end |
177 |
|
178 |
|
179 |
|
180 |
|
181 |
function obj:onIsRunning(running) |
182 |
return running |
183 |
end |
184 |
|
185 |
|
186 |
function obj:onStarting() |
187 |
return self._ReturnCode_t.RTC_OK |
188 |
end |
189 |
|
190 |
|
191 |
function obj:onStarted() |
192 |
return self._ReturnCode_t.RTC_OK |
193 |
end |
194 |
|
195 |
|
196 |
function obj:onStopping() |
197 |
return self._ReturnCode_t.RTC_OK |
198 |
end |
199 |
|
200 |
|
201 |
function obj:onStopped() |
202 |
return self._ReturnCode_t.RTC_OK |
203 |
end |
204 |
|
205 |
|
206 |
|
207 |
function obj:onGetRate(rate) |
208 |
return rate |
209 |
end |
210 |
|
211 |
|
212 |
|
213 |
function obj:onSettingRate(rate) |
214 |
|
215 |
return rate |
216 |
end |
217 |
|
218 |
|
219 |
|
220 |
|
221 |
function obj:onSetRate(rate) |
222 |
return self._ReturnCode_t.RTC_OK |
223 |
end |
224 |
|
225 |
|
226 |
|
227 |
function obj:onAddingComponent(rtobj) |
228 |
return self._ReturnCode_t.RTC_OK |
229 |
end |
230 |
|
231 |
|
232 |
|
233 |
function obj:onAddedComponent(rtobj) |
234 |
return self._ReturnCode_t.RTC_OK |
235 |
end |
236 |
|
237 |
|
238 |
|
239 |
function obj:onRemovingComponent(rtobj) |
240 |
return self._ReturnCode_t.RTC_OK |
241 |
end |
242 |
|
243 |
|
244 |
|
245 |
function obj:onRemovedComponent(rtobj) |
246 |
return self._ReturnCode_t.RTC_OK |
247 |
end |
248 |
|
249 |
|
250 |
|
251 |
function obj:onActivating(comp) |
252 |
return self._ReturnCode_t.RTC_OK |
253 |
end |
254 |
|
255 |
|
256 |
|
257 |
|
258 |
function obj:onWaitingActivated(comp, count) |
259 |
return self._ReturnCode_t.RTC_OK |
260 |
end |
261 |
|
262 |
|
263 |
|
264 |
|
265 |
function obj:onActivated(comp, count) |
266 |
return self._ReturnCode_t.RTC_OK |
267 |
end |
268 |
|
269 |
|
270 |
|
271 |
function obj:onActivating(comp) |
272 |
return self._ReturnCode_t.RTC_OK |
273 |
end |
274 |
|
275 |
|
276 |
|
277 |
function obj:onDeactivating(comp) |
278 |
return self._ReturnCode_t.RTC_OK |
279 |
end |
280 |
|
281 |
|
282 |
|
283 |
|
284 |
function obj:onWaitingDeactivated(comp, count) |
285 |
return self._ReturnCode_t.RTC_OK |
286 |
end |
287 |
|
288 |
|
289 |
|
290 |
|
291 |
function obj:onDeactivated(comp, count) |
292 |
return self._ReturnCode_t.RTC_OK |
293 |
end |
294 |
|
295 |
|
296 |
|
297 |
function obj:onResetting(comp) |
298 |
return self._ReturnCode_t.RTC_OK |
299 |
end |
300 |
|
301 |
|
302 |
|
303 |
|
304 |
function obj:onWaitingReset(comp, count) |
305 |
return self._ReturnCode_t.RTC_OK |
306 |
end |
307 |
|
308 |
|
309 |
|
310 |
|
311 |
function obj:onReset(comp, count) |
312 |
return self._ReturnCode_t.RTC_OK |
313 |
end |
314 |
|
315 |
|
316 |
|
317 |
function obj:onGetComponentState(state) |
318 |
return state |
319 |
end |
320 |
|
321 |
|
322 |
|
323 |
function obj:onGetKind(kind) |
324 |
return kind |
325 |
end |
326 |
|
327 |
|
328 |
|
329 |
function obj:onGetProfile(profile) |
330 |
return profile |
331 |
end |
332 |
|
333 |
|
334 |
function obj:invokeWorkerPreDo() |
335 |
self._worker:invokeWorkerPreDo() |
336 |
end |
337 |
|
338 |
|
339 |
function obj:invokeWorkerDo() |
340 |
self._worker:invokeWorkerDo() |
341 |
end |
342 |
|
343 |
|
344 |
function obj:invokeWorkerPostDo() |
345 |
self._worker:invokeWorkerPostDo() |
346 |
end |
347 |
|
348 |
|
349 |
function obj:getPeriod() |
350 |
return self._profile:getPeriod() |
351 |
end |
352 |
|
353 |
|
354 |
function obj:getRate() |
355 |
local rate_ = self._profile:getRate() |
356 |
return self:onGetRate(rate_) |
357 |
end |
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
function obj:activateComponent(comp) |
365 |
self._rtcout:RTC_TRACE("activateComponent()") |
366 |
local ret_ = self:onActivating(comp) |
367 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
368 |
self._rtcout:RTC_ERROR("onActivating() failed.") |
369 |
return ret_ |
370 |
end |
371 |
|
372 |
local rtobj_ = {object=nil} |
373 |
ret_ = self._worker:activateComponent(comp, rtobj_) |
374 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
375 |
return ret_ |
376 |
end |
377 |
|
378 |
if not self._syncActivation then |
379 |
ret_ = self:onActivated(rtobj_.object, -1) |
380 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
381 |
|
382 |
self._rtcout:RTC_ERROR("onActivated() failed.") |
383 |
end |
384 |
|
385 |
return ret_ |
386 |
end |
387 |
|
388 |
|
389 |
self._rtcout:RTC_DEBUG("Synchronous activation mode. ") |
390 |
self._rtcout:RTC_DEBUG("Waiting for the RTC to be ACTIVE state. ") |
391 |
return self:waitForActivated(rtobj_.object) |
392 |
end |
393 |
|
394 |
|
395 |
|
396 |
function obj:waitForActivated(rtobj) |
397 |
return self._ReturnCode_t.RTC_OK |
398 |
end |
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
function obj:deactivateComponent(comp) |
406 |
self._rtcout:RTC_TRACE("deactivateComponent()") |
407 |
local ret_ = self:onDeactivating(comp) |
408 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
409 |
self._rtcout:RTC_ERROR("onDeactivating() failed.") |
410 |
return ret_ |
411 |
end |
412 |
|
413 |
local rtobj_ = {object=nil} |
414 |
ret_ = self._worker:deactivateComponent(comp, rtobj_) |
415 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
416 |
return ret_ |
417 |
end |
418 |
|
419 |
if not self._syncDeactivation then |
420 |
ret_ = self:onDeactivated(rtobj_[0], -1) |
421 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
422 |
self._rtcout:RTC_ERROR("onActivated() failed.") |
423 |
end |
424 |
return ret_ |
425 |
end |
426 |
|
427 |
self._rtcout:RTC_DEBUG("Synchronous deactivation mode. ") |
428 |
self._rtcout:RTC_DEBUG("Waiting for the RTC to be INACTIVE state. ") |
429 |
return self:waitForDeactivated(rtobj_.object) |
430 |
|
431 |
end |
432 |
|
433 |
|
434 |
|
435 |
function obj:waitForDeactivated(rtobj) |
436 |
return self._ReturnCode_t.RTC_OK |
437 |
end |
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
function obj:resetComponent(comp) |
445 |
self._rtcout:RTC_TRACE("resetComponent()") |
446 |
local ret_ = self:onResetting(comp) |
447 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
448 |
self._rtcout:RTC_ERROR("onResetting() failed.") |
449 |
return ret_ |
450 |
end |
451 |
|
452 |
local rtobj_ = {object=nil} |
453 |
ret_ = self._worker:resetComponent(comp, rtobj_) |
454 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
455 |
return ret_ |
456 |
end |
457 |
|
458 |
if not self._syncReset then |
459 |
ret_ = self:onReset(rtobj_[0], -1) |
460 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
461 |
self._rtcout:RTC_ERROR("onReset() failed.") |
462 |
end |
463 |
return ret_ |
464 |
end |
465 |
|
466 |
self._rtcout:RTC_DEBUG("Synchronous deactivation mode. ") |
467 |
self._rtcout:RTC_DEBUG("Waiting for the RTC to be INACTIVE state. ") |
468 |
return self:waitForReset(rtobj_.object) |
469 |
|
470 |
end |
471 |
|
472 |
|
473 |
|
474 |
function obj:waitForReset(rtobj) |
475 |
return self._ReturnCode_t.RTC_OK |
476 |
end |
477 |
|
478 |
|
479 |
|
480 |
function obj:isRunning() |
481 |
self._rtcout:RTC_TRACE("isRunning()") |
482 |
return self._worker:isRunning() |
483 |
end |
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
function obj:is_running() |
490 |
self._rtcout:RTC_TRACE("is_running()") |
491 |
return self:isRunning() |
492 |
end |
493 |
|
494 |
|
495 |
|
496 |
function obj:get_rate() |
497 |
return self:getRate() |
498 |
end |
499 |
|
500 |
|
501 |
|
502 |
function obj:set_rate(rate) |
503 |
return self:setRate(rate) |
504 |
end |
505 |
|
506 |
|
507 |
|
508 |
function obj:activate_component(comp) |
509 |
|
510 |
return self:activateComponent(comp) |
511 |
end |
512 |
|
513 |
|
514 |
|
515 |
function obj:deactivate_component(comp) |
516 |
return self:deactivateComponent(comp) |
517 |
end |
518 |
|
519 |
|
520 |
|
521 |
function obj:reset_component(comp) |
522 |
return self:resetComponent(comp) |
523 |
end |
524 |
|
525 |
|
526 |
|
527 |
function obj:get_component_state(comp) |
528 |
return self:getComponentState(comp) |
529 |
end |
530 |
|
531 |
|
532 |
function obj:get_kind() |
533 |
return self:getKind() |
534 |
end |
535 |
function obj:getKind() |
536 |
local kind_ = self._profile:getKind() |
537 |
self._rtcout:RTC_TRACE("getKind() = %s", self:getKindString(kind_)) |
538 |
kind_ = self:onGetKind(kind_) |
539 |
self._rtcout:RTC_DEBUG("onGetKind() returns %s", self:getKindString(kind_)) |
540 |
return kind_ |
541 |
end |
542 |
|
543 |
|
544 |
|
545 |
function obj:addComponent(comp) |
546 |
self._rtcout:RTC_TRACE("addComponent()") |
547 |
local ret_ = self:onAddingComponent(comp) |
548 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
549 |
self._rtcout:RTC_ERROR("Error: onAddingComponent(). RTC is not attached.") |
550 |
return ret_ |
551 |
end |
552 |
|
553 |
ret_ = self._worker:addComponent(comp) |
554 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
555 |
self._rtcout:RTC_ERROR("Error: ECWorker addComponent() faild.") |
556 |
return ret_ |
557 |
end |
558 |
|
559 |
ret_ = self._profile:addComponent(comp) |
560 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
561 |
self._rtcout:RTC_ERROR("Error: ECProfile addComponent() faild.") |
562 |
return ret_ |
563 |
end |
564 |
|
565 |
ret_ = self:onAddedComponent(comp) |
566 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
567 |
self._rtcout:RTC_ERROR("Error: onAddedComponent() faild.") |
568 |
self._rtcout:RTC_INFO("Removing attached RTC.") |
569 |
self._worker:removeComponent(comp) |
570 |
self._profile:removeComponent(comp) |
571 |
return ret_ |
572 |
end |
573 |
|
574 |
self._rtcout:RTC_INFO("Component has been added to this EC.") |
575 |
return self._ReturnCode_t.RTC_OK |
576 |
end |
577 |
|
578 |
|
579 |
|
580 |
function obj:add_component(comp) |
581 |
return self:addComponent(comp) |
582 |
end |
583 |
|
584 |
|
585 |
|
586 |
function obj:removeComponent(comp) |
587 |
self._rtcout:RTC_TRACE("removeComponent()") |
588 |
local ret_ = self:onRemovingComponent(comp) |
589 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
590 |
self._rtcout:RTC_ERROR("Error: onRemovingComponent(). RTC will not not attached.") |
591 |
return ret_ |
592 |
end |
593 |
|
594 |
ret_ = self._worker:removeComponent(comp) |
595 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
596 |
self._rtcout:RTC_ERROR("Error: ECWorker removeComponent() faild.") |
597 |
return ret_ |
598 |
end |
599 |
|
600 |
ret_ = self._profile:removeComponent(comp) |
601 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
602 |
self._rtcout:RTC_ERROR("Error: ECProfile removeComponent() faild.") |
603 |
return ret_ |
604 |
end |
605 |
|
606 |
ret_ = self:onRemovedComponent(comp) |
607 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
608 |
self._rtcout:RTC_ERROR("Error: onRemovedComponent() faild.") |
609 |
self._rtcout:RTC_INFO("Removing attached RTC.") |
610 |
self._worker:removeComponent(comp) |
611 |
self._profile:removeComponent(comp) |
612 |
return ret_ |
613 |
end |
614 |
|
615 |
self._rtcout:RTC_INFO("Component has been removeed to this EC.") |
616 |
return self._ReturnCode_t.RTC_OK |
617 |
end |
618 |
|
619 |
|
620 |
|
621 |
function obj:remove_component(comp) |
622 |
return self:removeComponent(comp) |
623 |
end |
624 |
|
625 |
|
626 |
function obj:get_profile() |
627 |
return self:getProfile() |
628 |
end |
629 |
|
630 |
|
631 |
function obj:getProfile() |
632 |
self._rtcout:RTC_TRACE("getProfile()") |
633 |
local prof_ = self._profile:getProfile() |
634 |
self._rtcout:RTC_DEBUG("kind: "..self:getKindString(prof_.kind)) |
635 |
self._rtcout:RTC_DEBUG("rate: "..prof_.rate) |
636 |
self._rtcout:RTC_DEBUG("properties:") |
637 |
local props_ = Properties.new() |
638 |
NVUtil.copyToProperties(props_, prof_.properties) |
639 |
self._rtcout:RTC_DEBUG(props_) |
640 |
return self:onGetProfile(prof_) |
641 |
end |
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
function obj:setOwner(comp) |
648 |
return self._profile:setOwner(comp) |
649 |
end |
650 |
|
651 |
|
652 |
|
653 |
function obj:getOwner() |
654 |
return self._profile:getOwner() |
655 |
end |
656 |
|
657 |
|
658 |
|
659 |
function obj:getKindString(kind) |
660 |
return self._profile:getKindString(kind) |
661 |
end |
662 |
|
663 |
|
664 |
|
665 |
|
666 |
function obj:getComponentState(comp) |
667 |
local state_ = self._worker:getComponentState(comp) |
668 |
self._rtcout:RTC_TRACE("getComponentState() = "..self:getStateString(state_)) |
669 |
if state_ == self._LifeCycleState.CREATED_STATE then |
670 |
self._rtcout:RTC_ERROR("CREATED state: not initialized ".. |
671 |
"RTC or unknwon RTC specified.") |
672 |
end |
673 |
|
674 |
return self:onGetComponentState(state_) |
675 |
end |
676 |
|
677 |
|
678 |
|
679 |
function obj:getStateString(state) |
680 |
return self._worker:getStateString(state) |
681 |
end |
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
function obj:stop() |
688 |
self._rtcout:RTC_TRACE("stop()") |
689 |
local ret_ = self:onStopping() |
690 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
691 |
self._rtcout:RTC_ERROR("onStopping() failed. Stopping EC aborted.") |
692 |
return ret_ |
693 |
end |
694 |
|
695 |
ret_ = self._worker:stop() |
696 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
697 |
self._rtcout:RTC_ERROR("Invoking on_shutdown() for each RTC failed.") |
698 |
return ret_ |
699 |
end |
700 |
|
701 |
ret_ = self:onStopped() |
702 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
703 |
self._rtcout:RTC_ERROR("onStopped() failed. Stopped EC aborted.") |
704 |
return ret_ |
705 |
end |
706 |
|
707 |
return ret_ |
708 |
end |
709 |
|
710 |
|
711 |
|
712 |
return obj |
713 |
end |
714 |
|
715 |
|
716 |
ExecutionContextBase.ExecutionContextFactory = {} |
717 |
setmetatable(ExecutionContextBase.ExecutionContextFactory, {__index=GlobalFactory.Factory.new()}) |
718 |
|
719 |
function ExecutionContextBase.ExecutionContextFactory:instance() |
720 |
return self |
721 |
end |
722 |
|
723 |
return ExecutionContextBase |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local ExecutionContextWorker= {} |
11 |
|
12 |
|
13 |
|
14 |
local oil = require "oil" |
15 |
local RTObjectStateMachine = require "openrtm.RTObjectStateMachine" |
16 |
local StringUtil = require "openrtm.StringUtil" |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
ExecutionContextWorker.new = function() |
23 |
local obj = {} |
24 |
local RTObject = require "openrtm.RTObject" |
25 |
local ECOTHER_OFFSET = RTObject.ECOTHER_OFFSET |
26 |
local Manager = require "openrtm.Manager" |
27 |
obj._ReturnCode_t = Manager:instance():getORB().types:lookup("::RTC::ReturnCode_t").labelvalue |
28 |
obj._LifeCycleState = Manager:instance():getORB().types:lookup("::RTC::LifeCycleState").labelvalue |
29 |
|
30 |
obj._rtcout = Manager:instance():getLogbuf("ec_worker") |
31 |
obj._running = false |
32 |
obj._rtcout:RTC_TRACE("ExecutionContextWorker.__init__") |
33 |
obj._ref = nil |
34 |
obj._comps = {} |
35 |
obj._addedComps = {} |
36 |
obj._removedComps = {} |
37 |
|
38 |
function obj:exit() |
39 |
self._rtcout:RTC_TRACE("exit") |
40 |
end |
41 |
|
42 |
|
43 |
|
44 |
function obj:rateChanged() |
45 |
self._rtcout:RTC_TRACE("rateChanged()") |
46 |
local ret = self._ReturnCode_t.RTC_OK |
47 |
for i,comp in ipairs(self._comps) do |
48 |
tmp = comp:onRateChanged() |
49 |
if tmp ~= self._ReturnCode_t.RTC_OK then |
50 |
ret = tmp |
51 |
end |
52 |
end |
53 |
return ret |
54 |
end |
55 |
|
56 |
|
57 |
function obj:setECRef(ref) |
58 |
self._ref = ref |
59 |
end |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
function obj:bindComponent(rtc) |
67 |
self._rtcout:RTC_TRACE("bindComponent()") |
68 |
if rtc == nil then |
69 |
self._rtcout:RTC_ERROR("NULL pointer is given.") |
70 |
return self._ReturnCode_t.BAD_PARAMETER |
71 |
end |
72 |
local ec_ = self:getECRef() |
73 |
|
74 |
local id_ = rtc:bindContext(ec_) |
75 |
if id_ < 0 or id_ > ECOTHER_OFFSET then |
76 |
self._rtcout:RTC_ERROR("bindContext returns invalid id: "..id_) |
77 |
return self._ReturnCode_t.RTC_ERROR |
78 |
end |
79 |
|
80 |
self._rtcout:RTC_DEBUG("bindContext returns id = "..id_) |
81 |
|
82 |
|
83 |
local comp_ = rtc |
84 |
table.insert(self._comps, RTObjectStateMachine.new(id_, comp_)) |
85 |
self._rtcout:RTC_DEBUG("bindComponent() succeeded.") |
86 |
return self._ReturnCode_t.RTC_OK |
87 |
end |
88 |
|
89 |
|
90 |
function obj:getECRef() |
91 |
return self._ref |
92 |
end |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
function obj:start() |
98 |
self._rtcout:RTC_TRACE("start()") |
99 |
if self._running then |
100 |
self._rtcout:RTC_WARN("ExecutionContext is already running.") |
101 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
102 |
end |
103 |
|
104 |
|
105 |
for i, comp in ipairs(self._comps) do |
106 |
comp:onStartup() |
107 |
end |
108 |
|
109 |
self._rtcout:RTC_DEBUG(#self._comps.." components started.") |
110 |
self._running = true |
111 |
return self._ReturnCode_t.RTC_OK |
112 |
end |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
function obj:stop() |
118 |
self._rtcout:RTC_TRACE("stop()") |
119 |
|
120 |
if not self._running then |
121 |
self._rtcout:RTC_WARN("ExecutionContext is already stopped.") |
122 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
123 |
end |
124 |
|
125 |
self._running = false |
126 |
|
127 |
for i, comp in ipairs(self._comps) do |
128 |
comp:onShutdown() |
129 |
end |
130 |
|
131 |
|
132 |
return self._ReturnCode_t.RTC_OK |
133 |
end |
134 |
|
135 |
|
136 |
function obj:invokeWorkerPreDo() |
137 |
self._rtcout:RTC_PARANOID("invokeWorkerPreDo()") |
138 |
for i, comp in ipairs(self._comps) do |
139 |
comp:workerPreDo() |
140 |
end |
141 |
end |
142 |
|
143 |
|
144 |
function obj:invokeWorkerDo() |
145 |
self._rtcout:RTC_PARANOID("invokeWorkerDo()") |
146 |
for i, comp in ipairs(self._comps) do |
147 |
comp:workerDo() |
148 |
end |
149 |
end |
150 |
|
151 |
|
152 |
function obj:invokeWorkerPostDo() |
153 |
self._rtcout:RTC_PARANOID("invokeWorkerPostDo()") |
154 |
for i, comp in ipairs(self._comps) do |
155 |
comp:workerPostDo() |
156 |
end |
157 |
self:updateComponentList() |
158 |
end |
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
function obj:activateComponent(comp, rtobj) |
167 |
self._rtcout:RTC_TRACE("activateComponent()") |
168 |
local obj_ = self:findComponent(comp) |
169 |
if obj_ == nil then |
170 |
self._rtcout:RTC_ERROR("Given RTC is not participant of this EC.") |
171 |
return self._ReturnCode_t.BAD_PARAMETER |
172 |
end |
173 |
|
174 |
self._rtcout:RTC_DEBUG("Component found in the EC.") |
175 |
|
176 |
|
177 |
if not obj_:isCurrentState(self._LifeCycleState.INACTIVE_STATE) then |
178 |
self._rtcout:RTC_ERROR("State of the RTC is not INACTIVE_STATE.") |
179 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
180 |
end |
181 |
|
182 |
self._rtcout:RTC_DEBUG("Component is in INACTIVE state. Going to ACTIVE state.") |
183 |
|
184 |
obj_:goTo(self._LifeCycleState.ACTIVE_STATE) |
185 |
rtobj.object = obj_ |
186 |
|
187 |
self._rtcout:RTC_DEBUG("activateComponent() done.") |
188 |
return self._ReturnCode_t.RTC_OK |
189 |
end |
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
function obj:deactivateComponent(comp, rtobj) |
198 |
self._rtcout:RTC_TRACE("deactivateComponent()") |
199 |
local obj_ = self:findComponent(comp) |
200 |
if obj_ == nil then |
201 |
self._rtcout:RTC_ERROR("Given RTC is not participant of this EC.") |
202 |
return self._ReturnCode_t.BAD_PARAMETER |
203 |
end |
204 |
|
205 |
self._rtcout:RTC_DEBUG("Component found in the EC.") |
206 |
|
207 |
if not obj_:isCurrentState(self._LifeCycleState.ACTIVE_STATE) then |
208 |
self._rtcout:RTC_ERROR("State of the RTC is not ACTIVE_STATE.") |
209 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
210 |
end |
211 |
|
212 |
|
213 |
|
214 |
obj_:goTo(self._LifeCycleState.INACTIVE_STATE) |
215 |
rtobj.object = obj_ |
216 |
|
217 |
|
218 |
return self._ReturnCode_t.RTC_OK |
219 |
end |
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
function obj:resetComponent(comp, rtobj) |
228 |
self._rtcout:RTC_TRACE("resetComponent()") |
229 |
local obj_ = self:findComponent(comp) |
230 |
if obj_ == nil then |
231 |
self._rtcout:RTC_ERROR("Given RTC is not participant of this EC.") |
232 |
return self._ReturnCode_t.BAD_PARAMETER |
233 |
end |
234 |
|
235 |
self._rtcout:RTC_DEBUG("Component found in the EC.") |
236 |
|
237 |
if not obj_:isCurrentState(self._LifeCycleState.ERROR_STATE) then |
238 |
self._rtcout:RTC_ERROR("State of the RTC is not ERROR_STATE.") |
239 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
240 |
end |
241 |
|
242 |
|
243 |
|
244 |
obj_:goTo(self._LifeCycleState.INACTIVE_STATE) |
245 |
rtobj.object = obj_ |
246 |
|
247 |
|
248 |
return self._ReturnCode_t.RTC_OK |
249 |
end |
250 |
|
251 |
|
252 |
|
253 |
function obj:findComponent(comp) |
254 |
for i, comp_ in ipairs(self._comps) do |
255 |
|
256 |
if comp_:isEquivalent(comp) then |
257 |
return comp_ |
258 |
end |
259 |
end |
260 |
return nil |
261 |
end |
262 |
|
263 |
|
264 |
function obj:updateComponentList() |
265 |
for k,comp in ipairs(self._addedComps) do |
266 |
table.insert(self._comps, comp) |
267 |
self._rtcout:RTC_TRACE("Component added.") |
268 |
end |
269 |
|
270 |
self._addedComps = {} |
271 |
|
272 |
|
273 |
|
274 |
for k, comp in ipairs(self._removedComps) do |
275 |
local lwrtobj_ = comp:getRTObject() |
276 |
lwrtobj_:detach_context(comp:getExecutionContextHandle()) |
277 |
|
278 |
local idx_ = StringUtil.table_index(self._comps, comp) |
279 |
|
280 |
if idx_ > 0 then |
281 |
table.remove(self._comps, idx_) |
282 |
self._rtcout:RTC_TRACE("Component deleted.") |
283 |
end |
284 |
end |
285 |
|
286 |
self._removedComps = {} |
287 |
end |
288 |
|
289 |
|
290 |
|
291 |
|
292 |
function obj:getComponentState(comp) |
293 |
self._rtcout:RTC_TRACE("getComponentState()") |
294 |
|
295 |
local rtobj_ = self:findComponent(comp) |
296 |
if rtobj_ == nil then |
297 |
self._rtcout:RTC_WARN("Given RTC is not participant of this EC.") |
298 |
return self._LifeCycleState.CREATED_STATE |
299 |
end |
300 |
|
301 |
local state_ = rtobj_:getState() |
302 |
|
303 |
self._rtcout:RTC_DEBUG("getComponentState() = "..self:getStateString(state_).." done") |
304 |
return state_ |
305 |
end |
306 |
|
307 |
|
308 |
|
309 |
|
310 |
function obj:getStateString(state) |
311 |
local st = {"CREATED_STATE", |
312 |
"INACTIVE_STATE", |
313 |
"ACTIVE_STATE", |
314 |
"ERROR_STATE"} |
315 |
|
316 |
if st[state+1] == nil then |
317 |
return "" |
318 |
else |
319 |
return st[state+1] |
320 |
end |
321 |
end |
322 |
|
323 |
|
324 |
|
325 |
function obj:isRunning() |
326 |
self._rtcout:RTC_TRACE("isRunning()") |
327 |
return self._running |
328 |
end |
329 |
|
330 |
|
331 |
function obj:addComponent(comp) |
332 |
self._rtcout:RTC_TRACE("addComponent()") |
333 |
if comp == oil.corba.idl.null then |
334 |
self._rtcout:RTC_ERROR("nil reference is given.") |
335 |
return self._ReturnCode_t.BAD_PARAMETER |
336 |
end |
337 |
local success, exception = oil.pcall( |
338 |
function() |
339 |
local ec_ = self:getECRef() |
340 |
local id_ = comp:attach_context(ec_) |
341 |
|
342 |
table.insert(self._addedComps, RTObjectStateMachine.new(id_, comp)) |
343 |
end) |
344 |
if not success then |
345 |
self._rtcout:RTC_ERROR("addComponent() failed.") |
346 |
return self._ReturnCode_t.RTC_ERROR |
347 |
end |
348 |
|
349 |
|
350 |
self._rtcout:RTC_DEBUG("addComponent() succeeded.") |
351 |
|
352 |
|
353 |
|
354 |
self:updateComponentList() |
355 |
return self._ReturnCode_t.RTC_OK |
356 |
end |
357 |
|
358 |
function obj:removeComponent(comp) |
359 |
self._rtcout:RTC_TRACE("removeComponent()") |
360 |
if comp == oil.corba.idl.null then |
361 |
self._rtcout:RTC_ERROR("nil reference is given.") |
362 |
return self._ReturnCode_t.BAD_PARAMETER |
363 |
end |
364 |
|
365 |
local rtobj_ = self:findComponent(comp) |
366 |
|
367 |
if rtobj_ == nil then |
368 |
self._rtcout:RTC_ERROR("no RTC found in this context.") |
369 |
return self._ReturnCode_t.BAD_PARAMETER |
370 |
end |
371 |
|
372 |
table.insert(self._removedComps, rtobj_) |
373 |
|
374 |
|
375 |
|
376 |
|
377 |
self:updateComponentList() |
378 |
return self._ReturnCode_t.RTC_OK |
379 |
end |
380 |
|
381 |
|
382 |
|
383 |
return obj |
384 |
end |
385 |
|
386 |
|
387 |
return ExecutionContextWorker |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
self:load(comp_id:getProperty("implementation_id"), "") |
823 |
|
824 |
factory = self._factory:find(comp_id) |
825 |
if factory == nil then |
826 |
self._rtcout:RTC_ERROR("Factory not found for loaded module: "..comp_id:getProperty("implementation_id")) |
827 |
return nil |
828 |
end |
829 |
end |
830 |
local prop = factory:profile() |
831 |
local inherit_prop = {"config.version", |
832 |
"openrtm.name", |
833 |
"openrtm.version", |
834 |
"os.name", |
835 |
"os.release", |
836 |
"os.version", |
837 |
"os.arch", |
838 |
"os.hostname", |
839 |
"corba.endpoints", |
840 |
"corba.endpoints_ipv4", |
841 |
"corba.endpoints_ipv6", |
842 |
"corba.id", |
843 |
"exec_cxt.periodic.type", |
844 |
"exec_cxt.periodic.rate", |
845 |
"exec_cxt.event_driven.type", |
846 |
"exec_cxt.sync_transition", |
847 |
"exec_cxt.sync_activation", |
848 |
"exec_cxt.sync_deactivation", |
849 |
"exec_cxt.sync_reset", |
850 |
"exec_cxt.transition_timeout", |
851 |
"exec_cxt.activation_timeout", |
852 |
"exec_cxt.deactivation_timeout", |
853 |
"exec_cxt.reset_timeout", |
854 |
"exec_cxt.cpu_affinity", |
855 |
"logger.enable", |
856 |
"logger.log_level", |
857 |
"naming.enable", |
858 |
"naming.type", |
859 |
"naming.formats", |
860 |
"sdo.service.provider.available_services", |
861 |
"sdo.service.consumer.available_services", |
862 |
"sdo.service.provider.enabled_services", |
863 |
"sdo.service.consumer.enabled_services", |
864 |
"manager.instance_name"} |
865 |
local prop_ = prop:getNode("port") |
866 |
prop_:mergeProperties(self._config:getNode("port")) |
867 |
local comp = factory:create(self) |
868 |
|
869 |
|
870 |
|
871 |
|
872 |
if comp == nil then |
873 |
self._rtcout:RTC_ERROR("createComponent: RTC creation failed: ".. |
874 |
comp_id:getProperty("implementation_id")) |
875 |
return nil |
876 |
end |
877 |
|
878 |
if self._config:getProperty("corba.endpoints_ipv4") == "" then |
879 |
self:setEndpointProperty(comp:getObjRef()) |
880 |
end |
881 |
for i, v in pairs(inherit_prop) do |
882 |
if self._config:findNode(v) then |
883 |
|
884 |
prop:setProperty(v,self._config:getProperty(v)) |
885 |
end |
886 |
end |
887 |
|
888 |
self._rtcout:RTC_TRACE("RTC Created: "..comp_id:getProperty("implementation_id")) |
889 |
self._listeners.rtclifecycle_:postCreate(comp) |
890 |
prop:mergeProperties(comp_prop) |
891 |
self._listeners.rtclifecycle_:preConfigure(prop) |
892 |
self:configureComponent(comp,prop) |
893 |
self._listeners.rtclifecycle_:postConfigure(prop) |
894 |
self._listeners.rtclifecycle_:preInitialize() |
895 |
if comp:initialize() ~= self._ReturnCode_t.RTC_OK then |
896 |
self._rtcout:RTC_TRACE("RTC initialization failed: ".. |
897 |
comp_id:getProperty("implementation_id")) |
898 |
self._rtcout:RTC_TRACE(comp_id:getProperty("implementation_id").." was finalized") |
899 |
if comp:exit() ~= self._ReturnCode_t.RTC_OK then |
900 |
self._rtcout:RTC_DEBUG(comp_id:getProperty("implementation_id").." finalization was failed.") |
901 |
end |
902 |
return nil |
903 |
end |
904 |
self._rtcout:RTC_TRACE("RTC initialization succeeded: ".. |
905 |
comp_id:getProperty("implementation_id")) |
906 |
self._listeners.rtclifecycle_:postInitialize() |
907 |
self:registerComponent(comp) |
908 |
return comp |
909 |
end |
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
function Manager:registerComponent(comp) |
917 |
self._rtcout:RTC_TRACE("Manager.registerComponent("..comp:getInstanceName()..")") |
918 |
|
919 |
|
920 |
self._compManager:registerObject(comp) |
921 |
local names = comp:getNamingNames() |
922 |
|
923 |
self._listeners.naming_:preBind(comp, names) |
924 |
|
925 |
for i, name in ipairs(names) do |
926 |
|
927 |
self._rtcout:RTC_TRACE("Bind name: "..name) |
928 |
self._namingManager:bindObject(name, comp) |
929 |
end |
930 |
self._listeners.naming_:postBind(comp, names) |
931 |
|
932 |
self:publishPorts(comp) |
933 |
self:subscribePorts(comp) |
934 |
|
935 |
return true |
936 |
end |
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
function Manager:unregisterComponent(comp) |
943 |
self._rtcout:RTC_TRACE("Manager.unregisterComponent("..comp:getInstanceName()..")") |
944 |
self._compManager:unregisterObject(comp:getInstanceName()) |
945 |
local names = comp:getNamingNames() |
946 |
|
947 |
self._listeners.naming_:preUnbind(comp, names) |
948 |
for i,name in ipairs(names) do |
949 |
self._rtcout:RTC_TRACE("Unbind name: "..name) |
950 |
self._namingManager:unbindObject(name) |
951 |
end |
952 |
self._listeners.naming_:postUnbind(comp, names) |
953 |
end |
954 |
|
955 |
|
956 |
|
957 |
|
958 |
function Manager:createContext(ec_args) |
959 |
|
960 |
end |
961 |
|
962 |
|
963 |
|
964 |
|
965 |
function Manager:deleteComponent(argv) |
966 |
if argv.instance_name ~= nil then |
967 |
local instance_name = argv.instance_name |
968 |
self._rtcout.RTC_TRACE("Manager.deleteComponent("..instance_name..")") |
969 |
local _comp = self._compManager:find(instance_name) |
970 |
if _comp ~= nil then |
971 |
self._rtcout:RTC_WARN("RTC "..instance_name.." was not found in manager.") |
972 |
return |
973 |
end |
974 |
self:deleteComponent({comp=_comp}) |
975 |
elseif argv.comp ~= nil then |
976 |
local comp = argv.comp |
977 |
self._rtcout:RTC_TRACE("Manager.deleteComponent(RTObject_impl)") |
978 |
|
979 |
self:unregisterComponent(comp) |
980 |
|
981 |
local comp_id = comp:getProperties() |
982 |
local factory = self._factory:find(comp_id) |
983 |
|
984 |
|
985 |
if factory == nil then |
986 |
self._rtcout:RTC_DEBUG("Factory not found: ".. |
987 |
comp_id:getProperty("implementation_id")) |
988 |
return |
989 |
else |
990 |
self._rtcout:RTC_DEBUG("Factory found: ".. |
991 |
comp_id:getProperty("implementation_id")) |
992 |
factory:destroy(comp) |
993 |
end |
994 |
if StringUtil.toBool(self._config:getProperty("manager.shutdown_on_nortcs"), "YES", "NO", true) then |
995 |
local comps = self:getComponents() |
996 |
|
997 |
if #comps == 0 then |
998 |
self:createShutdownThread(1) |
999 |
end |
1000 |
end |
1001 |
end |
1002 |
end |
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
function Manager:getComponent(instance_name) |
1008 |
self._rtcout:RTC_TRACE("Manager.getComponent("..instance_name..")") |
1009 |
return self._compManager:find(instance_name) |
1010 |
end |
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
function Manager:addManagerActionListener(listener,autoclean) |
1016 |
if autoclean == nil then |
1017 |
autoclean = true |
1018 |
end |
1019 |
self._listeners.manager_:addListener(listener, autoclean) |
1020 |
end |
1021 |
|
1022 |
|
1023 |
|
1024 |
function Manager:removeManagerActionListener(listener) |
1025 |
self._listeners.manager_:removeListener(listener) |
1026 |
end |
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
function Manager:addModuleActionListener(listener, autoclean) |
1032 |
if autoclean == nil then |
1033 |
autoclean = true |
1034 |
end |
1035 |
self._listeners.module_:addListener(listener, autoclean) |
1036 |
end |
1037 |
|
1038 |
|
1039 |
|
1040 |
function Manager:removeModuleActionListener(listener) |
1041 |
self._listeners.module_:removeListener(listener) |
1042 |
end |
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
function Manager:addRtcLifecycleActionListener(listener, autoclean) |
1048 |
if autoclean == nil then |
1049 |
autoclean = true |
1050 |
end |
1051 |
self._listeners.rtclifecycle_:addListener(listener, autoclean) |
1052 |
end |
1053 |
|
1054 |
|
1055 |
|
1056 |
function Manager:removeRtcLifecycleActionListener(listener) |
1057 |
self._listeners.rtclifecycle_:removeListener(listener) |
1058 |
end |
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
function Manager:addNamingActionListener(listener, autoclean) |
1064 |
if autoclean == nil then |
1065 |
autoclean = true |
1066 |
end |
1067 |
self._listeners.naming_:addListener(listener, autoclean) |
1068 |
end |
1069 |
|
1070 |
|
1071 |
|
1072 |
function Manager:removeNamingActionListener(listener) |
1073 |
self._listeners.naming_:removeListener(listener) |
1074 |
end |
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
function Manager:addLocalServiceActionListener(listener, autoclean) |
1080 |
if autoclean == nil then |
1081 |
autoclean = true |
1082 |
end |
1083 |
self._listeners.localservice_:addListener(listener, autoclean) |
1084 |
end |
1085 |
|
1086 |
|
1087 |
|
1088 |
function Manager:removeLocalServiceActionListener(listener) |
1089 |
self._listeners.localservice_:removeListener(listener) |
1090 |
end |
1091 |
|
1092 |
|
1093 |
|
1094 |
function Manager:getORB() |
1095 |
|
1096 |
|
1097 |
self._rtcout:RTC_TRACE("Manager.getORB()") |
1098 |
|
1099 |
return self._orb |
1100 |
end |
1101 |
|
1102 |
|
1103 |
|
1104 |
function Manager:initManager(argv) |
1105 |
local config = ManagerConfig.new(argv) |
1106 |
self._config = Properties.new() |
1107 |
config:configure(self._config) |
1108 |
self._config:setProperty("logger.file_name",self:formatString(self._config:getProperty("logger.file_name"), |
1109 |
self._config)) |
1110 |
self._module = ModuleManager.new(self._config) |
1111 |
|
1112 |
|
1113 |
end |
1114 |
|
1115 |
function Manager:shutdownManagerServant() |
1116 |
if self._mgrservant ~= nil then |
1117 |
self._mgrservant:exit() |
1118 |
self._mgrservant = nil |
1119 |
end |
1120 |
end |
1121 |
|
1122 |
|
1123 |
function Manager:shutdownManager() |
1124 |
|
1125 |
end |
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
function Manager:initLogstreamFile() |
1132 |
local logprop = self._config:getNode("logger") |
1133 |
local logstream = LogstreamFactory:instance():createObject("file") |
1134 |
if logstream == nil then |
1135 |
return |
1136 |
end |
1137 |
if not logstream:init(logprop) then |
1138 |
logstream = LogstreamFactory:instance():deleteObject(logstream) |
1139 |
end |
1140 |
self._rtcout:addLogger(logstream) |
1141 |
end |
1142 |
|
1143 |
|
1144 |
function Manager:initLogstreamPlugins() |
1145 |
|
1146 |
end |
1147 |
|
1148 |
|
1149 |
function Manager:initLogstreamOthers() |
1150 |
local factory = LogstreamFactory:instance() |
1151 |
local pp = self._config:getNode("logger.logstream") |
1152 |
|
1153 |
local leaf0 = pp:getLeaf() |
1154 |
|
1155 |
for k,l in pairs(leaf0) do |
1156 |
local lstype = l:getName() |
1157 |
local logstream = factory:createObject(lstype) |
1158 |
if logstream == nil then |
1159 |
self._rtcout:RTC_WARN("Logstream "..lstype.." creation failed.") |
1160 |
else |
1161 |
self._rtcout:RTC_INFO("Logstream "..lstype.." created.") |
1162 |
if not logstream:init(l) then |
1163 |
self._rtcout:RTC_WARN("Logstream "..lstype.." init failed.") |
1164 |
factory:deleteObject(logstream) |
1165 |
self._rtcout:RTC_WARN("Logstream "..lstype.." deleted.") |
1166 |
else |
1167 |
self._rtcout:RTC_INFO("Logstream "..lstype.." added.") |
1168 |
self._rtcout:addLogger(logstream) |
1169 |
end |
1170 |
end |
1171 |
end |
1172 |
end |
1173 |
|
1174 |
|
1175 |
|
1176 |
function Manager:initLogger() |
1177 |
self._rtcout = self:getLogbuf() |
1178 |
|
1179 |
if not StringUtil.toBool(self._config:getProperty("logger.enable"), "YES", "NO", true) then |
1180 |
return true |
1181 |
end |
1182 |
|
1183 |
self:initLogstreamFile() |
1184 |
self:initLogstreamPlugins() |
1185 |
self:initLogstreamOthers() |
1186 |
|
1187 |
self._rtcout:setLogLevel(self._config:getProperty("logger.log_level")) |
1188 |
self._rtcout:setLogLock(StringUtil.toBool(self._config:getProperty("logger.stream_lock"), |
1189 |
"enable", "disable", false)) |
1190 |
self._rtcout:RTC_INFO(self._config:getProperty("openrtm.version")) |
1191 |
self._rtcout:RTC_INFO("Copyright (C) 2018") |
1192 |
self._rtcout:RTC_INFO(" Nobuhiko Miyamoto") |
1193 |
self._rtcout:RTC_INFO(" Tokyo Metropolitan University") |
1194 |
self._rtcout:RTC_INFO("Manager starting.") |
1195 |
self._rtcout:RTC_INFO("Starting local logging.") |
1196 |
|
1197 |
return true |
1198 |
end |
1199 |
|
1200 |
|
1201 |
function Manager:shutdownLogger() |
1202 |
|
1203 |
end |
1204 |
|
1205 |
|
1206 |
function Manager:initORB() |
1207 |
|
1208 |
if ORB_Dummy_ENABLE then |
1209 |
self._orb = ORB_Dummy |
1210 |
else |
1211 |
local endpoints = self:createORBEndpoints() |
1212 |
local port = nil |
1213 |
local host = nil |
1214 |
|
1215 |
|
1216 |
if #endpoints > 0 then |
1217 |
local endpoint = endpoints[1] |
1218 |
local tmp = StringUtil.split(endpoint, ":") |
1219 |
host = tmp[1] |
1220 |
port = tmp[2] |
1221 |
end |
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
if oil.VERSION == "OiL 0.6" then |
1227 |
if StringUtil.toBool(self._config:getProperty("corba.ssl.enable"), "YES", "NO", false) then |
1228 |
local key_file = self._config:getProperty("corba.ssl.key_file") |
1229 |
local ca_file = self._config:getProperty("corba.ssl.certificate_authority_file") |
1230 |
|
1231 |
|
1232 |
self._orb = oil.init{ |
1233 |
flavor = "cooperative;corba;corba.ssl;kernel.ssl", |
1234 |
host=host, |
1235 |
port=port, |
1236 |
options = { |
1237 |
client = { |
1238 |
security = "required", |
1239 |
ssl = { |
1240 |
key = key_file, |
1241 |
certificate = ca_file |
1242 |
}, |
1243 |
}, |
1244 |
}, |
1245 |
} |
1246 |
else |
1247 |
self._orb = oil.init{ flavor = "cooperative;corba;", host=host, port=port } |
1248 |
end |
1249 |
|
1250 |
else |
1251 |
self._orb = oil.init{ flavor = "cooperative;corba;intercepted;typed;base;", host=host, port=port } |
1252 |
end |
1253 |
|
1254 |
if oil.VERSION == "OiL 0.5" then |
1255 |
oil.corba.idl.null = nil |
1256 |
elseif oil.VERSION == "OiL 0.6" then |
1257 |
oil.corba = {} |
1258 |
oil.corba.idl = {} |
1259 |
oil.corba.idl.null = nil |
1260 |
|
1261 |
|
1262 |
self._orb.tostring = function(self, str) |
1263 |
return tostring(str) |
1264 |
end |
1265 |
end |
1266 |
|
1267 |
self._orb:loadidlfile(Manager:findIdLFile("CosNaming.idl")) |
1268 |
self._orb:loadidlfile(Manager:findIdLFile("RTC.idl")) |
1269 |
self._orb:loadidlfile(Manager:findIdLFile("OpenRTM.idl")) |
1270 |
self._orb:loadidlfile(Manager:findIdLFile("DataPort.idl")) |
1271 |
self._orb:loadidlfile(Manager:findIdLFile("Manager.idl")) |
1272 |
self._orb:loadidlfile(Manager:findIdLFile("InterfaceDataTypes.idl")) |
1273 |
end |
1274 |
self._ReturnCode_t = self._orb.types:lookup("::RTC::ReturnCode_t").labelvalue |
1275 |
|
1276 |
end |
1277 |
|
1278 |
|
1279 |
function Manager:loadIdLFile(name) |
1280 |
self._orb:loadidlfile(name) |
1281 |
end |
1282 |
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 |
function Manager:findIdLFile(name) |
1288 |
local fpath = StringUtil.dirname(ManagerInfo.getfilepath()) |
1289 |
|
1290 |
|
1291 |
|
1292 |
local _str = string.gsub(fpath,"\\","/").."../idl/"..name |
1293 |
|
1294 |
return _str |
1295 |
end |
1296 |
|
1297 |
|
1298 |
|
1299 |
function Manager:createORBOptions() |
1300 |
|
1301 |
end |
1302 |
|
1303 |
|
1304 |
|
1305 |
function Manager:createORBEndpoints() |
1306 |
local endpoints = {} |
1307 |
local prop = self._config:getProperty("corba.endpoints") |
1308 |
|
1309 |
|
1310 |
if StringUtil.toBool(self._config:getProperty("manager.is_master"), "YES", "NO", false) then |
1311 |
local mm = self._config:getProperty("corba.master_manager", ":2810") |
1312 |
local mmm = StringUtil.split(mm, ":") |
1313 |
local master = "" |
1314 |
if #mmm == 2 then |
1315 |
master = ":"..mmm[2] |
1316 |
else |
1317 |
master = ":2810" |
1318 |
end |
1319 |
table.insert(endpoints, master) |
1320 |
elseif prop == "" then |
1321 |
return endpoints |
1322 |
end |
1323 |
|
1324 |
local strs = StringUtil.split(prop, ",") |
1325 |
for k,v in ipairs(strs) do |
1326 |
table.insert(endpoints, v) |
1327 |
end |
1328 |
return endpoints |
1329 |
end |
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
function Manager:createORBEndpointOption(opt, endpoints) |
1335 |
|
1336 |
end |
1337 |
|
1338 |
|
1339 |
function Manager:shutdownORB() |
1340 |
self._orb:shutdown() |
1341 |
self._orb = nil |
1342 |
end |
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
function Manager:initNaming() |
1350 |
self._rtcout:RTC_TRACE("Manager.initNaming()") |
1351 |
self._namingManager = NamingManager.new(self) |
1352 |
|
1353 |
if not StringUtil.toBool(self._config:getProperty("naming.enable"), "YES", "NO", true) then |
1354 |
return true |
1355 |
end |
1356 |
local meths = StringUtil.split(self._config:getProperty("naming.type"),",") |
1357 |
meths = StringUtil.strip(meths) |
1358 |
|
1359 |
|
1360 |
for i, meth in ipairs(meths) do |
1361 |
|
1362 |
local names = StringUtil.split(self._config:getProperty(meth..".nameservers"), ",") |
1363 |
for j, name in ipairs(names) do |
1364 |
|
1365 |
self._rtcout:RTC_TRACE("Register Naming Server: "..meth.."/"..name) |
1366 |
self._namingManager:registerNameServer(meth,name) |
1367 |
end |
1368 |
end |
1369 |
if StringUtil.toBool(self._config:getProperty("naming.update.enable"), "YES", "NO", true) then |
1370 |
end |
1371 |
return true |
1372 |
end |
1373 |
|
1374 |
|
1375 |
function Manager:shutdownNaming() |
1376 |
|
1377 |
end |
1378 |
|
1379 |
|
1380 |
|
1381 |
function Manager:initExecContext() |
1382 |
self._rtcout:RTC_TRACE("Manager.initExecContext()") |
1383 |
PeriodicExecutionContext.Init(self) |
1384 |
OpenHRPExecutionContext.Init(self) |
1385 |
SimulatorExecutionContext.Init(self) |
1386 |
|
1387 |
return true |
1388 |
end |
1389 |
|
1390 |
|
1391 |
|
1392 |
function Manager:initComposite() |
1393 |
self._rtcout:RTC_TRACE("Manager.initComposite()") |
1394 |
PeriodicECSharedComposite.Init(self) |
1395 |
return true |
1396 |
end |
1397 |
|
1398 |
|
1399 |
|
1400 |
function Manager:initFactories() |
1401 |
FactoryInit() |
1402 |
return true |
1403 |
end |
1404 |
|
1405 |
|
1406 |
|
1407 |
function Manager:initTimer() |
1408 |
return true |
1409 |
end |
1410 |
function Manager:endpointPropertySwitch() |
1411 |
|
1412 |
end |
1413 |
|
1414 |
|
1415 |
|
1416 |
function Manager:setEndpointProperty() |
1417 |
local ret = {} |
1418 |
return ret |
1419 |
end |
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
function Manager:initManagerServant() |
1426 |
self._rtcout:RTC_TRACE("Manager.initManagerServant()") |
1427 |
if not StringUtil.toBool( |
1428 |
self._config:getProperty("manager.corba_servant"), "YES","NO",true) then |
1429 |
return true |
1430 |
end |
1431 |
|
1432 |
self._mgrservant = ManagerServant.new() |
1433 |
|
1434 |
if self._config:getProperty("corba.endpoints_ipv4") == "" then |
1435 |
self:setEndpointProperty(self._mgrservant:getObjRef()) |
1436 |
end |
1437 |
local prop = self._config:getNode("manager") |
1438 |
local names = StringUtil.split(prop:getProperty("naming_formats"),",") |
1439 |
|
1440 |
if StringUtil.toBool(prop:getProperty("is_master"), |
1441 |
"YES","NO",true) then |
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
end |
1447 |
if StringUtil.toBool(self._config:getProperty("corba.update_master_manager.enable"), |
1448 |
"YES", "NO", true) and |
1449 |
not StringUtil.toBool(self._config:getProperty("manager.is_master"), |
1450 |
"YES", "NO", false) then |
1451 |
end |
1452 |
|
1453 |
local otherref = nil |
1454 |
|
1455 |
local success, exception = oil.pcall( |
1456 |
function() |
1457 |
end) |
1458 |
if not success then |
1459 |
end |
1460 |
|
1461 |
return true |
1462 |
end |
1463 |
|
1464 |
|
1465 |
|
1466 |
function Manager:initLocalService() |
1467 |
return true |
1468 |
end |
1469 |
|
1470 |
|
1471 |
function Manager:shutdownComponents() |
1472 |
self._rtcout:RTC_TRACE("Manager.shutdownComponents()") |
1473 |
local comps = self._namingManager:getObjects() |
1474 |
for k,comp in ipairs(comps) do |
1475 |
local success, exception = oil.pcall( |
1476 |
function() |
1477 |
comp:exit() |
1478 |
local p = Properties.new({key=comp:getInstanceName()}) |
1479 |
p:mergeProperties(comp:getProperties()) |
1480 |
end) |
1481 |
if not success then |
1482 |
|
1483 |
self._rtcout:RTC_TRACE(exception) |
1484 |
end |
1485 |
end |
1486 |
|
1487 |
|
1488 |
for k,ec in ipairs(self._ecs) do |
1489 |
local success, exception = oil.pcall( |
1490 |
function() |
1491 |
self._orb:deactivate(ec._svr) |
1492 |
end) |
1493 |
if not success then |
1494 |
self._rtcout:RTC_TRACE(exception) |
1495 |
end |
1496 |
end |
1497 |
end |
1498 |
|
1499 |
|
1500 |
|
1501 |
function Manager:cleanupComponent(comp) |
1502 |
|
1503 |
end |
1504 |
|
1505 |
|
1506 |
|
1507 |
function Manager:cleanupComponents() |
1508 |
self._rtcout:RTC_VERBOSE("Manager.cleanupComponents()") |
1509 |
|
1510 |
self._rtcout:RTC_VERBOSE(#self._finalized.comps.." components are marked as finalized.") |
1511 |
for i, _comp in ipairs(self._finalized.comps) do |
1512 |
self:deleteComponent({comp=_comp}) |
1513 |
end |
1514 |
|
1515 |
self._finalized.comps = {} |
1516 |
end |
1517 |
|
1518 |
|
1519 |
|
1520 |
function Manager:notifyFinalized(_comp) |
1521 |
self._rtcout:RTC_TRACE("Manager.notifyFinalized()") |
1522 |
|
1523 |
|
1524 |
self:deleteComponent({comp=_comp}) |
1525 |
end |
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
function Manager:procComponentArgs(comp_arg, comp_id, comp_conf) |
1540 |
local id_and_conf_str = StringUtil.split(comp_arg, "?") |
1541 |
local id_and_conf = {} |
1542 |
for k, v in pairs(id_and_conf_str) do |
1543 |
v = StringUtil.eraseHeadBlank(v) |
1544 |
v = StringUtil.eraseTailBlank(v) |
1545 |
table.insert(id_and_conf, v) |
1546 |
end |
1547 |
|
1548 |
if #id_and_conf ~= 1 and #id_and_conf ~= 2 then |
1549 |
self._rtcout:RTC_ERROR("Invalid arguments. Two or more '?'") |
1550 |
return false |
1551 |
end |
1552 |
local prof = CompParam.prof_list |
1553 |
local param_num = #prof |
1554 |
|
1555 |
if id_and_conf[1]:find(":") == nil then |
1556 |
id_and_conf[1] = prof[1]..":::"..id_and_conf[1].."::" |
1557 |
end |
1558 |
|
1559 |
|
1560 |
local id_str = StringUtil.split(id_and_conf[1], ":") |
1561 |
local id = {} |
1562 |
|
1563 |
for k, v in pairs(id_str) do |
1564 |
v = StringUtil.eraseHeadBlank(v) |
1565 |
v = StringUtil.eraseTailBlank(v) |
1566 |
table.insert(id, v) |
1567 |
end |
1568 |
if #id ~= param_num then |
1569 |
self._rtcout:RTC_ERROR("Invalid RTC id format.") |
1570 |
return false |
1571 |
end |
1572 |
|
1573 |
if id[1] ~= prof[1] then |
1574 |
self._rtcout:RTC_ERROR("Invalid id type.") |
1575 |
return false |
1576 |
end |
1577 |
|
1578 |
for i = 2,param_num do |
1579 |
|
1580 |
comp_id:setProperty(prof[i], id[i]) |
1581 |
|
1582 |
self._rtcout:RTC_TRACE("RTC basic profile "..prof[i]..": "..id[i]) |
1583 |
end |
1584 |
|
1585 |
if #id_and_conf == 2 then |
1586 |
local conf_str = StringUtil.split(id_and_conf[2], "&") |
1587 |
local conf = {} |
1588 |
for k, v in pairs(conf_str) do |
1589 |
v = StringUtil.eraseHeadBlank(v) |
1590 |
v = StringUtil.eraseTailBlank(v) |
1591 |
table.insert(conf, v) |
1592 |
end |
1593 |
for i = 1,#conf do |
1594 |
local keyval_str = StringUtil.split(conf[i], "=") |
1595 |
local keyval = {} |
1596 |
for k, v in pairs(keyval_str) do |
1597 |
v = StringUtil.eraseHeadBlank(v) |
1598 |
v = StringUtil.eraseTailBlank(v) |
1599 |
table.insert(keyval, v) |
1600 |
end |
1601 |
if #keyval > 1 then |
1602 |
comp_conf:setProperty(keyval[1],keyval[2]) |
1603 |
self._rtcout:RTC_TRACE("RTC property "..keyval[1]..": "..keyval[2]) |
1604 |
end |
1605 |
end |
1606 |
end |
1607 |
|
1608 |
|
1609 |
return true |
1610 |
end |
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
function Manager:procContextArgs(ec_args, ec_id, ec_conf) |
1618 |
return true |
1619 |
end |
1620 |
|
1621 |
|
1622 |
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
function Manager:configureComponent(comp, prop) |
1628 |
local category = comp:getCategory() |
1629 |
local type_name = comp:getTypeName() |
1630 |
local inst_name = comp:getInstanceName() |
1631 |
local type_conf = category.."."..type_name..".config_file" |
1632 |
local name_conf = category.."."..inst_name..".config_file" |
1633 |
local type_prop = Properties.new() |
1634 |
local name_prop = Properties.new() |
1635 |
local config_fname = {} |
1636 |
if self._config:getProperty(name_conf) ~= "" then |
1637 |
local conff = io.open(self._config:getProperty(name_conf), "r") |
1638 |
if conff ~= nil then |
1639 |
name_prop:load(conff) |
1640 |
self._rtcout:RTC_INFO("Component instance conf file: %s loaded.", |
1641 |
self._config:getProperty(name_conf)) |
1642 |
self._rtcout:RTC_DEBUG(name_prop) |
1643 |
table.insert(config_fname, self._config:getProperty(name_conf)) |
1644 |
else |
1645 |
print("Not found. : "..self._config:getProperty(name_conf)) |
1646 |
end |
1647 |
end |
1648 |
|
1649 |
if self._config:findNode(category.."."..inst_name) ~= nil then |
1650 |
local temp_ = Properties.new({prop=self._config:getNode(category.."."..inst_name)}) |
1651 |
local keys_ = temp_:propertyNames() |
1652 |
|
1653 |
if not (#keys_ == 1 and keys_[#keys_] == "config_file") then |
1654 |
name_prop:mergeProperties(self._config:getNode(category.."."..inst_name)) |
1655 |
self._rtcout:RTC_INFO("Component name conf exists in rtc.conf. Merged.") |
1656 |
self._rtcout:RTC_INFO(name_prop) |
1657 |
if self._config:findNode("config_file") ~= nil then |
1658 |
table.insert(config_fname, self._config:getProperty("config_file")) |
1659 |
end |
1660 |
end |
1661 |
|
1662 |
end |
1663 |
|
1664 |
if self._config:getProperty(type_conf) ~= "" then |
1665 |
local conff = io.open(self._config:getProperty(type_conf), "r") |
1666 |
if conff ~= nil then |
1667 |
type_prop:load(conff) |
1668 |
self._rtcout:RTC_INFO("Component instance conf file: %s loaded.", |
1669 |
self._config:getProperty(type_conf)) |
1670 |
self._rtcout:RTC_DEBUG(type_prop) |
1671 |
table.insert(config_fname, self._config:getProperty(type_conf)) |
1672 |
else |
1673 |
print("Not found. : "..self._config:getProperty(type_conf)) |
1674 |
end |
1675 |
end |
1676 |
|
1677 |
if self._config:findNode(category.."."..type_name) ~= nil then |
1678 |
local temp_ = Properties.new({prop=self._config:getNode(category.."."..type_name)}) |
1679 |
local keys_ = temp_:propertyNames() |
1680 |
if not (#keys_ == 1 and keys_[#keys_] == "config_file") then |
1681 |
type_prop:mergeProperties(self._config:getNode(category.."."..type_name)) |
1682 |
self._rtcout:RTC_INFO("Component name conf exists in rtc.conf. Merged.") |
1683 |
self._rtcout:RTC_INFO(type_prop) |
1684 |
if self._config:findNode("config_file") ~= nil then |
1685 |
table.insert(config_fname, self._config:getProperty("config_file")) |
1686 |
end |
1687 |
end |
1688 |
end |
1689 |
comp:setProperties(prop) |
1690 |
type_prop:mergeProperties(name_prop) |
1691 |
type_prop:setProperty("config_file",StringUtil.flatten(StringUtil.unique_sv(config_fname))) |
1692 |
comp:setProperties(type_prop) |
1693 |
local comp_prop = Properties.new({prop=comp:getProperties()}) |
1694 |
local naming_formats = self._config:getProperty("naming.formats") |
1695 |
if comp_prop:findNode("naming.formats") then |
1696 |
naming_formats = comp_prop:getProperty("naming.formats") |
1697 |
end |
1698 |
naming_formats = StringUtil.flatten(StringUtil.unique_sv(StringUtil.split(naming_formats, ","))) |
1699 |
|
1700 |
local naming_names = self:formatString(naming_formats, comp:getProperties()) |
1701 |
|
1702 |
comp:getProperties():setProperty("naming.formats",naming_formats) |
1703 |
comp:getProperties():setProperty("naming.names",naming_names) |
1704 |
|
1705 |
end |
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
function Manager:mergeProperty(prop, file_name) |
1712 |
return true |
1713 |
end |
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
function Manager:formatString(naming_format, prop) |
1730 |
local name_ = naming_format |
1731 |
local str_ = "" |
1732 |
local count = 0 |
1733 |
local len_ = #name_ |
1734 |
local num = 0 |
1735 |
|
1736 |
|
1737 |
local flag = true |
1738 |
while(flag) do |
1739 |
num = num + 1 |
1740 |
local n = string.sub(name_,num,num) |
1741 |
|
1742 |
if n == "" then |
1743 |
break |
1744 |
end |
1745 |
|
1746 |
if n == '%' then |
1747 |
count = count + 1 |
1748 |
if count % 2 == 0 then |
1749 |
str_ = str_..n |
1750 |
end |
1751 |
elseif n == '$' then |
1752 |
count = 0 |
1753 |
num = num + 1 |
1754 |
n = string.sub(name_,num,num) |
1755 |
if n == "" then |
1756 |
break |
1757 |
end |
1758 |
if n == '{' or n == '(' then |
1759 |
num = num + 1 |
1760 |
n = string.sub(name_,num,num) |
1761 |
local env = "" |
1762 |
local start = num+1 |
1763 |
while(true) do |
1764 |
if n == '}' or n == ')' then |
1765 |
break |
1766 |
elseif n == "" then |
1767 |
break |
1768 |
end |
1769 |
env = env..n |
1770 |
num = num + 1 |
1771 |
n = string.sub(name_,num,num) |
1772 |
end |
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 |
end |
1778 |
else |
1779 |
if count > 0 and count % 2 == 1 then |
1780 |
count = 0 |
1781 |
if n == "n" then str_ = str_..prop:getProperty("instance_name") |
1782 |
elseif n == "t" then str_ = str_..prop:getProperty("type_name") |
1783 |
elseif n == "m" then str_ = str_..prop:getProperty("type_name") |
1784 |
elseif n == "v" then str_ = str_..prop:getProperty("version") |
1785 |
elseif n == "V" then str_ = str_..prop:getProperty("vendor") |
1786 |
elseif n == "c" then str_ = str_..prop:getProperty("category") |
1787 |
elseif n == "h" then str_ = str_..self._config:getProperty("os.hostname") |
1788 |
elseif n == "M" then str_ = str_..self._config:getProperty("manager.name") |
1789 |
elseif n == "p" then str_ = str_..self._config:getProperty("manager.pid") |
1790 |
else str_ = str_..n end |
1791 |
else |
1792 |
count = 0 |
1793 |
str_ = str_..n |
1794 |
end |
1795 |
end |
1796 |
end |
1797 |
return str_ |
1798 |
|
1799 |
|
1800 |
end |
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
function Manager:getLogbuf(name) |
1806 |
if name == nil then |
1807 |
name = "Manager" |
1808 |
end |
1809 |
if not StringUtil.toBool(self._config:getProperty("logger.enable"), "YES", "NO", true) then |
1810 |
|
1811 |
return LogStream.new():getLogger(name) |
1812 |
end |
1813 |
if self._rtcout == nil then |
1814 |
self._rtcout = LogStream.new(name) |
1815 |
|
1816 |
self._rtcout:setLogLevel(self._config:getProperty("logger.log_level")) |
1817 |
return self._rtcout:getLogger(name) |
1818 |
else |
1819 |
return self._rtcout:getLogger(name) |
1820 |
end |
1821 |
end |
1822 |
|
1823 |
|
1824 |
|
1825 |
function Manager:getConfig() |
1826 |
return self._config |
1827 |
end |
1828 |
|
1829 |
|
1830 |
|
1831 |
function Manager:try_direct_load(file_name) |
1832 |
|
1833 |
end |
1834 |
|
1835 |
|
1836 |
|
1837 |
function Manager:publishPorts(comp) |
1838 |
|
1839 |
end |
1840 |
|
1841 |
|
1842 |
|
1843 |
function Manager:subscribePorts(comp) |
1844 |
|
1845 |
end |
1846 |
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 |
function Manager:getPortsOnNameServers(nsname, kind) |
1852 |
local ret = {} |
1853 |
return ret |
1854 |
end |
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 |
function Manager:connectDataPorts(port, target_ports) |
1860 |
|
1861 |
end |
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
function Manager:connectServicePorts(port, target_ports) |
1867 |
|
1868 |
end |
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
function Manager:initPreConnection() |
1874 |
self._rtcout:RTC_TRACE("Connection pre-creation: "..tostring(self._config:getProperty("manager.components.preconnect"))) |
1875 |
local connectors = StringUtil.split(tostring(self._config:getProperty("manager.components.preconnect")), ",") |
1876 |
|
1877 |
for k,c in ipairs(connectors) do |
1878 |
c = StringUtil.eraseBothEndsBlank(c) |
1879 |
|
1880 |
if c == "" then |
1881 |
else |
1882 |
local port0_str = StringUtil.split(c,"?")[1] |
1883 |
local param = StringUtil.urlparam2map(c) |
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
local ports = {} |
1890 |
local configs = {} |
1891 |
for k,p in pairs(param) do |
1892 |
if k == "port" then |
1893 |
table.insert(ports,p) |
1894 |
else |
1895 |
local pos = string.find(k,"port") |
1896 |
local tmp = string.gsub(k,"port","") |
1897 |
|
1898 |
local ret, v = StringUtil.stringTo(0, tmp) |
1899 |
|
1900 |
if ret and pos ~= nil then |
1901 |
table.insert(ports, p) |
1902 |
else |
1903 |
configs[k] = p |
1904 |
end |
1905 |
end |
1906 |
end |
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
if configs["dataflow_type"] == nil then |
1914 |
configs["dataflow_type"] = "push" |
1915 |
end |
1916 |
if configs["interface_type"] == nil then |
1917 |
configs["interface_type"] = "data_service" |
1918 |
end |
1919 |
local tmp = StringUtil.split(port0_str,"%.") |
1920 |
tmp[#tmp] = nil |
1921 |
|
1922 |
local comp0_name = StringUtil.flatten(tmp,"%.") |
1923 |
|
1924 |
local port0_name = port0_str |
1925 |
local comp0_ref = nil |
1926 |
|
1927 |
if string.find(comp0_name, "://") == nil then |
1928 |
|
1929 |
local comp0 = self:getComponent(comp0_name) |
1930 |
|
1931 |
if comp0 == nil then |
1932 |
self._rtcout:RTC_ERROR(comp0_name.." not found.") |
1933 |
else |
1934 |
comp0_ref = comp0:getObjRef() |
1935 |
end |
1936 |
else |
1937 |
local rtcs = self._namingManager:string_to_component(comp0_name) |
1938 |
|
1939 |
if #rtcs == 0 then |
1940 |
self._rtcout:RTC_ERROR(comp0_name.." not found.") |
1941 |
else |
1942 |
comp0_ref = rtcs[1] |
1943 |
port0_name = StringUtil.split(port0_str, "/") |
1944 |
port0_name = port0_name[#port0_name] |
1945 |
end |
1946 |
end |
1947 |
|
1948 |
local port0_var = CORBA_RTCUtil.get_port_by_name(comp0_ref, port0_name) |
1949 |
|
1950 |
|
1951 |
if port0_var == oil.corba.idl.null then |
1952 |
self._rtcout:RTC_DEBUG("port "..port0_str.." found: ") |
1953 |
else |
1954 |
if #ports == 0 then |
1955 |
local prop = Properties.new() |
1956 |
|
1957 |
for k,v in pairs(configs) do |
1958 |
k = StringUtil.eraseBothEndsBlank(k) |
1959 |
v = StringUtil.eraseBothEndsBlank(v) |
1960 |
prop:setProperty("dataport."..k,v) |
1961 |
end |
1962 |
if self._ReturnCode_t.RTC_OK ~= CORBA_RTCUtil.connect(c, prop, port0_var, oil.corba.idl.null) then |
1963 |
self._rtcout.RTC_ERROR("Connection error: "..c) |
1964 |
end |
1965 |
end |
1966 |
for k,port_str in ipairs(ports) do |
1967 |
|
1968 |
local tmp = StringUtil.split(port_str, "%.") |
1969 |
tmp[#tmp] = nil |
1970 |
local comp_name = StringUtil.flatten(tmp,"%.") |
1971 |
local port_name = port_str |
1972 |
|
1973 |
local comp_ref = nil |
1974 |
|
1975 |
if string.find(comp_name, "://") == nil then |
1976 |
|
1977 |
local comp = self:getComponent(comp_name) |
1978 |
if comp == nil then |
1979 |
self._rtcout:RTC_ERROR(comp_name.." not found.") |
1980 |
else |
1981 |
comp_ref = comp:getObjRef() |
1982 |
end |
1983 |
else |
1984 |
local rtcs = self._namingManager:string_to_component(comp_name) |
1985 |
|
1986 |
if #rtcs == 0 then |
1987 |
self._rtcout:RTC_ERROR(comp_name.." not found.") |
1988 |
else |
1989 |
comp_ref = rtcs[1] |
1990 |
port_name = StringUtil.split(port_str, "/") |
1991 |
port_name = port_name[#port_name] |
1992 |
end |
1993 |
end |
1994 |
|
1995 |
if comp_ref ~= nil then |
1996 |
port_var = CORBA_RTCUtil.get_port_by_name(comp_ref, port_name) |
1997 |
|
1998 |
|
1999 |
if port_var == oil.corba.idl.null then |
2000 |
self._rtcout:RTC_DEBUG("port "..port_str.." found: ") |
2001 |
else |
2002 |
local prop = Properties.new() |
2003 |
|
2004 |
for k,v in pairs(configs) do |
2005 |
k = StringUtil.eraseBothEndsBlank(k) |
2006 |
v = StringUtil.eraseBothEndsBlank(v) |
2007 |
prop:setProperty("dataport."..k,v) |
2008 |
end |
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 |
|
2014 |
if self._ReturnCode_t.RTC_OK ~= CORBA_RTCUtil.connect(c, prop, port0_var, port_var) then |
2015 |
self._rtcout.RTC_ERROR("Connection error: "..c) |
2016 |
end |
2017 |
|
2018 |
end |
2019 |
end |
2020 |
end |
2021 |
end |
2022 |
end |
2023 |
end |
2024 |
end |
2025 |
|
2026 |
|
2027 |
|
2028 |
|
2029 |
function Manager:initPreActivation() |
2030 |
self._rtcout:RTC_TRACE("Components pre-activation: "..tostring(self._config:getProperty("manager.components.preactivation"))) |
2031 |
local comps = StringUtil.split(tostring(self._config:getProperty("manager.components.preactivation")), ",") |
2032 |
for k,c in pairs(comps) do |
2033 |
local c = StringUtil.eraseBothEndsBlank(c) |
2034 |
|
2035 |
if c ~= "" then |
2036 |
local comp_ref = nil |
2037 |
if string.find(c, "://") == nil then |
2038 |
local comp = self:getComponent(c) |
2039 |
if comp == nil then |
2040 |
self._rtcout:RTC_ERROR(c.." not found.") |
2041 |
else |
2042 |
comp_ref = comp:getObjRef() |
2043 |
end |
2044 |
else |
2045 |
local rtcs = self._namingManager:string_to_component(c) |
2046 |
if #rtcs == 0 then |
2047 |
self._rtcout:RTC_ERROR(c.." not found.") |
2048 |
else |
2049 |
comp_ref = rtcs[1] |
2050 |
end |
2051 |
end |
2052 |
if comp_ref ~= nil then |
2053 |
local ret = CORBA_RTCUtil.activate(comp_ref) |
2054 |
if ret ~= self._ReturnCode_t.RTC_OK then |
2055 |
self._rtcout:RTC_ERROR(c.." activation failed.") |
2056 |
else |
2057 |
self._rtcout:RTC_INFO(c.." activated.") |
2058 |
end |
2059 |
end |
2060 |
end |
2061 |
end |
2062 |
end |
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 |
function Manager:initPreCreation() |
2068 |
local comps = StringUtil.strip(StringUtil.split(self._config:getProperty("manager.components.precreate"), ",")) |
2069 |
for k,comp in ipairs(comps) do |
2070 |
if comp == nil or comp == "" then |
2071 |
else |
2072 |
self:createComponent(comp) |
2073 |
end |
2074 |
end |
2075 |
end |
2076 |
|
2077 |
|
2078 |
|
2079 |
function Manager:getManagerServant() |
2080 |
self._rtcout:RTC_TRACE("Manager.getManagerServant()") |
2081 |
return self._mgrservant |
2082 |
end |
2083 |
|
2084 |
|
2085 |
|
2086 |
function Manager:getComponents() |
2087 |
self._rtcout:RTC_TRACE("Manager.getComponents()") |
2088 |
return self._compManager:getObjects() |
2089 |
end |
2090 |
|
2091 |
|
2092 |
|
2093 |
function Manager:getNaming() |
2094 |
self._rtcout:RTC_TRACE("Manager.getNaming()") |
2095 |
return self._namingManager |
2096 |
end |
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
function Manager:load(fname, initfunc) |
2103 |
self._rtcout:RTC_TRACE("Manager.load(fname = "..fname..", initfunc = "..initfunc..")") |
2104 |
fname = string.gsub(fname, "\\", "./") |
2105 |
self._listeners.module_:preLoad(fname, initfunc) |
2106 |
local success, exception = oil.pcall( |
2107 |
function() |
2108 |
if initfunc == "" then |
2109 |
initfunc = "Init" |
2110 |
end |
2111 |
|
2112 |
local path = self._module:load(fname, initfunc) |
2113 |
self._rtcout:RTC_DEBUG("module path: "..path) |
2114 |
self._listeners.module_:postLoad(path, initfunc) |
2115 |
end) |
2116 |
if not success then |
2117 |
|
2118 |
|
2119 |
|
2120 |
if exception.type == "NotAllowedOperation" then |
2121 |
self._rtcout:RTC_ERROR("Operation not allowed: "..exception.reason) |
2122 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
2123 |
elseif exception.type == "NotFound" then |
2124 |
self._rtcout:RTC_ERROR("Not found: "..fname) |
2125 |
return self._ReturnCode_t.RTC_ERROR |
2126 |
elseif exception.type == "FileNotFound" then |
2127 |
self._rtcout:RTC_ERROR("Not found: "..fname) |
2128 |
return self._ReturnCode_t.RTC_ERROR |
2129 |
elseif exception.type == "InvalidArguments" then |
2130 |
self._rtcout:RTC_ERROR("Invalid argument: "..exception.reason) |
2131 |
return self._ReturnCode_t.BAD_PARAMETER |
2132 |
else |
2133 |
self._rtcout:RTC_ERROR("Unknown error.") |
2134 |
return self._ReturnCode_t.RTC_ERROR |
2135 |
end |
2136 |
end |
2137 |
return self._ReturnCode_t.RTC_OK |
2138 |
|
2139 |
end |
2140 |
|
2141 |
|
2142 |
|
2143 |
function Manager:unload(fname) |
2144 |
self._rtcout:RTC_TRACE("Manager.unload()") |
2145 |
self._listeners.module_:preUnload(fname) |
2146 |
self._module:unload(fname) |
2147 |
self._listeners.module_:postUnload(fname) |
2148 |
end |
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 |
|
2158 |
function Manager:setinitThread(thread) |
2159 |
self._initThread = thread |
2160 |
end |
2161 |
|
2162 |
|
2163 |
|
2164 |
local function alignment(self, size) |
2165 |
local extra = (self.cursor-2)%size |
2166 |
if extra > 0 then return size-extra end |
2167 |
return 0 |
2168 |
end |
2169 |
|
2170 |
|
2171 |
local align = function(self, size) |
2172 |
local shift = alignment(self, size) |
2173 |
|
2174 |
if shift > 0 then self:jump(shift) end |
2175 |
end |
2176 |
|
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 |
function Manager:cdrMarshal(data, dataType) |
2182 |
|
2183 |
local encoder = self._orb:newencoder() |
2184 |
|
2185 |
|
2186 |
encoder.align = align |
2187 |
|
2188 |
encoder:put(data, self._orb.types:lookup(dataType)) |
2189 |
|
2190 |
local cdr = encoder:getdata() |
2191 |
|
2192 |
|
2193 |
|
2194 |
if #cdr == 0 then |
2195 |
else |
2196 |
cdr = string.sub(cdr,2) |
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
end |
2204 |
|
2205 |
|
2206 |
|
2207 |
return cdr |
2208 |
end |
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 |
function Manager:cdrUnmarshal(cdr, dataType) |
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
cdr = string.char(1)..cdr |
2230 |
local decoder = self._orb:newdecoder(cdr) |
2231 |
|
2232 |
decoder.align = align |
2233 |
|
2234 |
|
2235 |
local _data = decoder:get(self._orb.types:lookup(dataType)) |
2236 |
return _data |
2237 |
end |
2238 |
|
2239 |
|
2240 |
|
2241 |
Manager.is_main = function() |
2242 |
|
2243 |
return ManagerInfo.is_main() |
2244 |
end |
2245 |
|
2246 |
|
2247 |
local terminate_Task = {} |
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
terminate_Task.new = function(mgr, sleep_time) |
2253 |
local obj = {} |
2254 |
obj._mgr = mgr |
2255 |
obj._sleep_time = sleep_time |
2256 |
|
2257 |
function obj:svc() |
2258 |
|
2259 |
Timer.sleep(self._sleep_time) |
2260 |
self._mgr:shutdown() |
2261 |
end |
2262 |
return obj |
2263 |
end |
2264 |
|
2265 |
|
2266 |
function Manager:createShutdownThread(sleep_time) |
2267 |
if not self.shutdown_start then |
2268 |
if sleep_time == nil then |
2269 |
sleep_time = 0 |
2270 |
end |
2271 |
if not self.no_block then |
2272 |
Task.start(terminate_Task.new(self, sleep_time)) |
2273 |
else |
2274 |
oil.main(function() |
2275 |
oil.newthread(self._orb.run, self._orb) |
2276 |
Task.start(terminate_Task.new(self, sleep_time)) |
2277 |
end) |
2278 |
end |
2279 |
end |
2280 |
end |
2281 |
|
2282 |
|
2283 |
|
2284 |
return Manager |
2285 |
|
2286 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local ManagerServant= {} |
11 |
|
12 |
|
13 |
local StringUtil = require "openrtm.StringUtil" |
14 |
local NVUtil = require "openrtm.NVUtil" |
15 |
local oil = require "oil" |
16 |
local RTCUtil = require "openrtm.RTCUtil" |
17 |
local Properties = require "openrtm.Properties" |
18 |
local CORBA_SeqUtil = require "openrtm.CORBA_SeqUtil" |
19 |
local Timer = require "openrtm.Timer" |
20 |
|
21 |
|
22 |
|
23 |
ManagerServant.CompParam = {} |
24 |
ManagerServant.CompParam.prof_list = { |
25 |
"RTC", |
26 |
"vendor", |
27 |
"category", |
28 |
"implementation_id", |
29 |
"language", |
30 |
"version" |
31 |
} |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
local is_equiv = function(mgr) |
39 |
local obj = {} |
40 |
obj._mgr = mgr |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
local call_func = function(self, mgr) |
46 |
return NVUtil._is_equivalent(self._mgr, mgr, self._mgr.getObjRef, mgr.getObjRef) |
47 |
end |
48 |
setmetatable(obj, {__call=call_func}) |
49 |
return obj |
50 |
end |
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
ManagerServant.CompParam.new = function(module_name) |
59 |
local obj = {} |
60 |
module_name = StringUtil.split(module_name, "?")[1] |
61 |
local param_list = StringUtil.split(module_name, ":") |
62 |
if #param_list < #ManagerServant.CompParam.prof_list then |
63 |
obj._type = "RTC" |
64 |
obj._vendor = "" |
65 |
obj._category = "" |
66 |
obj._impl_id = module_name |
67 |
obj._language = "Lua" |
68 |
obj._version = "" |
69 |
else |
70 |
obj._type = param_list[1] |
71 |
obj._vendor = param_list[2] |
72 |
obj._category = param_list[3] |
73 |
obj._impl_id = param_list[4] |
74 |
if param_list[5] ~= "" then |
75 |
obj._language = param_list[5] |
76 |
else |
77 |
obj._language = "Lua" |
78 |
end |
79 |
obj._version = param_list[6] |
80 |
end |
81 |
function obj:vendor() |
82 |
return self._vendor |
83 |
end |
84 |
function obj:category() |
85 |
return self._category |
86 |
end |
87 |
function obj:impl_id() |
88 |
return self._impl_id |
89 |
end |
90 |
function obj:language() |
91 |
return self._language |
92 |
end |
93 |
function obj:version() |
94 |
return self._version |
95 |
end |
96 |
|
97 |
return obj |
98 |
end |
99 |
|
100 |
|
101 |
|
102 |
ManagerServant.new = function() |
103 |
local obj = {} |
104 |
|
105 |
|
106 |
|
107 |
|
108 |
function obj:createINSManager() |
109 |
local success, exception = oil.pcall( |
110 |
function() |
111 |
|
112 |
local id = self._mgr:getConfig():getProperty("manager.name") |
113 |
self._svr = self._mgr:getORB():newservant(self, id, "IDL:RTM/Manager:1.0") |
114 |
self._objref = RTCUtil.getReference(self._mgr:getORB(), self._svr, "IDL:RTM/Manager:1.0") |
115 |
|
116 |
|
117 |
end) |
118 |
if not success then |
119 |
self._rtcout:RTC_DEBUG(exception) |
120 |
return false |
121 |
end |
122 |
return true |
123 |
end |
124 |
|
125 |
function obj:getObjRef() |
126 |
return self._objref |
127 |
end |
128 |
|
129 |
function obj:exit() |
130 |
|
131 |
for k,master in ipairs(self._masters) do |
132 |
master:remove_slave_manager(self._objref) |
133 |
end |
134 |
self._masters = {} |
135 |
for k,slave in ipairs(self._slaves) do |
136 |
slave:remove_master_manager(self._objref) |
137 |
end |
138 |
self._slaves = {} |
139 |
|
140 |
self._mgr:getORB():deactivate(self._svr) |
141 |
|
142 |
end |
143 |
|
144 |
|
145 |
|
146 |
|
147 |
function obj:findManager(host_port) |
148 |
self._rtcout:RTC_TRACE("findManager(host_port = "..host_port..")") |
149 |
local mgr = oil.corba.idl.null |
150 |
local success, exception = oil.pcall( |
151 |
function() |
152 |
local config = self._mgr:getConfig() |
153 |
local mgrloc = "corbaloc:iiop:" |
154 |
mgrloc = mgrloc..host_port |
155 |
mgrloc = mgrloc.."/"..config:getProperty("manager.name") |
156 |
|
157 |
self._rtcout:RTC_DEBUG("corbaloc: "..mgrloc) |
158 |
|
159 |
|
160 |
mgr = RTCUtil.newproxy(self._mgr:getORB(), mgrloc,"IDL:RTM/Manager:1.0") |
161 |
if NVUtil._non_existent(mgr) then |
162 |
mgr = oil.corba.idl.null |
163 |
end |
164 |
|
165 |
|
166 |
end) |
167 |
if not success then |
168 |
mgr = oil.corba.idl.null |
169 |
self._rtcout:RTC_DEBUG(exception) |
170 |
end |
171 |
|
172 |
return mgr |
173 |
end |
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
function obj:get_components_by_name(name) |
182 |
self._rtcout:RTC_TRACE("get_components_by_name()") |
183 |
local rtcs = self._mgr:getComponents() |
184 |
local crtcs = {} |
185 |
local name = StringUtil.eraseHeadBlank(name) |
186 |
|
187 |
local rtc_name = StringUtil.split(name, "/") |
188 |
for k,rtc in ipairs(rtcs) do |
189 |
if #rtc_name == 1 then |
190 |
|
191 |
if rtc:getInstanceName() == rtc_name[1] then |
192 |
table.insert(crtcs, rtc:getObjRef()) |
193 |
end |
194 |
|
195 |
else |
196 |
if rtc_name[1] == "*" then |
197 |
if rtc:getInstanceName() == rtc_name[2] then |
198 |
table.insert(crtcs, rtc:getObjRef()) |
199 |
end |
200 |
else |
201 |
if rtc:getCategory() == rtc_name[1] then |
202 |
if rtc:getInstanceName() == rtc_name[2] then |
203 |
table.insert(crtcs, rtc:getObjRef()) |
204 |
end |
205 |
end |
206 |
end |
207 |
end |
208 |
end |
209 |
return crtcs |
210 |
end |
211 |
|
212 |
|
213 |
|
214 |
|
215 |
function obj:add_master_manager(mgr) |
216 |
self._rtcout:RTC_TRACE("add_master_manager(), "..#self._masters.." masters") |
217 |
local index = CORBA_SeqUtil.find(self._masters, is_equiv(mgr)) |
218 |
|
219 |
if not (index < 1) then |
220 |
self._rtcout:RTC_ERROR("Already exists.") |
221 |
return self._ReturnCode_t.BAD_PARAMETER |
222 |
end |
223 |
|
224 |
table.insert(self._masters, mgr) |
225 |
self._rtcout.RTC_TRACE("add_master_manager() done, "..#self._masters.." masters") |
226 |
return self._ReturnCode_t.RTC_OK |
227 |
end |
228 |
|
229 |
|
230 |
|
231 |
function obj:add_slave_manager(mgr) |
232 |
self._rtcout:RTC_TRACE("add_slave_manager(), "..#self._slaves.." slaves") |
233 |
local index = CORBA_SeqUtil.find(self._slaves, is_equiv(mgr)) |
234 |
|
235 |
if not (index < 1) then |
236 |
self._rtcout:RTC_ERROR("Already exists.") |
237 |
return self._ReturnCode_t.BAD_PARAMETER |
238 |
end |
239 |
|
240 |
table.insert(self._slaves, mgr) |
241 |
self._rtcout.RTC_TRACE("add_slave_manager() done, "..#self._slaves.." slaves") |
242 |
return self._ReturnCode_t.RTC_OK |
243 |
end |
244 |
|
245 |
|
246 |
|
247 |
function obj:getObjRef() |
248 |
return self._objref |
249 |
end |
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
function obj:load_module(pathname, initfunc) |
256 |
self._rtcout:RTC_TRACE("ManagerServant::load_module("..pathname..", "..initfunc..")") |
257 |
self._mgr:load(pathname, initfunc) |
258 |
return self._ReturnCode_t.RTC_OK |
259 |
end |
260 |
|
261 |
|
262 |
|
263 |
|
264 |
function obj:unload_module(pathname) |
265 |
self._rtcout:RTC_TRACE("ManagerServant::unload_module("..pathname..")") |
266 |
self._mgr:unload(pathname) |
267 |
return self._ReturnCode_t.RTC_OK |
268 |
end |
269 |
|
270 |
|
271 |
|
272 |
function obj:get_loadable_modules() |
273 |
return {} |
274 |
end |
275 |
|
276 |
|
277 |
|
278 |
function obj:get_loaded_modules() |
279 |
self._rtcout:RTC_TRACE("get_loaded_modules()") |
280 |
local prof = self._mgr:getLoadedModules() |
281 |
local cprof = {} |
282 |
for k,p in ipairs(prof) do |
283 |
local module_profile = {properties={}} |
284 |
NVUtil.copyFromProperties(module_profile.properties, p) |
285 |
table.insert(cprof, p) |
286 |
|
287 |
end |
288 |
|
289 |
|
290 |
if self._isMaster then |
291 |
for k,slave in ipairs(self._slaves) do |
292 |
local success, exception = oil.pcall( |
293 |
function() |
294 |
local profs = slave:get_loaded_modules() |
295 |
CORBA_SeqUtil.push_back_list(cprof, profs) |
296 |
end |
297 |
) |
298 |
if not success then |
299 |
self._rtcout:RTC_ERROR("Unknown exception cought.") |
300 |
self._rtcout:RTC_DEBUG(exception) |
301 |
table.remove(self._slaves, k) |
302 |
end |
303 |
end |
304 |
end |
305 |
|
306 |
return cprof |
307 |
end |
308 |
|
309 |
|
310 |
|
311 |
function obj:get_factory_profiles() |
312 |
self._rtcout:RTC_TRACE("get_factory_profiles()") |
313 |
local prof = self._mgr:getFactoryProfiles() |
314 |
local cprof = {} |
315 |
for k,p in ipairs(prof) do |
316 |
local module_profile = {properties={}} |
317 |
NVUtil.copyFromProperties(module_profile.properties, p) |
318 |
table.insert(cprof, p) |
319 |
|
320 |
end |
321 |
|
322 |
|
323 |
if self._isMaster then |
324 |
for k,slave in ipairs(self._slaves) do |
325 |
local success, exception = oil.pcall( |
326 |
function() |
327 |
local profs = slave:get_factory_profiles() |
328 |
CORBA_SeqUtil.push_back_list(cprof, profs) |
329 |
end |
330 |
) |
331 |
if not success then |
332 |
self._rtcout:RTC_ERROR("Unknown exception cought.") |
333 |
self._rtcout:RTC_DEBUG(exception) |
334 |
table.remove(self._slaves, k) |
335 |
end |
336 |
end |
337 |
end |
338 |
|
339 |
return cprof |
340 |
end |
341 |
|
342 |
function obj:findManagerByName(manager_name) |
343 |
return oil.corba.idl.null |
344 |
end |
345 |
|
346 |
|
347 |
|
348 |
|
349 |
function obj:getParameterByModulename(param_name, module_name) |
350 |
local arg = module_name[1] |
351 |
local pos0, c = string.find(arg, "&"..param_name.."=") |
352 |
local pos1, c = string.find(arg, "?"..param_name.."=") |
353 |
|
354 |
if pos0 == nil and pos1 == nil then |
355 |
return "" |
356 |
end |
357 |
local pos = 0 |
358 |
if pos1 == nil then |
359 |
pos = pos0 |
360 |
else |
361 |
pos = pos1 |
362 |
end |
363 |
|
364 |
|
365 |
local paramstr = "" |
366 |
local endpos, c = string.find(string.sub(arg,pos+1), '&') |
367 |
if endpos == nil then |
368 |
endpos = string.find(string.sub(arg,pos+1), '?') |
369 |
if endpos == nil then |
370 |
paramstr = string.sub(arg, pos + 1) |
371 |
else |
372 |
paramstr = string.sub(arg, pos + 1, pos - 1 + endpos) |
373 |
end |
374 |
else |
375 |
paramstr = string.sub(arg, pos + 1, pos - 1 + endpos) |
376 |
|
377 |
end |
378 |
self._rtcout:RTC_VERBOSE(param_name.." arg: "..paramstr) |
379 |
|
380 |
local eqpos, c = string.find(paramstr, "=") |
381 |
if eqpos == nil then |
382 |
eqpos = 0 |
383 |
end |
384 |
|
385 |
paramstr = string.sub(paramstr, eqpos + 1) |
386 |
|
387 |
self._rtcout:RTC_DEBUG(param_name.." is "..paramstr) |
388 |
if endpos == nil then |
389 |
arg = string.sub(arg, 1, pos-1) |
390 |
else |
391 |
arg = string.sub(arg,1,pos-1)..string.sub(arg, endpos) |
392 |
end |
393 |
|
394 |
module_name[1] = arg |
395 |
|
396 |
return paramstr |
397 |
end |
398 |
|
399 |
function obj:createComponentByManagerName(module_name) |
400 |
local arg = module_name |
401 |
local tmp = {arg} |
402 |
local mgrstr = self:getParameterByModulename("manager_name",tmp) |
403 |
local arg = tmp[1] |
404 |
if mgrstr == "" then |
405 |
return oil.corba.idl.null |
406 |
end |
407 |
|
408 |
local mgrobj = oil.corba.idl.null |
409 |
if mgrstr ~= "manager_%p" then |
410 |
mgrobj = self:findManagerByName(mgrstr) |
411 |
end |
412 |
|
413 |
|
414 |
local comp_param = ManagerServant.CompParam.new(arg) |
415 |
if mgrobj == oil.corba.idl.null then |
416 |
local config = self._mgr:getConfig() |
417 |
local rtcd_cmd = config:getProperty("manager.modules."..comp_param:language()..".manager_cmd") |
418 |
if rtcd_cmd == "" then |
419 |
rtcd_cmd = "rtcd_lua" |
420 |
end |
421 |
local load_path = config:getProperty("manager.modules.load_path") |
422 |
local load_path_language = config:getProperty("manager.modules."..comp_param:language()..".load_path") |
423 |
load_path = load_path..","..load_path_language |
424 |
local cmd = rtcd_cmd |
425 |
load_path = string.gsub(load_path, "\\","\\\\") |
426 |
|
427 |
cmd = cmd.." -o ".."manager.is_master:NO" |
428 |
cmd = cmd.." -o ".."manager.corba_servant:YES" |
429 |
cmd = cmd.." -o ".."corba.master_manager:"..config:getProperty("corba.master_manager") |
430 |
cmd = cmd.." -o ".."manager.name:"..config:getProperty("manager.name") |
431 |
cmd = cmd.." -o ".."manager.instance_name:"..mgrstr |
432 |
cmd = cmd.." -o ".."\"manager.modules.load_path:"..load_path.."\"" |
433 |
cmd = cmd.." -o ".."manager.supported_languages:"..comp_param:language() |
434 |
cmd = cmd.." -o ".."manager.shutdown_auto:NO" |
435 |
|
436 |
self._rtcout:RTC_DEBUG("Invoking command: "..cmd..".") |
437 |
|
438 |
local slaves_names = {} |
439 |
local regex = 'manager_%d.*' |
440 |
if mgrstr == "manager_%p" then |
441 |
for k, slave in pairs(self._slaves) do |
442 |
local success, exception = oil.pcall( |
443 |
function() |
444 |
local prof = slave:get_configuration() |
445 |
local prop = Properties.new() |
446 |
NVUtil.copyToProperties(prop, prof) |
447 |
local name = prop:getProperty("manager.instance_name") |
448 |
if string.match(name, regex) ~= nil then |
449 |
table.insert(slaves_names, name) |
450 |
end |
451 |
end) |
452 |
if not success then |
453 |
self._rtcout:RTC_ERROR("Unknown exception cought.") |
454 |
self._rtcout:RTC_DEBUG(exception) |
455 |
table.remove(self._slaves, k) |
456 |
end |
457 |
end |
458 |
end |
459 |
|
460 |
local ret = os.execute(cmd) |
461 |
|
462 |
|
463 |
Timer.sleep(0.01) |
464 |
local count = 0 |
465 |
local t0_ = os.clock() |
466 |
while mgrobj == oil.corba.idl.null do |
467 |
if mgrstr == "manager_%p" then |
468 |
mgrobj = self:findManager(mgrstr) |
469 |
for k, slave in pairs(self._slaves) do |
470 |
local success, exception = oil.pcall( |
471 |
function() |
472 |
local prof = slave.get_configuration() |
473 |
local prop = OpenRTM_aist.Properties() |
474 |
NVUtil.copyToProperties(prop, prof) |
475 |
local name = prop.getProperty("manager.instance_name") |
476 |
|
477 |
if string.match(name, regex) ~= nil and not StringUtil.includes(slaves_names, name) then |
478 |
mgrobj = slave |
479 |
end |
480 |
end) |
481 |
if not success then |
482 |
self._rtcout:RTC_ERROR("Unknown exception cought.") |
483 |
self._rtcout:RTC_DEBUG(exception) |
484 |
table.remove(self._slaves, k) |
485 |
end |
486 |
end |
487 |
else |
488 |
mgrobj = self:findManagerByName(mgrstr) |
489 |
end |
490 |
|
491 |
count = count+1 |
492 |
if count > 1000 then |
493 |
break |
494 |
end |
495 |
local t1_ = os.clock() |
496 |
if (t1_ - t0_) > 10.0 and count > 10 then |
497 |
break |
498 |
end |
499 |
|
500 |
Timer.sleep(0.01) |
501 |
|
502 |
end |
503 |
|
504 |
end |
505 |
if mgrobj == oil.corba.idl.null then |
506 |
self._rtcout:RTC_WARN("Manager cannot be found.") |
507 |
return oil.corba.idl.null |
508 |
end |
509 |
self._rtcout:RTC_DEBUG("Creating component on "..mgrstr) |
510 |
self._rtcout:RTC_DEBUG("arg: "..arg) |
511 |
local rtobj = oil.corba.idl.null |
512 |
local success, exception = oil.pcall( |
513 |
function() |
514 |
rtobj = mgrobj.create_component(arg) |
515 |
self._rtcout.RTC_DEBUG("Component created "..arg) |
516 |
end) |
517 |
if not success then |
518 |
self._rtcout.RTC_DEBUG("Exception was caught while creating component.") |
519 |
self._rtcout.RTC_ERROR(exception) |
520 |
return oil.corba.idl.null |
521 |
end |
522 |
return rtobj |
523 |
end |
524 |
|
525 |
function obj:createComponentByAddress(module_name) |
526 |
local arg = module_name |
527 |
local tmp = {arg} |
528 |
local mgrstr = self:getParameterByModulename("manager_address",tmp) |
529 |
local arg = tmp[1] |
530 |
if mgrstr == "" then |
531 |
return oil.corba.idl.null |
532 |
end |
533 |
|
534 |
local mgrvstr = StringUtil.split(mgrstr, ":") |
535 |
if #mgrvstr ~= 2 then |
536 |
self._rtcout:RTC_WARN("Invalid manager address: "..mgrstr) |
537 |
return oil.corba.idl.null |
538 |
end |
539 |
local mgrobj = self:findManager(mgrstr) |
540 |
local comp_param = ManagerServant.CompParam.new(arg) |
541 |
if mgrobj == oil.corba.idl.null then |
542 |
local config = self._mgr:getConfig() |
543 |
local rtcd_cmd = config:getProperty("manager.modules."..comp_param:language()..".manager_cmd") |
544 |
if rtcd_cmd == "" then |
545 |
rtcd_cmd = "rtcd_lua" |
546 |
end |
547 |
local load_path = config:getProperty("manager.modules.load_path") |
548 |
local load_path_language = config:getProperty("manager.modules."..comp_param:language()..".load_path") |
549 |
load_path = load_path..","..load_path_language |
550 |
local cmd = rtcd_cmd |
551 |
load_path = string.gsub(load_path, "\\","\\\\") |
552 |
cmd = cmd.." -o corba.master_manager:" |
553 |
cmd = cmd..mgrstr |
554 |
cmd = cmd.." -o \"manager.modules.load_path:" |
555 |
cmd = cmd..load_path + "\"" |
556 |
cmd = cmd.." -d " |
557 |
|
558 |
self._rtcout:RTC_DEBUG("Invoking command: "..cmd..".") |
559 |
local ret = os.execute(cmd) |
560 |
|
561 |
Timer.sleep(0.01) |
562 |
local count = 0 |
563 |
local t0_ = os.clock() |
564 |
while mgrobj == oil.corba.idl.null do |
565 |
mgrobj = self:findManager(mgrstr) |
566 |
count = count+1 |
567 |
if count > 1000 then |
568 |
break |
569 |
end |
570 |
local t1_ = os.clock() |
571 |
if (t1_ - t0_) > 10.0 and count > 10 then |
572 |
break |
573 |
end |
574 |
|
575 |
Timer.sleep(0.01) |
576 |
|
577 |
end |
578 |
|
579 |
end |
580 |
if mgrobj == oil.corba.idl.null then |
581 |
self._rtcout:RTC_WARN("Manager cannot be found.") |
582 |
return oil.corba.idl.null |
583 |
end |
584 |
self._rtcout:RTC_DEBUG("Creating component on "..mgrstr) |
585 |
self._rtcout:RTC_DEBUG("arg: "..arg) |
586 |
local rtobj = oil.corba.idl.null |
587 |
local success, exception = oil.pcall( |
588 |
function() |
589 |
rtobj = mgrobj.create_component(arg) |
590 |
self._rtcout.RTC_DEBUG("Component created "..arg) |
591 |
end) |
592 |
if not success then |
593 |
self._rtcout.RTC_DEBUG("Exception was caught while creating component.") |
594 |
self._rtcout.RTC_ERROR(exception) |
595 |
return oil.corba.idl.null |
596 |
end |
597 |
return rtobj |
598 |
end |
599 |
|
600 |
|
601 |
|
602 |
|
603 |
function obj:create_component(module_name) |
604 |
self._rtcout:RTC_TRACE("create_component("..module_name..")") |
605 |
local rtc = self:createComponentByAddress(module_name) |
606 |
if rtc ~= oil.corba.idl.null then |
607 |
return rtc |
608 |
end |
609 |
rtc = self:createComponentByManagerName(module_name) |
610 |
if rtc ~= oil.corba.idl.null then |
611 |
return rtc |
612 |
end |
613 |
local tmp = {module_name} |
614 |
self:getParameterByModulename("manager_address",tmp) |
615 |
module_name = tmp[1] |
616 |
|
617 |
local comp_param = ManagerServant.CompParam.new(module_name) |
618 |
|
619 |
if self._isMaster then |
620 |
|
621 |
for k, slave in ipairs(self._slaves) do |
622 |
local success, exception = oil.pcall( |
623 |
function() |
624 |
local prof = slave:get_configuration() |
625 |
local prop = Properties.new() |
626 |
NVUtil.copyToProperties(prop, prof) |
627 |
local slave_lang = prop:getProperty("manager.language") |
628 |
|
629 |
if slave_lang == comp_param:language() then |
630 |
rtc = slave:create_component(module_name) |
631 |
end |
632 |
end) |
633 |
if not success then |
634 |
self._rtcout:RTC_ERROR("Unknown exception cought.") |
635 |
self._rtcout:RTC_DEBUG(exception) |
636 |
table.remove(self._slaves, k) |
637 |
end |
638 |
if rtc ~= oil.corba.idl.null then |
639 |
return rtc |
640 |
end |
641 |
end |
642 |
|
643 |
if manager_name == "" then |
644 |
module_name = module_name + "&manager_name=manager_%p" |
645 |
rtc = self:createComponentByManagerName(module_name) |
646 |
return rtc |
647 |
end |
648 |
else |
649 |
|
650 |
rtc = self._mgr:createComponent(module_name) |
651 |
if rtc ~= nil then |
652 |
return rtc:getObjRef() |
653 |
end |
654 |
end |
655 |
|
656 |
return oil.corba.idl.null |
657 |
end |
658 |
|
659 |
|
660 |
|
661 |
|
662 |
function obj:delete_component(instance_name) |
663 |
self._rtcout:RTC_TRACE("delete_component("..instance_name..")") |
664 |
local comp_ = self._mgr:getComponent(instance_name) |
665 |
if comp_ == nil then |
666 |
self._rtcout:RTC_WARN("No such component exists: "..instance_name) |
667 |
return self._ReturnCode_t.BAD_PARAMETER |
668 |
end |
669 |
|
670 |
local success, exception = oil.pcall( |
671 |
function() |
672 |
comp_:exit() |
673 |
end) |
674 |
if not success then |
675 |
self._rtcout:RTC_ERROR("Unknown exception was raised, when RTC was finalized.") |
676 |
return self._ReturnCode_t.RTC_ERROR |
677 |
end |
678 |
|
679 |
return self._ReturnCode_t.RTC_OK |
680 |
end |
681 |
|
682 |
|
683 |
|
684 |
function obj:get_components() |
685 |
self._rtcout:RTC_TRACE("get_components()") |
686 |
|
687 |
|
688 |
local rtcs = self._mgr:getComponents() |
689 |
local crtcs = {} |
690 |
|
691 |
|
692 |
for i, rtc in ipairs(rtcs) do |
693 |
table.insert(crtcs, rtc:getObjRef()) |
694 |
end |
695 |
|
696 |
return crtcs |
697 |
end |
698 |
|
699 |
|
700 |
|
701 |
function obj:get_component_profiles() |
702 |
local rtcs = self._mgr:getComponents() |
703 |
local cprofs = {} |
704 |
|
705 |
for i, rtc in ipairs(rtcs) do |
706 |
table.insert(cprofs, rtc:get_component_profile()) |
707 |
end |
708 |
return cprofs |
709 |
|
710 |
end |
711 |
|
712 |
|
713 |
|
714 |
function obj:get_profile() |
715 |
self._rtcout:RTC_TRACE("get_profile()") |
716 |
local prof = {properties={}} |
717 |
NVUtil.copyFromProperties(prof.properties, self._mgr:getConfig():getNode("manager")) |
718 |
|
719 |
return prof |
720 |
end |
721 |
|
722 |
|
723 |
|
724 |
function obj:get_configuration() |
725 |
self._rtcout:RTC_TRACE("get_configuration()") |
726 |
local nvlist = {} |
727 |
NVUtil.copyFromProperties(nvlist, self._mgr:getConfig()) |
728 |
return nvlist |
729 |
end |
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
function obj:set_configuration(name, value) |
736 |
self._rtcout:RTC_TRACE("set_configuration(name = "..name..", value = "..value..")") |
737 |
self._mgr:getConfig():setProperty(name, value) |
738 |
return self._ReturnCode_t.RTC_OK |
739 |
end |
740 |
|
741 |
|
742 |
|
743 |
function obj:is_master() |
744 |
local ret = "" |
745 |
if self._isMaster then |
746 |
ret = "YES" |
747 |
else |
748 |
ret = "NO" |
749 |
end |
750 |
self._rtcout:RTC_TRACE("is_master(): "..ret) |
751 |
return self._isMaster |
752 |
end |
753 |
|
754 |
|
755 |
|
756 |
function obj:get_master_managers() |
757 |
self._rtcout:RTC_TRACE("get_master_managers()") |
758 |
return self._masters |
759 |
end |
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
function obj:remove_master_manager(mgr) |
766 |
self._rtcout:RTC_TRACE("remove_master_manager(), "..#self._masters.." masters") |
767 |
local index = CORBA_SeqUtil.find(self._masters, is_equiv(mgr)) |
768 |
|
769 |
if index < 1 then |
770 |
self._rtcout:RTC_ERROR("Not found.") |
771 |
return self._ReturnCode_t.BAD_PARAMETER |
772 |
end |
773 |
|
774 |
|
775 |
self._masters[index] = nil |
776 |
self._rtcout.RTC_TRACE("remove_master_manager() done, "..#self._masters.." masters") |
777 |
return self._ReturnCode_t.RTC_OK |
778 |
end |
779 |
|
780 |
|
781 |
|
782 |
function obj:get_slave_managers() |
783 |
self._rtcout:RTC_TRACE("get_slave_managers(), "..#self._slaves.." slaves") |
784 |
return self._slaves |
785 |
end |
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
function obj:remove_slave_manager(mgr) |
792 |
self._rtcout:RTC_TRACE("remove_slave_manager(), "..#self._slaves.." slaves") |
793 |
local index = CORBA_SeqUtil.find(self._slaves, is_equiv(mgr)) |
794 |
|
795 |
if index < 1 then |
796 |
self._rtcout:RTC_ERROR("Not found.") |
797 |
return self._ReturnCode_t.BAD_PARAMETER |
798 |
end |
799 |
|
800 |
|
801 |
self._slaves[index] = nil |
802 |
self._rtcout.RTC_TRACE("remove_slave_manager() done, "..#self._slaves.." slaves") |
803 |
return self._ReturnCode_t.RTC_OK |
804 |
end |
805 |
|
806 |
|
807 |
|
808 |
function obj:fork() |
809 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
810 |
end |
811 |
|
812 |
|
813 |
|
814 |
function obj:shutdown() |
815 |
self._mgr:createShutdownThread(1) |
816 |
return self._ReturnCode_t.RTC_OK |
817 |
end |
818 |
|
819 |
|
820 |
|
821 |
function obj:restart() |
822 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
823 |
end |
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
function obj:get_service(name) |
830 |
return oil.corba.idl.null |
831 |
end |
832 |
|
833 |
local Manager = require "openrtm.Manager" |
834 |
obj._mgr = Manager:instance() |
835 |
obj._ReturnCode_t = obj._mgr:getORB().types:lookup("::RTC::ReturnCode_t").labelvalue |
836 |
|
837 |
obj._owner = oil.corba.idl.null |
838 |
obj._rtcout = obj._mgr:getLogbuf("ManagerServant") |
839 |
obj._isMaster = false |
840 |
obj._masters = {} |
841 |
obj._slaves = {} |
842 |
|
843 |
local config = obj._mgr:getConfig() |
844 |
|
845 |
obj._objref = oil.corba.idl.null |
846 |
|
847 |
|
848 |
if not obj:createINSManager() then |
849 |
obj._rtcout:RTC_WARN("Manager CORBA servant creation failed.") |
850 |
return obj |
851 |
end |
852 |
|
853 |
|
854 |
|
855 |
obj._rtcout:RTC_TRACE("Manager CORBA servant was successfully created.") |
856 |
|
857 |
if StringUtil.toBool(config:getProperty("manager.is_master"), "YES", "NO", true) then |
858 |
obj._rtcout:RTC_TRACE("This manager is master.") |
859 |
obj._isMaster = true |
860 |
return obj |
861 |
else |
862 |
obj._rtcout:RTC_TRACE("This manager is slave.") |
863 |
local success, exception = oil.pcall( |
864 |
function() |
865 |
local owner = obj:findManager(config:getProperty("corba.master_manager")) |
866 |
|
867 |
|
868 |
if owner == oil.corba.idl.null then |
869 |
obj._rtcout:RTC_INFO("Master manager not found") |
870 |
return obj |
871 |
end |
872 |
|
873 |
obj:add_master_manager(owner) |
874 |
owner:add_slave_manager(obj._objref) |
875 |
end) |
876 |
if not success then |
877 |
obj._rtcout:RTC_ERROR("Unknown exception cought.") |
878 |
obj._rtcout:RTC_ERROR(exception) |
879 |
end |
880 |
end |
881 |
|
882 |
return obj |
883 |
end |
884 |
|
885 |
return ManagerServant |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local StringUtil = require "openrtm.StringUtil" |
11 |
local ObjectManager = require "openrtm.ObjectManager" |
12 |
local Properties = require "openrtm.Properties" |
13 |
|
14 |
|
15 |
|
16 |
local ModuleManager= {} |
17 |
|
18 |
|
19 |
|
20 |
local CONFIG_EXT = "manager.modules.config_ext" |
21 |
local CONFIG_PATH = "manager.modules.config_path" |
22 |
local DETECT_MOD = "manager.modules.detect_loadable" |
23 |
local MOD_LOADPTH = "manager.modules.load_path" |
24 |
local INITFUNC_SFX = "manager.modules.init_func_suffix" |
25 |
local INITFUNC_PFX = "manager.modules.init_func_prefix" |
26 |
local ALLOW_ABSPATH = "manager.modules.abs_path_allowed" |
27 |
local ALLOW_URL = "manager.modules.download_allowed" |
28 |
local MOD_DWNDIR = "manager.modules.download_dir" |
29 |
local MOD_DELMOD = "manager.modules.download_cleanup" |
30 |
local MOD_PRELOAD = "manager.modules.preload" |
31 |
|
32 |
|
33 |
local DLL = {} |
34 |
|
35 |
DLL.new = function(dll) |
36 |
local obj = {} |
37 |
obj.dll = dll |
38 |
return obj |
39 |
end |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
local DLLEntity = {} |
48 |
DLLEntity.new = function(dll,prop) |
49 |
local obj = {} |
50 |
obj.dll = dll |
51 |
obj.properties = prop |
52 |
return obj |
53 |
end |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
local DLLPred = function(argv) |
59 |
local obj = {} |
60 |
if argv.name ~= nil then |
61 |
obj._import_name = argv.name |
62 |
end |
63 |
if argv.factory ~= nil then |
64 |
obj._import_name = argv.factory |
65 |
end |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
local call_func = function(self, dll) |
72 |
|
73 |
|
74 |
return (self._import_name == dll.properties:getProperty("import_name")) |
75 |
end |
76 |
setmetatable(obj, {__call=call_func}) |
77 |
return obj |
78 |
end |
79 |
|
80 |
|
81 |
ModuleManager.Error = {} |
82 |
|
83 |
|
84 |
|
85 |
ModuleManager.Error.new = function(reason_) |
86 |
local obj = {} |
87 |
obj.reason = reason_ |
88 |
obj.type = "Error" |
89 |
local str_func = function(self) |
90 |
local str = "ModuleManager."..self.type..":"..self.reason |
91 |
return str |
92 |
end |
93 |
setmetatable(obj, {__tostring =str_func}) |
94 |
return obj |
95 |
end |
96 |
|
97 |
|
98 |
ModuleManager.NotFound = {} |
99 |
|
100 |
|
101 |
|
102 |
ModuleManager.NotFound.new = function(name_) |
103 |
local obj = {} |
104 |
obj.name = name_ |
105 |
obj.type = "NotFound" |
106 |
local str_func = function(self) |
107 |
local str = "ModuleManager."..self.type..":"..self.name |
108 |
return str |
109 |
end |
110 |
setmetatable(obj, {__tostring =str_func}) |
111 |
return obj |
112 |
end |
113 |
|
114 |
|
115 |
ModuleManager.FileNotFound = {} |
116 |
|
117 |
|
118 |
|
119 |
ModuleManager.FileNotFound.new = function(name_) |
120 |
local obj = {} |
121 |
obj.type = "FileNotFound" |
122 |
local str_func = function(self) |
123 |
local str = "ModuleManager."..self.type..":"..self.name |
124 |
return str |
125 |
end |
126 |
setmetatable(obj, {__tostring =str_func, __index=ModuleManager.NotFound.new(name_)}) |
127 |
return obj |
128 |
end |
129 |
|
130 |
ModuleManager.ModuleNotFound = {} |
131 |
|
132 |
|
133 |
|
134 |
ModuleManager.ModuleNotFound.new = function(name_) |
135 |
local obj = {} |
136 |
obj.type = "ModuleNotFound" |
137 |
local str_func = function(self) |
138 |
local str = "ModuleManager."..self.type..":"..self.name |
139 |
return str |
140 |
end |
141 |
setmetatable(obj, {__tostring =str_func, __index=ModuleManager.NotFound.new(name_)}) |
142 |
return obj |
143 |
end |
144 |
|
145 |
ModuleManager.SymbolNotFound = {} |
146 |
|
147 |
|
148 |
|
149 |
ModuleManager.SymbolNotFound.new = function(name_) |
150 |
local obj = {} |
151 |
obj.type = "SymbolNotFound" |
152 |
local str_func = function(self) |
153 |
local str = "ModuleManager."..self.type..":"..self.name |
154 |
return str |
155 |
end |
156 |
setmetatable(obj, {__tostring =str_func, __index=ModuleManager.NotFound.new(name_)}) |
157 |
return obj |
158 |
end |
159 |
|
160 |
|
161 |
ModuleManager.NotAllowedOperation = {} |
162 |
|
163 |
|
164 |
|
165 |
ModuleManager.NotAllowedOperation.new = function(reason_) |
166 |
local obj = {} |
167 |
obj.type = "NotAllowedOperation" |
168 |
local str_func = function(self) |
169 |
local str = "ModuleManager."..self.type..":"..self.reason |
170 |
return str |
171 |
end |
172 |
setmetatable(obj, {__tostring =str_func, __index=ModuleManager.Error.new(reason_)}) |
173 |
return obj |
174 |
end |
175 |
|
176 |
|
177 |
ModuleManager.InvalidArguments = {} |
178 |
|
179 |
|
180 |
|
181 |
ModuleManager.InvalidArguments.new = function(reason_) |
182 |
local obj = {} |
183 |
obj.type = "InvalidArguments" |
184 |
local str_func = function(self) |
185 |
local str = "ModuleManager."..self.type..":"..self.reason |
186 |
return str |
187 |
end |
188 |
setmetatable(obj, {__tostring =str_func, __index=ModuleManager.Error.new(reason_)}) |
189 |
return obj |
190 |
end |
191 |
|
192 |
|
193 |
ModuleManager.InvalidOperation = {} |
194 |
|
195 |
|
196 |
|
197 |
ModuleManager.InvalidOperation.new = function(reason_) |
198 |
local obj = {} |
199 |
obj.type = "InvalidOperation" |
200 |
local str_func = function(self) |
201 |
local str = "ModuleManager."..self.type..":"..self.reason |
202 |
return str |
203 |
end |
204 |
setmetatable(obj, {__tostring =str_func, __index=ModuleManager.Error.new(reason_)}) |
205 |
return obj |
206 |
end |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
ModuleManager.new = function(prop) |
219 |
local obj = {} |
220 |
|
221 |
|
222 |
function obj:exit() |
223 |
self:unloadAll() |
224 |
end |
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
function obj:load(file_name, init_func) |
232 |
file_name = string.gsub(file_name, "\\", "/") |
233 |
self._rtcout:RTC_TRACE("load(fname = "..file_name..")") |
234 |
if file_name == "" then |
235 |
error(ModuleManager.InvalidArguments.new("Invalid file name.")) |
236 |
end |
237 |
if StringUtil.isURL(file_name) then |
238 |
if not self._downloadAllowed then |
239 |
error(ModuleManager.NotAllowedOperation.new("Downloading module is not allowed.")) |
240 |
else |
241 |
error(ModuleManager.NotFound.new("Not implemented.")) |
242 |
end |
243 |
end |
244 |
local import_name = StringUtil.basename(file_name) |
245 |
local pathChanged=false |
246 |
local file_path = nil |
247 |
local save_path = "" |
248 |
|
249 |
|
250 |
if StringUtil.isAbsolutePath(file_name) then |
251 |
if not self._absoluteAllowed then |
252 |
error(ModuleManager.NotAllowedOperation.new("Absolute path is not allowed")) |
253 |
else |
254 |
save_path = package.path |
255 |
package.path = package.path..";"..StringUtil.dirname(file_name).."?.lua" |
256 |
|
257 |
pathChanged = true |
258 |
import_name = StringUtil.basename(file_name) |
259 |
file_path = file_name |
260 |
end |
261 |
|
262 |
else |
263 |
file_path = self:findFile(file_name, self._loadPath) |
264 |
if file_path == nil then |
265 |
error(ModuleManager.FileNotFound.new(file_name)) |
266 |
end |
267 |
end |
268 |
|
269 |
|
270 |
|
271 |
if not self:fileExist(file_path) then |
272 |
|
273 |
error(ModuleManager.FileNotFound.new(file_name)) |
274 |
end |
275 |
|
276 |
|
277 |
|
278 |
local f = io.open(file_path, "r") |
279 |
if init_func ~= nil then |
280 |
if string.find(f:read("*a"), init_func) == nil then |
281 |
|
282 |
error(ModuleManager.FileNotFound.new(file_name)) |
283 |
end |
284 |
end |
285 |
f:close() |
286 |
|
287 |
|
288 |
|
289 |
if not pathChanged then |
290 |
package.path = package.path..";"..StringUtil.dirname(file_path).."?.lua" |
291 |
end |
292 |
|
293 |
local ext_pos = string.find(import_name, ".lua") |
294 |
if ext_pos ~= nil then |
295 |
import_name = string.sub(import_name,1,ext_pos-1) |
296 |
end |
297 |
|
298 |
|
299 |
|
300 |
local mo = require(tostring(import_name)) |
301 |
|
302 |
|
303 |
|
304 |
|
305 |
if pathChanged then |
306 |
package.path = save_path |
307 |
end |
308 |
|
309 |
|
310 |
file_path = string.gsub(file_path, "\\", "/") |
311 |
file_path = string.gsub(file_path, "//", "/") |
312 |
|
313 |
|
314 |
|
315 |
local dll = DLLEntity.new(mo,Properties.new()) |
316 |
|
317 |
dll.properties:setProperty("file_path",file_path) |
318 |
dll.properties:setProperty("import_name",import_name) |
319 |
self._modules:registerObject(dll) |
320 |
|
321 |
|
322 |
if init_func == nil then |
323 |
return file_name |
324 |
end |
325 |
|
326 |
self:symbol(import_name,init_func)(self._mgr) |
327 |
|
328 |
return file_name |
329 |
end |
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
function obj:findFile(fname, load_path) |
337 |
file_name = fname |
338 |
|
339 |
for k, path in ipairs(load_path) do |
340 |
local f = nil |
341 |
local suffix = self._properties:getProperty("manager.modules.Lua.suffixes") |
342 |
if string.find(fname, "."..suffix) == nil then |
343 |
f = tostring(path).."/"..tostring(file_name).."."..suffix |
344 |
else |
345 |
f = tostring(path).."/"..tostring(file_name) |
346 |
end |
347 |
|
348 |
|
349 |
|
350 |
if self:fileExist(f) then |
351 |
f = string.gsub(f,"\\","/") |
352 |
f = string.gsub(f,"//","/") |
353 |
return f |
354 |
end |
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
end |
362 |
return "" |
363 |
end |
364 |
|
365 |
|
366 |
|
367 |
|
368 |
function obj:fileExist(filename) |
369 |
local fname = filename |
370 |
local suffix = self._properties:getProperty("manager.modules.Lua.suffixes") |
371 |
if string.find(fname, "."..suffix) == nil then |
372 |
fname = tostring(filename).."."..suffix |
373 |
end |
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
local f = io.open(fname, "r") |
382 |
if f ~= nil then |
383 |
return true |
384 |
end |
385 |
return false |
386 |
|
387 |
|
388 |
end |
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
function obj:symbol(import_name, func_name) |
396 |
local dll = self._modules:find(import_name) |
397 |
|
398 |
if dll == nil then |
399 |
error(ModuleManager.ModuleNotFound.new(import_name)) |
400 |
end |
401 |
|
402 |
local func = dll.dll[func_name] |
403 |
|
404 |
if func == nil then |
405 |
error(ModuleManager.SymbolNotFound.new(import_name)) |
406 |
end |
407 |
|
408 |
return func |
409 |
end |
410 |
|
411 |
|
412 |
|
413 |
function obj:unload(file_name) |
414 |
file_name = string.gsub(file_name, "\\", "/") |
415 |
file_name = string.gsub(file_name, "//", "/") |
416 |
local dll = self._modules:find(file_name) |
417 |
if dll == nil then |
418 |
error(ModuleManager.NotFound.new(file_name)) |
419 |
end |
420 |
local dll_name = dll.properties:getProperty("import_name") |
421 |
|
422 |
package.loaded[dll_name] = nil |
423 |
self._modules:unregisterObject(file_name) |
424 |
|
425 |
end |
426 |
|
427 |
|
428 |
function obj:unloadAll() |
429 |
local dlls = self._modules:getObjects() |
430 |
for k,dll in ipairs(dlls) do |
431 |
local ident = dll.properties:getProperty("import_name") |
432 |
|
433 |
self._modules:unregisterObject(ident) |
434 |
end |
435 |
end |
436 |
|
437 |
|
438 |
|
439 |
function obj:getLoadedModules() |
440 |
local dlls = self._modules:getObjects() |
441 |
local modules = {} |
442 |
for k,dll in ipairs(dlls) do |
443 |
table.insert(modules, dll.properties) |
444 |
end |
445 |
return modules |
446 |
end |
447 |
|
448 |
obj._properties = prop |
449 |
obj._configPath = StringUtil.split(prop:getProperty(CONFIG_PATH), ",") |
450 |
|
451 |
for k, v in pairs(obj._configPath) do |
452 |
obj._configPath[k] = StringUtil.eraseHeadBlank(v) |
453 |
end |
454 |
obj._loadPath = StringUtil.split(prop:getProperty(MOD_LOADPTH,"./"), ",") |
455 |
local system_path = StringUtil.split(package.path,";") |
456 |
|
457 |
for k, v in pairs(obj._loadPath) do |
458 |
obj._loadPath[k] = StringUtil.eraseHeadBlank(v) |
459 |
end |
460 |
|
461 |
for k, v in pairs(system_path) do |
462 |
local path = StringUtil.eraseHeadBlank(v) |
463 |
if path ~= "" then |
464 |
path = StringUtil.dirname(path) |
465 |
table.insert(obj._loadPath, path) |
466 |
end |
467 |
|
468 |
end |
469 |
|
470 |
obj._absoluteAllowed = StringUtil.toBool(prop:getProperty(ALLOW_ABSPATH), |
471 |
"yes", "no", false) |
472 |
|
473 |
obj._downloadAllowed = StringUtil.toBool(prop:getProperty(ALLOW_URL), |
474 |
"yes", "no", false) |
475 |
|
476 |
obj._initFuncSuffix = prop:getProperty(INITFUNC_SFX) |
477 |
obj._initFuncPrefix = prop:getProperty(INITFUNC_PFX) |
478 |
obj._modules = ObjectManager.new(DLLPred) |
479 |
obj._rtcout = nil |
480 |
local Manager = require "openrtm.Manager" |
481 |
obj._mgr = Manager:instance() |
482 |
if obj._rtcout == nil then |
483 |
obj._rtcout = obj._mgr:getLogbuf("ModuleManager") |
484 |
end |
485 |
|
486 |
obj._modprofs = {} |
487 |
return obj |
488 |
end |
489 |
|
490 |
|
491 |
return ModuleManager |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
local NamingManager= {} |
12 |
|
13 |
|
14 |
local oil = require "oil" |
15 |
local CorbaNaming = require "openrtm.CorbaNaming" |
16 |
local StringUtil = require "openrtm.StringUtil" |
17 |
local RTCUtil = require "openrtm.RTCUtil" |
18 |
local NVUtil = require "openrtm.NVUtil" |
19 |
local CorbaConsumer = require "openrtm.CorbaConsumer" |
20 |
|
21 |
|
22 |
NamingManager.NamingBase = {} |
23 |
|
24 |
|
25 |
|
26 |
NamingManager.NamingBase.new = function() |
27 |
local obj = {} |
28 |
|
29 |
|
30 |
|
31 |
function obj:bindObject(name, rtobj) |
32 |
end |
33 |
|
34 |
|
35 |
|
36 |
function obj:bindPortObject(name, port) |
37 |
end |
38 |
|
39 |
|
40 |
function obj:unbindObject(name) |
41 |
end |
42 |
|
43 |
|
44 |
function obj:isAlive() |
45 |
return true |
46 |
end |
47 |
|
48 |
|
49 |
|
50 |
function obj:string_to_component(name) |
51 |
return {} |
52 |
end |
53 |
|
54 |
|
55 |
return obj |
56 |
end |
57 |
|
58 |
NamingManager.NamingOnCorba = {} |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
NamingManager.NamingOnCorba.new = function(orb, names) |
65 |
local obj = {} |
66 |
setmetatable(obj, {__index=NamingManager.NamingBase.new()}) |
67 |
local Manager = require "openrtm.Manager" |
68 |
obj._rtcout = Manager:instance():getLogbuf("manager.namingoncorba") |
69 |
obj._cosnaming = CorbaNaming.new(orb,names) |
70 |
obj._endpoint = "" |
71 |
obj._replaceEndpoint = false |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
function obj:bindObject(name, rtobj) |
77 |
|
78 |
self._rtcout:RTC_TRACE("bindObject(name = "..name..", rtobj or mgr)") |
79 |
local success, exception = oil.pcall( |
80 |
function() |
81 |
|
82 |
self._cosnaming:rebindByString(name, rtobj:getObjRef(), true) |
83 |
|
84 |
end) |
85 |
if not success then |
86 |
|
87 |
self._rtcout:RTC_ERROR(exception) |
88 |
end |
89 |
|
90 |
end |
91 |
|
92 |
|
93 |
|
94 |
function obj:unbindObject(name) |
95 |
self._rtcout:RTC_TRACE("unbindObject(name = "..name..")") |
96 |
local success, exception = oil.pcall( |
97 |
function() |
98 |
self._cosnaming:unbind(name) |
99 |
end) |
100 |
if not success then |
101 |
|
102 |
self._rtcout.RTC_ERROR(exception) |
103 |
end |
104 |
|
105 |
end |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
function obj:getComponentByName(context, name, rtcs) |
113 |
|
114 |
local orb = Manager:instance():getORB() |
115 |
local BindingType = orb.types:lookup("::CosNaming::BindingType").labelvalue |
116 |
|
117 |
local length = 500 |
118 |
|
119 |
local bl,bi = context:list(length) |
120 |
|
121 |
|
122 |
|
123 |
for k,i in ipairs(bl) do |
124 |
|
125 |
|
126 |
|
127 |
if NVUtil.getBindingType(i.binding_type) == BindingType.ncontext then |
128 |
local next_context = RTCUtil.newproxy(orb, context:resolve(i.binding_name),"IDL:omg.org/CosNaming/NamingContext:1.0") |
129 |
|
130 |
self:getComponentByName(next_context, name, rtcs) |
131 |
elseif NVUtil.getBindingType(i.binding_type) == BindingType.nobject then |
132 |
if i.binding_name[1].id == name and i.binding_name[1].kind == "rtc" then |
133 |
|
134 |
local success, exception = oil.pcall( |
135 |
function() |
136 |
local cc = CorbaConsumer.new() |
137 |
cc:setObject(context:resolve(i.binding_name)) |
138 |
local _obj = RTCUtil.newproxy(orb, cc:getObject(),"IDL:openrtm.aist.go.jp/OpenRTM/DataFlowComponent:1.0") |
139 |
|
140 |
if not NVUtil._non_existent(_obj) then |
141 |
table.insert(rtcs, _obj) |
142 |
end |
143 |
end) |
144 |
if not success then |
145 |
self._rtcout:RTC_ERROR(exception) |
146 |
end |
147 |
end |
148 |
end |
149 |
end |
150 |
end |
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
function obj:string_to_component(name) |
158 |
|
159 |
local rtc_list = {} |
160 |
local tmp = StringUtil.split(name, "://") |
161 |
if #tmp > 1 then |
162 |
|
163 |
if tmp[1] == "rtcname" then |
164 |
local url = tmp[2] |
165 |
local r = StringUtil.split(url, "/") |
166 |
|
167 |
if #r > 1 then |
168 |
local host = r[1] |
169 |
local rtc_name = string.sub(url, #host+2) |
170 |
|
171 |
|
172 |
|
173 |
local success, exception = oil.pcall( |
174 |
function() |
175 |
|
176 |
local cns = nil |
177 |
if host == "*" then |
178 |
cns = self._cosnaming |
179 |
else |
180 |
local orb = Manager:instance():getORB() |
181 |
cns = CorbaNaming.new(orb,host) |
182 |
|
183 |
end |
184 |
|
185 |
local names = StringUtil.split(rtc_name, "/") |
186 |
|
187 |
|
188 |
if #names == 2 and names[1] == "*" then |
189 |
|
190 |
local root_cxt = cns:getRootContext() |
191 |
|
192 |
self:getComponentByName(root_cxt, names[2], rtc_list) |
193 |
return rtc_list |
194 |
else |
195 |
rtc_name = rtc_name..".rtc" |
196 |
|
197 |
local _obj = cns:resolveStr(rtc_name) |
198 |
|
199 |
if _obj == oil.corba.idl.null then |
200 |
return {} |
201 |
end |
202 |
if NVUtil._non_existent(_obj) then |
203 |
return {} |
204 |
end |
205 |
|
206 |
_obj = RTCUtil.newproxy(orb, _obj,"IDL:openrtm.aist.go.jp/OpenRTM/DataFlowComponent:1.0") |
207 |
|
208 |
|
209 |
table.insert(rtc_list, _obj) |
210 |
return rtc_list |
211 |
end |
212 |
end) |
213 |
if not success then |
214 |
return {} |
215 |
end |
216 |
end |
217 |
end |
218 |
end |
219 |
|
220 |
return rtc_list |
221 |
end |
222 |
|
223 |
|
224 |
return obj |
225 |
end |
226 |
|
227 |
|
228 |
|
229 |
NamingManager.NamingOnManager = {} |
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
NamingManager.NamingOnManager.new = function(orb, mgr) |
236 |
local obj = {} |
237 |
setmetatable(obj, {__index=NamingManager.NamingBase.new()}) |
238 |
local Manager = require "openrtm.Manager" |
239 |
obj._rtcout = Manager:instance():getLogbuf("manager.namingonmanager") |
240 |
obj._cosnaming = nil |
241 |
obj._orb = orb |
242 |
obj._mgr = mgr |
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
function obj:getManager(name) |
249 |
if name == "*" then |
250 |
local mgr_sev = self._mgr:getManagerServant() |
251 |
local mgr = nil |
252 |
if mgr_sev:is_master() then |
253 |
mgr = mgr_sev:getObjRef() |
254 |
else |
255 |
local masters = mgr_sev:get_master_managers() |
256 |
if #masters > 0 then |
257 |
mgr = masters[1] |
258 |
else |
259 |
mgr = mgr_sev:getObjRef() |
260 |
end |
261 |
end |
262 |
return mgr |
263 |
end |
264 |
local success, exception = oil.pcall( |
265 |
function() |
266 |
local mgrloc = "corbaloc:iiop:" |
267 |
local prop = self._mgr:getConfig() |
268 |
local manager_name = prop:getProperty("manager.name") |
269 |
mgrloc = mgrloc..name |
270 |
mgrloc = mgrloc.."/"..manager_name |
271 |
|
272 |
|
273 |
|
274 |
|
275 |
mgr = RTCUtil.newproxy(self._orb, mgrloc,"IDL:RTM/Manager:1.0") |
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
self._rtcout:RTC_DEBUG("corbaloc: "..mgrloc) |
282 |
|
283 |
|
284 |
end) |
285 |
if not success then |
286 |
self._rtcout:RTC_DEBUG(exception) |
287 |
else |
288 |
return mgr |
289 |
end |
290 |
return oil.corba.idl.null |
291 |
end |
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
function obj:string_to_component(name) |
300 |
|
301 |
local rtc_list = {} |
302 |
local tmp = StringUtil.split(name, "://") |
303 |
|
304 |
|
305 |
if #tmp > 1 then |
306 |
|
307 |
if tmp[1] == "rtcloc" then |
308 |
|
309 |
local url = tmp[2] |
310 |
local r = StringUtil.split(url, "/") |
311 |
if #r > 1 then |
312 |
local host = r[1] |
313 |
local rtc_name = string.sub(url, #host+2) |
314 |
|
315 |
|
316 |
local mgr = self:getManager(host) |
317 |
|
318 |
if mgr ~= oil.corba.idl.null then |
319 |
|
320 |
|
321 |
rtc_list = mgr:get_components_by_name(rtc_name) |
322 |
|
323 |
|
324 |
local slaves = mgr:get_slave_managers() |
325 |
|
326 |
for k,slave in ipairs(slaves) do |
327 |
local success, exception = oil.pcall( |
328 |
function() |
329 |
rtc_list.extend(slave:get_components_by_name(rtc_name)) |
330 |
end) |
331 |
if not success then |
332 |
self._rtcout:RTC_DEBUG(exception) |
333 |
mgr:remove_slave_manager(slave) |
334 |
end |
335 |
end |
336 |
end |
337 |
end |
338 |
return rtc_list |
339 |
end |
340 |
end |
341 |
return rtc_list |
342 |
end |
343 |
|
344 |
return obj |
345 |
end |
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
NamingManager.NameServer = {} |
353 |
NamingManager.NameServer.new = function(meth, name, naming) |
354 |
local obj = {} |
355 |
obj.method = meth |
356 |
obj.nsname = name |
357 |
obj.ns = naming |
358 |
return obj |
359 |
end |
360 |
|
361 |
|
362 |
NamingManager.Comps = {} |
363 |
|
364 |
|
365 |
|
366 |
|
367 |
NamingManager.Comps.new = function(n, _obj) |
368 |
local obj = {} |
369 |
obj.name = n |
370 |
obj.rtobj = _obj |
371 |
return obj |
372 |
end |
373 |
|
374 |
|
375 |
NamingManager.Mgr = {} |
376 |
NamingManager.Mgr.new = function(n, _obj) |
377 |
local obj = {} |
378 |
obj.name = n |
379 |
obj.mgr = _obj |
380 |
return obj |
381 |
end |
382 |
|
383 |
NamingManager.Port = {} |
384 |
NamingManager.Port.new = function(n, _obj) |
385 |
local obj = {} |
386 |
obj.name = n |
387 |
obj.port = _obj |
388 |
return obj |
389 |
end |
390 |
|
391 |
|
392 |
|
393 |
|
394 |
NamingManager.new = function(manager) |
395 |
local obj = {} |
396 |
obj._manager = manager |
397 |
obj._rtcout = manager:getLogbuf('manager.namingmanager') |
398 |
obj._names = {} |
399 |
obj._compNames = {} |
400 |
obj._mgrNames = {} |
401 |
obj._portNames = {} |
402 |
|
403 |
|
404 |
|
405 |
function obj:registerNameServer(method, name_server) |
406 |
|
407 |
self._rtcout:RTC_TRACE("NamingManager::registerNameServer("..method..", "..name_server..")") |
408 |
local name = self:createNamingObj(method, name_server) |
409 |
|
410 |
table.insert(self._names, NamingManager.NameServer.new(method, name_server, name)) |
411 |
end |
412 |
|
413 |
|
414 |
|
415 |
|
416 |
function obj:createNamingObj(method, name_server) |
417 |
|
418 |
self._rtcout:RTC_TRACE("createNamingObj(method = "..method..", nameserver = "..name_server..")") |
419 |
|
420 |
local mth = method |
421 |
|
422 |
|
423 |
if mth == "corba" then |
424 |
local ret = nil |
425 |
local success, exception = oil.pcall( |
426 |
function() |
427 |
local name = NamingManager.NamingOnCorba.new(self._manager:getORB(),name_server) |
428 |
|
429 |
self._rtcout:RTC_INFO("NameServer connection succeeded: "..method.."/"..name_server) |
430 |
ret = name |
431 |
end) |
432 |
if not success then |
433 |
print(exception) |
434 |
self._rtcout:RTC_INFO("NameServer connection failed: "..method.."/"..name_server) |
435 |
end |
436 |
return ret |
437 |
elseif mth == "manager" then |
438 |
|
439 |
local name = NamingManager.NamingOnManager.new(self._manager:getORB(), self._manager) |
440 |
|
441 |
return name |
442 |
end |
443 |
return nil |
444 |
end |
445 |
|
446 |
|
447 |
|
448 |
function obj:bindObject(name, rtobj) |
449 |
self._rtcout:RTC_TRACE("NamingManager::bindObject("..name..")") |
450 |
for i, n in ipairs(self._names) do |
451 |
if n.ns ~= nil then |
452 |
local success, exception = oil.pcall( |
453 |
function() |
454 |
n.ns:bindObject(name, rtobj) |
455 |
end) |
456 |
if not success then |
457 |
n.ns = nil |
458 |
end |
459 |
end |
460 |
end |
461 |
|
462 |
self:registerCompName(name, rtobj) |
463 |
end |
464 |
function obj:bindManagerObject(name, mgr) |
465 |
self._rtcout:RTC_TRACE("NamingManager::bindManagerObject("..name..")") |
466 |
for i, n in ipairs(self._names) do |
467 |
if n.ns ~= nil then |
468 |
local success, exception = oil.pcall( |
469 |
function() |
470 |
n.ns:bindObject(name, mgr) |
471 |
end) |
472 |
if not success then |
473 |
n.ns = nil |
474 |
end |
475 |
end |
476 |
end |
477 |
|
478 |
self:registerMgrName(name, mgr) |
479 |
end |
480 |
function obj:bindPortObject(name, port) |
481 |
self._rtcout:RTC_TRACE("NamingManager::bindPortObject("..name..")") |
482 |
for i, n in ipairs(self._names) do |
483 |
if n.ns ~= nil then |
484 |
local success, exception = oil.pcall( |
485 |
function() |
486 |
n.ns:bindObject(name, port) |
487 |
end) |
488 |
if not success then |
489 |
n.ns = nil |
490 |
end |
491 |
end |
492 |
end |
493 |
|
494 |
self:registerPortName(name, port) |
495 |
end |
496 |
|
497 |
|
498 |
|
499 |
function obj:registerCompName(name, rtobj) |
500 |
for i, compName in ipairs(self._compNames) do |
501 |
if compName.name == name then |
502 |
compName.rtobj = rtobj |
503 |
return |
504 |
end |
505 |
end |
506 |
table.insert(self._compNames, NamingManager.Comps.new(name, rtobj)) |
507 |
end |
508 |
|
509 |
function obj:registerMgrName(name, mgr) |
510 |
for i, mgrName in ipairs(self._mgrNames) do |
511 |
if mgrName.name == name then |
512 |
mgrName.mgr = mgr |
513 |
return |
514 |
end |
515 |
end |
516 |
table.insert(self._mgrNames, NamingManager.Mgr.new(name, rtobj)) |
517 |
end |
518 |
|
519 |
function obj:registerPortName(name, port) |
520 |
for i, portName in ipairs(self._portNames) do |
521 |
if portName.name == name then |
522 |
portName.port = port |
523 |
return |
524 |
end |
525 |
end |
526 |
table.insert(self._portNames, NamingManager.Port.new(name, port)) |
527 |
end |
528 |
|
529 |
|
530 |
|
531 |
function obj:unbindObject(name) |
532 |
self._rtcout:RTC_TRACE("NamingManager::unbindObject("..name..")") |
533 |
for i,n in ipairs(self._names) do |
534 |
if n.ns ~= nil then |
535 |
n.ns:unbindObject(name) |
536 |
end |
537 |
end |
538 |
self:unregisterCompName(name) |
539 |
self:unregisterMgrName(name) |
540 |
self:unregisterPortName(name) |
541 |
end |
542 |
|
543 |
function obj:unbindAll() |
544 |
self._rtcout:RTC_TRACE("NamingManager::unbindAll(): %d names.", #self._compNames) |
545 |
for i, compName in ipairs(self._compNames) do |
546 |
self:unbindObject(compName.name) |
547 |
end |
548 |
for i, mgrName in ipairs(self._mgrNames) do |
549 |
self:unbindObject(mgrName.name) |
550 |
end |
551 |
for i, portName in ipairs(self._portNames) do |
552 |
self:unbindObject(portName.name) |
553 |
end |
554 |
end |
555 |
|
556 |
|
557 |
|
558 |
function obj:unregisterCompName(name) |
559 |
for i, compName in ipairs(self._compNames) do |
560 |
if compName.name == name then |
561 |
table.remove(self._compNames, i) |
562 |
return |
563 |
end |
564 |
end |
565 |
end |
566 |
|
567 |
|
568 |
function obj:unregisterMgrName(name) |
569 |
for i, mgrName in ipairs(self._mgrNames) do |
570 |
if mgrName.name == name then |
571 |
table.remove(self._mgrNames, i) |
572 |
return |
573 |
end |
574 |
end |
575 |
end |
576 |
|
577 |
|
578 |
function obj:unregisterPortName(name) |
579 |
for i, portName in ipairs(self._portNames) do |
580 |
if portName.name == name then |
581 |
table.remove(self._portNames, i) |
582 |
return |
583 |
end |
584 |
end |
585 |
end |
586 |
|
587 |
|
588 |
|
589 |
|
590 |
function obj:string_to_component(name) |
591 |
for k,n in ipairs(self._names) do |
592 |
if n.ns ~= nil then |
593 |
local comps = n.ns:string_to_component(name) |
594 |
if #comps > 0 then |
595 |
return comps |
596 |
end |
597 |
end |
598 |
end |
599 |
return {} |
600 |
end |
601 |
|
602 |
function obj:getObjects() |
603 |
local comps = {} |
604 |
for k,comp in ipairs(self._compNames) do |
605 |
table.insert(comps, comp.rtobj) |
606 |
end |
607 |
return comps |
608 |
end |
609 |
|
610 |
return obj |
611 |
end |
612 |
|
613 |
|
614 |
|
615 |
return NamingManager |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
local NVUtil= {} |
12 |
|
13 |
|
14 |
local oil = require "oil" |
15 |
local CORBA_SeqUtil = require "openrtm.CORBA_SeqUtil" |
16 |
local StringUtil = require "openrtm.StringUtil" |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
NVUtil.newNV = function(name, value) |
23 |
return {name=name, value=value} |
24 |
end |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
NVUtil.copyFromProperties = function(nv, prop) |
30 |
local keys = prop:propertyNames() |
31 |
local keys_len = #keys |
32 |
local nv_len = #nv |
33 |
if nv_len > 0 then |
34 |
for i = 1,nv_len do |
35 |
nv[i] = nil |
36 |
end |
37 |
end |
38 |
|
39 |
for i = 1, keys_len do |
40 |
table.insert(nv, NVUtil.newNV(keys[i], prop:getProperty(keys[i]))) |
41 |
end |
42 |
end |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
NVUtil.getReturnCode = function(ret_code) |
48 |
|
49 |
if type(ret_code) == "string" then |
50 |
local Manager = require "openrtm.Manager" |
51 |
local _ReturnCode_t = Manager:instance():getORB().types:lookup("::RTC::ReturnCode_t").labelvalue |
52 |
if ret_code == "RTC_OK" then |
53 |
return _ReturnCode_t.RTC_OK |
54 |
elseif ret_code == "RTC_ERROR" then |
55 |
return _ReturnCode_t.RTC_ERROR |
56 |
elseif ret_code == "BAD_PARAMETER" then |
57 |
return _ReturnCode_t.BAD_PARAMETER |
58 |
elseif ret_code == "UNSUPPORTED" then |
59 |
return _ReturnCode_t.UNSUPPORTED |
60 |
elseif ret_code == "OUT_OF_RESOURCES" then |
61 |
return _ReturnCode_t.OUT_OF_RESOURCES |
62 |
elseif ret_code == "PRECONDITION_NOT_MET" then |
63 |
return _ReturnCode_t.PRECONDITION_NOT_MET |
64 |
end |
65 |
end |
66 |
return ret_code |
67 |
end |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
NVUtil.getPortStatus = function(ret_code) |
73 |
|
74 |
if type(ret_code) == "string" then |
75 |
local Manager = require "openrtm.Manager" |
76 |
local _PortStatus = Manager:instance():getORB().types:lookup("::OpenRTM::PortStatus").labelvalue |
77 |
|
78 |
if ret_code == "PORT_OK" then |
79 |
return _PortStatus.PORT_OK |
80 |
elseif ret_code == "PORT_ERROR" then |
81 |
return _PortStatus.PORT_ERROR |
82 |
elseif ret_code == "BUFFER_FULL" then |
83 |
return _PortStatus.BUFFER_FULL |
84 |
elseif ret_code == "BUFFER_EMPTY" then |
85 |
return _PortStatus.BUFFER_EMPTY |
86 |
elseif ret_code == "BUFFER_TIMEOUT" then |
87 |
return _PortStatus.BUFFER_TIMEOUT |
88 |
elseif ret_code == "UNKNOWN_ERROR" then |
89 |
return _PortStatus.UNKNOWN_ERROR |
90 |
end |
91 |
end |
92 |
return ret_code |
93 |
end |
94 |
|
95 |
|
96 |
|
97 |
|
98 |
NVUtil.getPortStatus_RTC = function(ret_code) |
99 |
|
100 |
if type(ret_code) == "string" then |
101 |
local Manager = require "openrtm.Manager" |
102 |
local _PortStatus = Manager:instance():getORB().types:lookup("::RTC::PortStatus").labelvalue |
103 |
|
104 |
if ret_code == "PORT_OK" then |
105 |
return _PortStatus.PORT_OK |
106 |
elseif ret_code == "PORT_ERROR" then |
107 |
return _PortStatus.PORT_ERROR |
108 |
elseif ret_code == "BUFFER_FULL" then |
109 |
return _PortStatus.BUFFER_FULL |
110 |
elseif ret_code == "BUFFER_EMPTY" then |
111 |
return _PortStatus.BUFFER_EMPTY |
112 |
elseif ret_code == "BUFFER_TIMEOUT" then |
113 |
return _PortStatus.BUFFER_TIMEOUT |
114 |
elseif ret_code == "UNKNOWN_ERROR" then |
115 |
return _PortStatus.UNKNOWN_ERROR |
116 |
end |
117 |
end |
118 |
return ret_code |
119 |
end |
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
NVUtil.copyToProperties = function(prop, nvlist) |
126 |
for i, nv in ipairs(nvlist) do |
127 |
|
128 |
local val = NVUtil.any_from_any(nv.value) |
129 |
|
130 |
prop:setProperty(nv.name,val) |
131 |
end |
132 |
end |
133 |
|
134 |
local nv_find = {} |
135 |
|
136 |
|
137 |
|
138 |
nv_find.new = function(name) |
139 |
local obj = {} |
140 |
obj._name = name |
141 |
|
142 |
|
143 |
|
144 |
|
145 |
local call_func = function(self, nv) |
146 |
|
147 |
return (self._name == nv.name) |
148 |
end |
149 |
setmetatable(obj, {__call=call_func}) |
150 |
return obj |
151 |
end |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
NVUtil.find_index = function(nv, name) |
158 |
return CORBA_SeqUtil.find(nv, nv_find.new(name)) |
159 |
end |
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
NVUtil.appendStringValue = function(nv, _name, _value) |
168 |
local index = NVUtil.find_index(nv, _name) |
169 |
local tmp_nv = nv[index] |
170 |
if tmp_nv ~= nil then |
171 |
local tmp_str = NVUtil.any_from_any(tmp_nv.value) |
172 |
local values = StringUtil.split(tmp_str,",") |
173 |
local find_flag = false |
174 |
for i, val in ipairs(values) do |
175 |
if val == _value then |
176 |
find_flag = true |
177 |
end |
178 |
end |
179 |
if not find_flag then |
180 |
tmp_str = tmp_str..", " |
181 |
tmp_str = tmp_str.._value |
182 |
tmp_nv.value = tmp_str |
183 |
end |
184 |
else |
185 |
table.insert(nv,{name=_name,value=_value}) |
186 |
end |
187 |
end |
188 |
|
189 |
|
190 |
|
191 |
|
192 |
NVUtil.append = function(dest, src) |
193 |
for i, val in ipairs(src) do |
194 |
table.insert(dest, val) |
195 |
end |
196 |
end |
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
NVUtil.isStringValue = function(nv, name, value) |
205 |
|
206 |
if NVUtil.isString(nv, name) then |
207 |
if NVUtil.toString(nv, name) == value then |
208 |
return true |
209 |
end |
210 |
end |
211 |
return false |
212 |
end |
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
NVUtil.find = function(nv, name) |
219 |
local index = CORBA_SeqUtil.find(nv, nv_find.new(name)) |
220 |
if nv[index] ~= nil then |
221 |
return nv[index].value |
222 |
else |
223 |
return nil |
224 |
end |
225 |
end |
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
NVUtil._is_equivalent = function(obj1, obj2, obj1_ref, obj2_ref) |
234 |
if oil.VERSION == "OiL 0.4 beta" then |
235 |
if obj1._is_equivalent == nil then |
236 |
if obj2._is_equivalent == nil then |
237 |
return obj1_ref(obj1):_is_equivalent(obj2_ref(obj2)) |
238 |
else |
239 |
return obj1_ref(obj1):_is_equivalent(obj2) |
240 |
end |
241 |
else |
242 |
if obj2._is_equivalent == nil then |
243 |
|
244 |
return obj1:_is_equivalent(obj2_ref(obj2)) |
245 |
else |
246 |
return obj1:_is_equivalent(obj2) |
247 |
end |
248 |
end |
249 |
elseif oil.VERSION == "OiL 0.5" then |
250 |
if obj1._is_equivalent == nil then |
251 |
|
252 |
obj1 = obj1_ref(obj1) |
253 |
end |
254 |
if obj2._is_equivalent == nil then |
255 |
obj2 = obj2_ref(obj2) |
256 |
end |
257 |
|
258 |
if obj1._is_equivalent == nil or obj2._is_equivalent == nil then |
259 |
return (obj1 == obj2) |
260 |
else |
261 |
return obj1:_is_equivalent(obj2) |
262 |
end |
263 |
elseif oil.VERSION == "OiL 0.6" then |
264 |
if obj1._is_equivalent == nil then |
265 |
|
266 |
obj1 = obj1_ref(obj1) |
267 |
end |
268 |
if obj2._is_equivalent == nil then |
269 |
obj2 = obj2_ref(obj2) |
270 |
end |
271 |
if obj1._is_equivalent == nil and obj2._is_equivalent == nil then |
272 |
return (obj1 == obj2) |
273 |
else |
274 |
if obj1._is_equivalent ~= nil then |
275 |
return obj1:_is_equivalent(obj2) |
276 |
else |
277 |
return obj2:_is_equivalent(obj1) |
278 |
end |
279 |
end |
280 |
end |
281 |
end |
282 |
|
283 |
|
284 |
|
285 |
|
286 |
NVUtil.any_from_any = function(value) |
287 |
if type(value) == "table" then |
288 |
if value._anyval ~= nil then |
289 |
return value._anyval |
290 |
end |
291 |
end |
292 |
return value |
293 |
end |
294 |
|
295 |
|
296 |
|
297 |
|
298 |
NVUtil.dump_to_stream = function(nv) |
299 |
local out = "" |
300 |
for i, n in ipairs(nv) do |
301 |
local val = NVUtil.any_from_any(nv[i].value) |
302 |
if type(val) == "string" then |
303 |
out = out..n.name..": "..val.."\n" |
304 |
else |
305 |
out = out..n.name..": not a string value \n" |
306 |
end |
307 |
end |
308 |
return out |
309 |
end |
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
NVUtil.toString = function(nv, name) |
316 |
if name == nil then |
317 |
return NVUtil.dump_to_stream(nv) |
318 |
end |
319 |
|
320 |
local str_value = "" |
321 |
local ret_value = NVUtil.find(nv, name) |
322 |
if ret_value ~= nil then |
323 |
local val = NVUtil.any_from_any(ret_value) |
324 |
if type(val) == "string" then |
325 |
str_value = val |
326 |
end |
327 |
end |
328 |
return str_value |
329 |
end |
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
NVUtil.isString = function(nv, name) |
336 |
local value = NVUtil.find(nv, name) |
337 |
if value ~= nil then |
338 |
local val = NVUtil.any_from_any(value) |
339 |
return (type(val) == "string") |
340 |
else |
341 |
return false |
342 |
end |
343 |
end |
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
NVUtil.getBindingType = function(binding_type) |
350 |
if type(binding_type) == "string" then |
351 |
local Manager = require "openrtm.Manager" |
352 |
local _BindingType = Manager:instance():getORB().types:lookup("::CosNaming::BindingType").labelvalue |
353 |
|
354 |
if binding_type == "ncontext" then |
355 |
return _BindingType.ncontext |
356 |
elseif binding_type == "nobject" then |
357 |
return _BindingType.nobject |
358 |
end |
359 |
end |
360 |
return binding_type |
361 |
end |
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
NVUtil.getLifeCycleState = function(state) |
368 |
|
369 |
if type(state) == "string" then |
370 |
local Manager = require "openrtm.Manager" |
371 |
local _LifeCycleState = Manager:instance():getORB().types:lookup("::RTC::LifeCycleState").labelvalue |
372 |
if state == "CREATED_STATE" then |
373 |
return _LifeCycleState.CREATED_STATE |
374 |
elseif state == "INACTIVE_STATE" then |
375 |
return _LifeCycleState.INACTIVE_STATE |
376 |
elseif state == "ACTIVE_STATE" then |
377 |
return _LifeCycleState.ACTIVE_STATE |
378 |
elseif state == "ERROR_STATE" then |
379 |
return _LifeCycleState.ERROR_STATE |
380 |
end |
381 |
end |
382 |
return state |
383 |
end |
384 |
|
385 |
|
386 |
|
387 |
|
388 |
NVUtil._non_existent = function(_obj) |
389 |
|
390 |
if _obj._non_existent == nil then |
391 |
return false |
392 |
else |
393 |
local ret = true |
394 |
local success, exception = oil.pcall( |
395 |
function() |
396 |
ret = _obj:_non_existent() |
397 |
end) |
398 |
return ret |
399 |
end |
400 |
end |
401 |
|
402 |
|
403 |
return NVUtil |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
if dflow_type == "push" then |
259 |
self._rtcout:RTC_PARANOID("dataflow_type = push .... create PushConnector") |
260 |
|
261 |
consumer = self:createConsumer(cprof, prop) |
262 |
|
263 |
|
264 |
if consumer == nil then |
265 |
return self._ReturnCode_t.BAD_PARAMETER |
266 |
end |
267 |
|
268 |
|
269 |
local connector = self:createConnector(cprof, prop, {consumer_ = consumer}) |
270 |
|
271 |
|
272 |
|
273 |
|
274 |
if connector == nil then |
275 |
return self._ReturnCode_t.RTC_ERROR |
276 |
end |
277 |
|
278 |
local ret = connector:setConnectorInfo(profile) |
279 |
if ret == self._ReturnCode_t.RTC_OK then |
280 |
self._rtcout:RTC_DEBUG("subscribeInterfaces() successfully finished.") |
281 |
end |
282 |
|
283 |
|
284 |
return self._ReturnCode_t.RTC_OK |
285 |
elseif dflow_type == "pull" then |
286 |
local conn = self:getConnectorById(cprof.connector_id) |
287 |
if conn == nil then |
288 |
self._rtcout:RTC_ERROR("specified connector not found: "..cprof.connector_id) |
289 |
return self._ReturnCode_t.RTC_ERROR |
290 |
end |
291 |
|
292 |
local ret = conn:setConnectorInfo(profile) |
293 |
|
294 |
if ret == self._ReturnCode_t.RTC_OK then |
295 |
self._rtcout:RTC_DEBUG("subscribeInterfaces() successfully finished.") |
296 |
end |
297 |
|
298 |
return ret |
299 |
end |
300 |
|
301 |
self._rtcout:RTC_ERROR("unsupported dataflow_type") |
302 |
|
303 |
return self._ReturnCode_t.BAD_PARAMETER |
304 |
end |
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
function obj:publishInterfaces(cprof) |
317 |
self._rtcout:RTC_TRACE("publishInterfaces()") |
318 |
|
319 |
|
320 |
local retval = self:_publishInterfaces() |
321 |
if retval ~= self._ReturnCode_t.RTC_OK then |
322 |
return retval |
323 |
end |
324 |
|
325 |
|
326 |
local prop = Properties.new(self._properties) |
327 |
|
328 |
local conn_prop = Properties.new() |
329 |
|
330 |
NVUtil.copyToProperties(conn_prop, cprof.properties) |
331 |
prop:mergeProperties(conn_prop:getNode("dataport")) |
332 |
|
333 |
prop:mergeProperties(conn_prop:getNode("dataport.outport")) |
334 |
|
335 |
|
336 |
|
337 |
local dflow_type = StringUtil.normalize(prop:getProperty("dataflow_type")) |
338 |
|
339 |
if dflow_type == "push" then |
340 |
self._rtcout:RTC_PARANOID("dataflow_type = push .... do nothing") |
341 |
return self._ReturnCode_t.RTC_OK |
342 |
|
343 |
elseif dflow_type == "pull" then |
344 |
self._rtcout:RTC_PARANOID("dataflow_type = pull .... create PullConnector") |
345 |
|
346 |
provider = self:createProvider(cprof, prop) |
347 |
if provider == nil then |
348 |
return self._ReturnCode_t.BAD_PARAMETER |
349 |
end |
350 |
|
351 |
|
352 |
local connector = self:createConnector(cprof, prop, {provider_ = provider}) |
353 |
if connector == nil then |
354 |
return self._ReturnCode_t.RTC_ERROR |
355 |
end |
356 |
|
357 |
|
358 |
provider:setConnector(connector) |
359 |
|
360 |
self._rtcout:RTC_DEBUG("publishInterface() successfully finished.") |
361 |
return self._ReturnCode_t.RTC_OK |
362 |
end |
363 |
|
364 |
self._rtcout:RTC_ERROR("unsupported dataflow_type") |
365 |
|
366 |
return self._ReturnCode_t.BAD_PARAMETER |
367 |
end |
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
function obj:createConnector(cprof, prop, args) |
375 |
local provider_ = args.provider_ |
376 |
local consumer_ = args.consumer_ |
377 |
local profile = ConnectorInfo.new(cprof.name, |
378 |
cprof.connector_id, |
379 |
CORBA_SeqUtil.refToVstring(cprof.ports), |
380 |
prop) |
381 |
local connector = nil |
382 |
|
383 |
local ret = nil |
384 |
local success, exception = oil.pcall( |
385 |
function() |
386 |
if consumer_ ~= nil then |
387 |
connector = OutPortPushConnector.new(profile, consumer_, |
388 |
self._listeners) |
389 |
|
390 |
elseif provider_ ~= nil then |
391 |
connector = OutPortPullConnector.new(profile, provider_, |
392 |
self._listeners) |
393 |
|
394 |
else |
395 |
self._rtcout:RTC_ERROR("provider or consumer is not passed. returned 0;") |
396 |
ret = nil |
397 |
return |
398 |
end |
399 |
|
400 |
|
401 |
|
402 |
|
403 |
if consumer_ ~= nil then |
404 |
self._rtcout:RTC_TRACE("OutPortPushConnector created") |
405 |
elseif provider_ ~= nil then |
406 |
self._rtcout:RTC_TRACE("OutPortPullConnector created") |
407 |
end |
408 |
|
409 |
if StringUtil.normalize(prop:getProperty("interface_type")) == "direct" then |
410 |
|
411 |
if consumer_ ~= nil then |
412 |
local inport = self:getLocalInPort(profile) |
413 |
if inport == nil then |
414 |
self._rtcout:RTC_TRACE("interface_type is direct, ") |
415 |
self._rtcout:RTC_TRACE("but a peer InPort servant could not be obtained.") |
416 |
return nil |
417 |
end |
418 |
connector:setInPort(inport) |
419 |
else |
420 |
connector:setDirectMode() |
421 |
end |
422 |
end |
423 |
|
424 |
|
425 |
table.insert(self._connectors, connector) |
426 |
self._rtcout:RTC_PARANOID("connector push backed: "..#self._connectors) |
427 |
ret = connector |
428 |
return |
429 |
end) |
430 |
if not success then |
431 |
|
432 |
self._rtcout:RTC_ERROR("OutPortPushConnector creation failed") |
433 |
self._rtcout:RTC_ERROR(exception) |
434 |
return nil |
435 |
end |
436 |
return ret |
437 |
end |
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
function obj:createProvider(cprof, prop) |
446 |
|
447 |
if prop:getProperty("interface_type") == "" or |
448 |
not StringUtil.includes(self._providerTypes, prop:getProperty("interface_type")) then |
449 |
self._rtcout:RTC_ERROR("no provider found") |
450 |
self._rtcout:RTC_DEBUG("interface_type: "..prop:getProperty("interface_type")) |
451 |
self._rtcout:RTC_DEBUG("interface_types: ".. |
452 |
StringUtil.flatten(self._providerTypes)) |
453 |
return nil |
454 |
end |
455 |
|
456 |
self._rtcout:RTC_DEBUG("interface_type: "..prop:getProperty("interface_type")) |
457 |
local provider = OutPortProviderFactory:instance():createObject(prop:getProperty("interface_type")) |
458 |
|
459 |
if provider ~= nil then |
460 |
self._rtcout:RTC_DEBUG("provider created") |
461 |
provider:init(prop:getNode("provider")) |
462 |
|
463 |
if not provider:publishInterface(cprof.properties) then |
464 |
self._rtcout:RTC_ERROR("publishing interface information error") |
465 |
OutPortProviderFactory:instance():deleteObject(provider) |
466 |
return nil |
467 |
end |
468 |
|
469 |
return provider |
470 |
end |
471 |
|
472 |
self._rtcout:RTC_ERROR("provider creation failed") |
473 |
return nil |
474 |
end |
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
function obj:createConsumer(cprof, prop) |
483 |
|
484 |
|
485 |
if prop:getProperty("interface_type") == "" or |
486 |
not StringUtil.includes(self._consumerTypes, prop:getProperty("interface_type")) then |
487 |
self._rtcout:RTC_ERROR("no consumer found") |
488 |
self._rtcout:RTC_DEBUG("interface_type: "..prop:getProperty("interface_type")) |
489 |
self._rtcout:RTC_DEBUG("interface_types: "..StringUtil.flatten(self._consumerTypes)) |
490 |
return nil |
491 |
end |
492 |
|
493 |
|
494 |
self._rtcout:RTC_DEBUG("interface_type: "..prop:getProperty("interface_type")) |
495 |
local consumer = InPortConsumerFactory:instance():createObject(prop:getProperty("interface_type")) |
496 |
|
497 |
|
498 |
if consumer ~= nil then |
499 |
self._rtcout:RTC_DEBUG("consumer created") |
500 |
consumer:init(prop:getNode("consumer")) |
501 |
|
502 |
if not consumer:subscribeInterface(cprof.properties) then |
503 |
self._rtcout:RTC_ERROR("interface subscription failed.") |
504 |
InPortConsumerFactory:instance():deleteObject(provider) |
505 |
return nil |
506 |
end |
507 |
return consumer |
508 |
end |
509 |
|
510 |
self._rtcout:RTC_ERROR("provider creation failed") |
511 |
return nil |
512 |
end |
513 |
|
514 |
|
515 |
|
516 |
|
517 |
function obj:getConnectorById(id) |
518 |
self._rtcout:RTC_TRACE("getConnectorById(id = "..id..")") |
519 |
|
520 |
for i, con in pairs(self._connectors) do |
521 |
if id == con:id() then |
522 |
return con |
523 |
end |
524 |
end |
525 |
|
526 |
self._rtcout:RTC_WARN("ConnectorProfile with the id("..id..") not found.") |
527 |
return nil |
528 |
end |
529 |
|
530 |
|
531 |
|
532 |
function obj:unsubscribeInterfaces(connector_profile) |
533 |
self._rtcout:RTC_TRACE("unsubscribeInterfaces()") |
534 |
|
535 |
local id = connector_profile.connector_id |
536 |
self._rtcout:RTC_PARANOID("connector_id: "..id) |
537 |
|
538 |
for i, con in pairs(self._connectors) do |
539 |
if id == con:id() then |
540 |
con:deactivate() |
541 |
con:disconnect() |
542 |
self._connectors[i] = nil |
543 |
self._rtcout:RTC_TRACE("delete connector: "..id) |
544 |
return |
545 |
end |
546 |
end |
547 |
|
548 |
|
549 |
self._rtcout:RTC_ERROR("specified connector not found: "..id) |
550 |
end |
551 |
|
552 |
|
553 |
function obj:activateInterfaces() |
554 |
self._rtcout:RTC_TRACE("activateInterfaces()") |
555 |
for i, con in pairs(self._connectors) do |
556 |
con:activate() |
557 |
self._rtcout:RTC_DEBUG("activate connector: ".. |
558 |
con:name().." "..con:id()) |
559 |
end |
560 |
end |
561 |
|
562 |
|
563 |
function obj:deactivateInterfaces() |
564 |
self._rtcout:RTC_TRACE("deactivateInterfaces()") |
565 |
for i, con in pairs(self._connectors) do |
566 |
con:deactivate() |
567 |
self._rtcout:RTC_DEBUG("deactivate connector: ".. |
568 |
con:name().." "..con:id()) |
569 |
end |
570 |
end |
571 |
|
572 |
|
573 |
function obj:addConnectorDataListener(listener_type, listener, autoclean) |
574 |
if autoclean == nil then |
575 |
autoclean = true |
576 |
end |
577 |
self._rtcout:RTC_TRACE("addConnectorDataListener()") |
578 |
|
579 |
if listener_type < ConnectorDataListenerType.CONNECTOR_DATA_LISTENER_NUM then |
580 |
self._rtcout:RTC_TRACE("addConnectorDataListener(%s)", ConnectorDataListener.toString(listener_type)) |
581 |
self._listeners.connectorData_[listener_type]:addListener(listener, autoclean) |
582 |
return |
583 |
end |
584 |
|
585 |
self._rtcout:RTC_ERROR("addConnectorDataListener(): Unknown Listener Type") |
586 |
|
587 |
end |
588 |
|
589 |
function obj:removeConnectorDataListener(listener_type, listener) |
590 |
self._rtcout:RTC_TRACE("removeConnectorDataListener()") |
591 |
|
592 |
if listener_type < ConnectorDataListenerType.CONNECTOR_DATA_LISTENER_NUM then |
593 |
self._rtcout:RTC_TRACE("removeConnectorDataListener(%s)", ConnectorDataListener.toString(listener_type)) |
594 |
self._listeners.connectorData_[listener_type]:removeListener(listener) |
595 |
return |
596 |
end |
597 |
|
598 |
self._rtcout:RTC_ERROR("removeConnectorDataListener(): Unknown Listener Type") |
599 |
end |
600 |
|
601 |
|
602 |
function obj:addConnectorListener(listener_type, listener, autoclean) |
603 |
if autoclean == nil then |
604 |
autoclean = true |
605 |
end |
606 |
self._rtcout:RTC_TRACE("addConnectorListener()") |
607 |
|
608 |
if listener_type < ConnectorListenerType.CONNECTOR_LISTENER_NUM then |
609 |
self._rtcout:RTC_TRACE("addConnectorListener(%s)", ConnectorListener.toString(listener_type)) |
610 |
self._listeners.connector_[listener_type]:addListener(listener, autoclean) |
611 |
return |
612 |
end |
613 |
|
614 |
self._rtcout:RTC_ERROR("addConnectorListener(): Unknown Listener Type") |
615 |
|
616 |
end |
617 |
|
618 |
function obj:removeConnectorListener(listener_type, listener) |
619 |
self._rtcout:RTC_TRACE("removeConnectorListener()") |
620 |
|
621 |
if listener_type < ConnectorListenerType.CONNECTOR_LISTENER_NUM then |
622 |
self._rtcout:RTC_TRACE("removeConnectorListener(%s)", ConnectorListener.toString(listener_type)) |
623 |
self._listeners.connector_[listener_type]:removeListener(listener) |
624 |
return |
625 |
end |
626 |
|
627 |
self._rtcout:RTC_ERROR("removeConnectorListener(): Unknown Listener Type") |
628 |
end |
629 |
|
630 |
function obj:getLocalInPort(profile) |
631 |
self._rtcout:RTC_DEBUG("Trying direct port connection.") |
632 |
self._rtcout:RTC_DEBUG("Current connector profile: name=%s, id=%s", profile.name, profile.id) |
633 |
for k,p in pairs(profile.ports) do |
634 |
if not NVUtil._is_equivalent(self, p, self.getObjRef, p.getObjRef) then |
635 |
self._rtcout:RTC_DEBUG("Peer port found: %s.", tostring(p)) |
636 |
|
637 |
if p.getObjRef == nil then |
638 |
return nil |
639 |
end |
640 |
self._rtcout:RTC_DEBUG("OutPortBase servant pointer is obtained.") |
641 |
return p |
642 |
end |
643 |
end |
644 |
return nil |
645 |
end |
646 |
|
647 |
|
648 |
return obj |
649 |
end |
650 |
|
651 |
|
652 |
return OutPortBase |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
local OutPortDSConsumer= {} |
13 |
|
14 |
|
15 |
local oil = require "oil" |
16 |
local OutPortConsumer = require "openrtm.OutPortConsumer" |
17 |
local NVUtil = require "openrtm.NVUtil" |
18 |
local BufferStatus = require "openrtm.BufferStatus" |
19 |
local DataPortStatus = require "openrtm.DataPortStatus" |
20 |
local CorbaConsumer = require "openrtm.CorbaConsumer" |
21 |
|
22 |
local Factory = require "openrtm.Factory" |
23 |
local OutPortConsumerFactory = OutPortConsumer.OutPortConsumerFactory |
24 |
|
25 |
local RTCUtil = require "openrtm.RTCUtil" |
26 |
|
27 |
local ConnectorListener = require "openrtm.ConnectorListener" |
28 |
local ConnectorListenerType = ConnectorListener.ConnectorListenerType |
29 |
local ConnectorDataListenerType = ConnectorListener.ConnectorDataListenerType |
30 |
|
31 |
|
32 |
|
33 |
OutPortDSConsumer.new = function() |
34 |
local obj = {} |
35 |
setmetatable(obj, {__index=OutPortConsumer.new()}) |
36 |
setmetatable(obj, {__index=CorbaConsumer.new()}) |
37 |
local Manager = require "openrtm.Manager" |
38 |
obj._PortStatus = Manager:instance():getORB().types:lookup("::RTC::PortStatus").labelvalue |
39 |
|
40 |
obj._rtcout = Manager:instance():getLogbuf("OutPortDSConsumer") |
41 |
obj._buffer = nil |
42 |
obj._profile = nil |
43 |
obj._listeners = nil |
44 |
|
45 |
|
46 |
|
47 |
function obj:init(prop) |
48 |
self._rtcout:RTC_TRACE("init()") |
49 |
end |
50 |
|
51 |
|
52 |
|
53 |
function obj:setBuffer(buffer) |
54 |
self._rtcout:RTC_TRACE("setBuffer()") |
55 |
self._buffer = buffer |
56 |
end |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
function obj:setListener(info, listeners) |
62 |
self._rtcout:RTC_TRACE("setListener()") |
63 |
self._listeners = listeners |
64 |
self._profile = info |
65 |
end |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
function obj:get(data) |
73 |
self._rtcout:RTC_PARANOID("get()") |
74 |
|
75 |
local ret = self._PortStatus.PORT_OK |
76 |
local cdr_data = "" |
77 |
local success, exception = oil.pcall( |
78 |
function() |
79 |
local outportcdr = self:getObject() |
80 |
|
81 |
|
82 |
if outportcdr ~= oil.corba.idl.null then |
83 |
ret,cdr_data = outportcdr:pull() |
84 |
ret = NVUtil.getPortStatus_RTC(ret) |
85 |
return |
86 |
end |
87 |
ret = DataPortStatus.CONNECTION_LOST |
88 |
return |
89 |
end) |
90 |
if not success then |
91 |
self._rtcout:RTC_WARN("Exception caught from OutPort.pull().") |
92 |
self._rtcout:RTC_ERROR(exception) |
93 |
return DataPortStatus.CONNECTION_LOST |
94 |
end |
95 |
|
96 |
if ret == self._PortStatus.PORT_OK then |
97 |
self._rtcout:RTC_DEBUG("get() successful") |
98 |
data._data = cdr_data |
99 |
self:onReceived(data._data) |
100 |
self:onBufferWrite(data._data) |
101 |
|
102 |
if self._buffer:full() then |
103 |
self._rtcout:RTC_INFO("InPort buffer is full.") |
104 |
self:onBufferFull(data._data) |
105 |
self:onReceiverFull(data._data) |
106 |
end |
107 |
|
108 |
self._buffer:put(data._data) |
109 |
self._buffer:advanceWptr() |
110 |
self._buffer:advanceRptr() |
111 |
return DataPortStatus.PORT_OK |
112 |
end |
113 |
return self:convertReturn(ret,data._data) |
114 |
end |
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
function obj:subscribeInterface(properties) |
123 |
self._rtcout:RTC_TRACE("subscribeInterface()") |
124 |
if self:subscribeFromIor(properties) then |
125 |
return true |
126 |
end |
127 |
if self:subscribeFromRef(properties) then |
128 |
return true |
129 |
end |
130 |
return false |
131 |
end |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
function obj:unsubscribeInterface(properties) |
137 |
self._rtcout:RTC_TRACE("unsubscribeInterface()") |
138 |
|
139 |
if self:unsubscribeFromIor(properties) then |
140 |
return |
141 |
end |
142 |
|
143 |
self:unsubscribeFromRef(properties) |
144 |
end |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
function obj:subscribeFromIor(properties) |
152 |
self._rtcout:RTC_TRACE("subscribeFromIor()") |
153 |
|
154 |
local index = NVUtil.find_index(properties, |
155 |
"dataport.data_service.outport_ior") |
156 |
|
157 |
if index < 0 then |
158 |
self._rtcout:RTC_ERROR("outport_ior not found") |
159 |
return false |
160 |
end |
161 |
|
162 |
local ior = "" |
163 |
if properties[index] ~= nil then |
164 |
ior = NVUtil.any_from_any(properties[index].value) |
165 |
end |
166 |
|
167 |
if ior == "" then |
168 |
self._rtcout:RTC_ERROR("dataport.data_service.outport_ior") |
169 |
return false |
170 |
end |
171 |
|
172 |
local Manager = require "openrtm.Manager" |
173 |
local orb = Manager:instance():getORB() |
174 |
local _obj = RTCUtil.newproxy(orb, ior,"IDL:omg.org/RTC/DataPullService:1.0") |
175 |
|
176 |
|
177 |
|
178 |
if _obj == nil then |
179 |
self._rtcout:RTC_ERROR("invalid IOR string has been passed") |
180 |
return false |
181 |
end |
182 |
|
183 |
if not self:setObject(_obj) then |
184 |
self._rtcout:RTC_WARN("Setting object to consumer failed.") |
185 |
return false |
186 |
end |
187 |
|
188 |
return true |
189 |
end |
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
function obj:subscribeFromRef(properties) |
199 |
self._rtcout:RTC_TRACE("subscribeFromRef()") |
200 |
local index = NVUtil.find_index(properties, |
201 |
"dataport.data_service.outport_ref") |
202 |
if index < 0 then |
203 |
self._rtcout:RTC_ERROR("outport_ref not found") |
204 |
return false |
205 |
end |
206 |
|
207 |
local _obj = NVUtil.any_from_any(properties[index].value) |
208 |
|
209 |
local Manager = require "openrtm.Manager" |
210 |
local orb = Manager:instance():getORB() |
211 |
|
212 |
_obj = orb:narrow(_obj, "IDL:omg.org/RTC/DataPullService:1.0") |
213 |
|
214 |
|
215 |
if _obj == nil then |
216 |
self._rtcout:RTC_ERROR("prop[outport_ref] is not objref") |
217 |
return false |
218 |
end |
219 |
|
220 |
|
221 |
if not self:setObject(obj) then |
222 |
self._rtcout:RTC_ERROR("Setting object to consumer failed.") |
223 |
return false |
224 |
end |
225 |
|
226 |
return true |
227 |
end |
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
function obj:unsubscribeFromIor(properties) |
237 |
self._rtcout:RTC_TRACE("unsubscribeFromIor()") |
238 |
local index = NVUtil.find_index(properties, |
239 |
"dataport.data_service.outport_ior") |
240 |
if index < 0 then |
241 |
self._rtcout:RTC_ERROR("outport_ior not found") |
242 |
return false |
243 |
end |
244 |
|
245 |
|
246 |
ior = NVUtil.any_from_any(properties[index].value) |
247 |
|
248 |
|
249 |
if ior == "" then |
250 |
self._rtcout:RTC_ERROR("prop[outport_ior] is not string") |
251 |
return false |
252 |
end |
253 |
|
254 |
local Manager = require "openrtm.Manager" |
255 |
local orb = Manager:instance():getORB() |
256 |
local var = RTCUtil.newproxy(orb, ior,"IDL:omg.org/RTC/DataPullService:1.0") |
257 |
|
258 |
if not NVUtil._is_equivalent(self:_ptr(true), var, self:_ptr(true).getObjRef, var.getObjRef) then |
259 |
self._rtcout:RTC_ERROR("connector property inconsistency") |
260 |
return false |
261 |
end |
262 |
|
263 |
self:releaseObject() |
264 |
return true |
265 |
end |
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
function obj:unsubscribeFromRef(properties) |
273 |
self._rtcout:RTC_TRACE("unsubscribeFromRef()") |
274 |
local index = NVUtil.find_index(properties, |
275 |
"dataport.data_service.outport_ref") |
276 |
|
277 |
if index < 0 then |
278 |
return false |
279 |
end |
280 |
|
281 |
|
282 |
local _obj = NVUtil.any_from_any(properties[index].value) |
283 |
|
284 |
|
285 |
if obj == nil then |
286 |
return false |
287 |
end |
288 |
|
289 |
local obj_ptr = self:_ptr(true) |
290 |
|
291 |
if obj_ptr == nil or not NVUtil._is_equivalent(obj_ptr, obj, obj_ptr.getObjRef, obj.getObjRef) then |
292 |
return false |
293 |
end |
294 |
|
295 |
self:releaseObject() |
296 |
return true |
297 |
end |
298 |
|
299 |
|
300 |
function obj:convertReturn(status, data) |
301 |
if status == self._PortStatus.PORT_OK then |
302 |
|
303 |
return DataPortStatus.PORT_OK |
304 |
|
305 |
elseif status == self._PortStatus.PORT_ERROR then |
306 |
self:onSenderError() |
307 |
return DataPortStatus.PORT_ERROR |
308 |
|
309 |
elseif status == self._PortStatus.BUFFER_FULL then |
310 |
|
311 |
return DataPortStatus.BUFFER_FULL |
312 |
|
313 |
elseif status == self._PortStatus.BUFFER_EMPTY then |
314 |
self:onSenderEmpty() |
315 |
return DataPortStatus.BUFFER_EMPTY |
316 |
|
317 |
elseif status == self._PortStatus.BUFFER_TIMEOUT then |
318 |
self:onSenderTimeout() |
319 |
return DataPortStatus.BUFFER_TIMEOUT |
320 |
|
321 |
elseif status == self._PortStatus.UNKNOWN_ERROR then |
322 |
self:onSenderError() |
323 |
return DataPortStatus.UNKNOWN_ERROR |
324 |
|
325 |
else |
326 |
self:onSenderError() |
327 |
return DataPortStatus.UNKNOWN_ERROR |
328 |
end |
329 |
end |
330 |
|
331 |
|
332 |
|
333 |
function obj:onBufferWrite(data) |
334 |
if self._listeners ~= nil and self._profile ~= nil then |
335 |
self._listeners.connectorData_[ConnectorDataListenerType.ON_BUFFER_WRITE]:notify(self._profile, data) |
336 |
end |
337 |
end |
338 |
|
339 |
|
340 |
function obj:onBufferFull(data) |
341 |
if self._listeners ~= nil and self._profile ~= nil then |
342 |
self._listeners.connectorData_[ConnectorDataListenerType.ON_BUFFER_FULL]:notify(self._profile, data) |
343 |
end |
344 |
end |
345 |
|
346 |
|
347 |
function obj:onReceived(data) |
348 |
if self._listeners ~= nil and self._profile ~= nil then |
349 |
self._listeners.connectorData_[ConnectorDataListenerType.ON_RECEIVED]:notify(self._profile, data) |
350 |
end |
351 |
end |
352 |
|
353 |
|
354 |
function obj:onReceiverFull(data) |
355 |
if self._listeners ~= nil and self._profile ~= nil then |
356 |
self._listeners.connectorData_[ConnectorDataListenerType.ON_RECEIVER_FULL]:notify(self._profile, data) |
357 |
end |
358 |
end |
359 |
|
360 |
|
361 |
function obj:onSenderEmpty(data) |
362 |
if self._listeners ~= nil and self._profile ~= nil then |
363 |
self._listeners.connector_[ConnectorListenerType.ON_SENDER_EMPTY]:notify(self._profile) |
364 |
end |
365 |
end |
366 |
|
367 |
|
368 |
function obj:onSenderTimeout(data) |
369 |
if self._listeners ~= nil and self._profile ~= nil then |
370 |
self._listeners.connector_[ConnectorListenerType.ON_SENDER_TIMEOUT]:notify(self._profile) |
371 |
end |
372 |
end |
373 |
|
374 |
|
375 |
function obj:onSenderError(data) |
376 |
if self._listeners ~= nil and self._profile ~= nil then |
377 |
self._listeners.connector_[ConnectorListenerType.ON_SENDER_ERROR]:notify(self._profile) |
378 |
end |
379 |
end |
380 |
|
381 |
return obj |
382 |
end |
383 |
|
384 |
|
385 |
OutPortDSConsumer.Init = function() |
386 |
OutPortConsumerFactory:instance():addFactory("data_service", |
387 |
OutPortDSConsumer.new, |
388 |
Factory.Delete) |
389 |
end |
390 |
|
391 |
|
392 |
return OutPortDSConsumer |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local PeriodicECSharedComposite = {} |
11 |
|
12 |
|
13 |
local oil = require "oil" |
14 |
local StringUtil = require "openrtm.StringUtil" |
15 |
local ConfigurationListener = require "openrtm.ConfigurationListener" |
16 |
local ConfigurationSetListener = ConfigurationListener.ConfigurationSetListener |
17 |
local SdoOrganization = require "openrtm.SdoOrganization" |
18 |
local Organization_impl = SdoOrganization.Organization_impl |
19 |
local RTCUtil = require "openrtm.RTCUtil" |
20 |
local RTObject = require "openrtm.RTObject" |
21 |
local ConfigurationListener = require "openrtm.ConfigurationListener" |
22 |
local ConfigurationSetListenerType = ConfigurationListener.ConfigurationSetListenerType |
23 |
local Factory = require "openrtm.Factory" |
24 |
local Properties = require "openrtm.Properties" |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
local periodicecsharedcomposite_spec = { |
30 |
["implementation_id"]="PeriodicECSharedComposite", |
31 |
["type_name"]="PeriodicECSharedComposite", |
32 |
["description"]="PeriodicECSharedComposite", |
33 |
["version"]="1.0", |
34 |
["vendor"]="jp.go.aist", |
35 |
["category"]="composite.PeriodicECShared", |
36 |
["activity_type"]="DataFlowComponent", |
37 |
["max_instance"]="0", |
38 |
["language"]="Python", |
39 |
["lang_type"]="script", |
40 |
["exported_ports"]="", |
41 |
["conf.default.members"]="", |
42 |
["conf.default.exported_ports"]=""} |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
function stringToStrVec(_type, _is) |
49 |
local p = StringUtil.split(_is, ",") |
50 |
return true, StringUtil.strip(p) |
51 |
end |
52 |
|
53 |
|
54 |
local setCallback = {} |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
setCallback.new = function(org) |
60 |
local obj = {} |
61 |
setmetatable(obj, {__index=ConfigurationSetListener.new()}) |
62 |
obj._org = org |
63 |
|
64 |
|
65 |
function obj:call(config_set) |
66 |
self._org:updateDelegatedPorts() |
67 |
end |
68 |
return obj |
69 |
end |
70 |
|
71 |
|
72 |
local addCallback = {} |
73 |
|
74 |
|
75 |
|
76 |
addCallback.new = function(org) |
77 |
local obj = {} |
78 |
setmetatable(obj, {__index=ConfigurationSetListener.new()}) |
79 |
obj._org = org |
80 |
|
81 |
|
82 |
function obj:call(config_set) |
83 |
self._org:updateDelegatedPorts() |
84 |
end |
85 |
return obj |
86 |
end |
87 |
|
88 |
|
89 |
local PeriodicECOrganization = {} |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
PeriodicECOrganization.new = function(rtobj) |
95 |
local obj = {} |
96 |
setmetatable(obj, {__index=Organization_impl.new(rtobj:getObjRef())}) |
97 |
obj._rtobj = rtobj |
98 |
obj._ec = nil |
99 |
obj._rtcMembers = {} |
100 |
local Manager = require "openrtm.Manager" |
101 |
obj._rtcout = Manager:instance():getLogbuf("rtobject.PeriodicECOrganization") |
102 |
obj._expPorts = {} |
103 |
obj:createRef() |
104 |
|
105 |
|
106 |
local Member = {} |
107 |
|
108 |
|
109 |
|
110 |
Member.new = function(rtobj) |
111 |
local obj = {} |
112 |
obj._rtobj = rtobj |
113 |
obj._profile = rtobj:get_component_profile() |
114 |
obj._eclist = rtobj:get_owned_contexts() |
115 |
obj._config = rtobj:get_configuration() |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
local call_func = function(self, x) |
122 |
self:swap(x) |
123 |
return self |
124 |
end |
125 |
|
126 |
setmetatable(obj, {__call=call_func}) |
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
function obj:swap(x) |
133 |
local rtobj = x._rtobj |
134 |
local profile = x._profile |
135 |
local eclist = x._eclist |
136 |
local config = x._config |
137 |
|
138 |
x._rtobj = self._rtobj |
139 |
x._profile = self._profile |
140 |
x._eclist = self._eclist |
141 |
x._config = self._config |
142 |
|
143 |
self._rtobj = rtobj |
144 |
self._profile = profile |
145 |
self._eclist = eclist |
146 |
self._config = config |
147 |
end |
148 |
return obj |
149 |
end |
150 |
|
151 |
|
152 |
obj._add_members = obj.add_members |
153 |
|
154 |
|
155 |
|
156 |
|
157 |
function obj:add_members(sdo_list) |
158 |
self._rtcout:RTC_DEBUG("add_members()") |
159 |
self:updateExportedPortsList() |
160 |
for k,sdo in ipairs(sdo_list) do |
161 |
local ret,dfc = self:sdoToDFC(sdo) |
162 |
if not ret then |
163 |
table.remove(sdo_list, StringUtil.table_index(sdo_list, sdo)) |
164 |
else |
165 |
|
166 |
local member = Member.new(dfc) |
167 |
self:stopOwnedEC(member) |
168 |
self:addOrganizationToTarget(member) |
169 |
self:addParticipantToEC(member) |
170 |
self:addPort(member, self._expPorts) |
171 |
table.insert(self._rtcMembers, member) |
172 |
end |
173 |
end |
174 |
local result = self:_add_members(sdo_list) |
175 |
return result |
176 |
end |
177 |
|
178 |
obj._set_members = obj.set_members |
179 |
|
180 |
|
181 |
|
182 |
|
183 |
function obj:set_members(sdo_list) |
184 |
self._rtcout:RTC_DEBUG("set_members()") |
185 |
self:removeAllMembers() |
186 |
self:updateExportedPortsList() |
187 |
|
188 |
for k,sdo in ipairs(sdo_list) do |
189 |
local ret,dfc = self:sdoToDFC(sdo) |
190 |
if not ret then |
191 |
table.remove(sdo_list, StringUtil.table_index(sdo_list, sdo)) |
192 |
else |
193 |
local member = Member.new(dfc) |
194 |
self:stopOwnedEC(member) |
195 |
self:addOrganizationToTarget(member) |
196 |
self:addParticipantToEC(member) |
197 |
self:addPort(member, self._expPorts) |
198 |
table.insert(self._rtcMembers, member) |
199 |
end |
200 |
end |
201 |
|
202 |
local result = self:_set_members(sdo_list) |
203 |
return result |
204 |
end |
205 |
|
206 |
obj._remove_member = obj.remove_member |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
function obj:remove_member(id) |
212 |
self._rtcout:RTC_DEBUG("remove_member(id = %s)", id) |
213 |
local rm_rtc = {} |
214 |
for k,member in ipairs(self._rtcMembers) do |
215 |
if tostring(id) == tostring(member._profile.instance_name) then |
216 |
self:removePort(member, self._expPorts) |
217 |
self._rtobj:getProperties():setProperty("conf.default.exported_ports", StringUtil.flatten(self._expPorts)) |
218 |
self:removeParticipantFromEC(member) |
219 |
self:removeOrganizationFromTarget(member) |
220 |
self:startOwnedEC(member) |
221 |
table.insert(rm_rtc, member) |
222 |
|
223 |
end |
224 |
end |
225 |
|
226 |
for k,m in ipairs(rm_rtc) do |
227 |
table.remove(self._rtcMembers, StringUtil.table_index(self._rtcMembers, m)) |
228 |
end |
229 |
|
230 |
local result = self:_remove_member(id) |
231 |
return result |
232 |
end |
233 |
|
234 |
|
235 |
function obj:removeAllMembers() |
236 |
self._rtcout:RTC_DEBUG("removeAllMembers()") |
237 |
self:updateExportedPortsList() |
238 |
for k,member in ipairs(self._rtcMembers) do |
239 |
|
240 |
self:removePort(member, self._expPorts) |
241 |
|
242 |
self:removeParticipantFromEC(member) |
243 |
|
244 |
self:removeOrganizationFromTarget(member) |
245 |
|
246 |
self:startOwnedEC(member) |
247 |
|
248 |
self:_remove_member(member._profile.instance_name) |
249 |
|
250 |
end |
251 |
self._rtcMembers = {} |
252 |
self._expPorts = {} |
253 |
end |
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
function obj:sdoToDFC(sdo) |
261 |
if sdo == oil.corba.idl.null then |
262 |
return false, nil |
263 |
end |
264 |
|
265 |
local Manager = require "openrtm.Manager" |
266 |
local orb = Manager:instance():getORB() |
267 |
local dfc = RTCUtil.newproxy(orb, sdo,"IDL:openrtm.aist.go.jp/OpenRTM/DataFlowComponent:1.0") |
268 |
|
269 |
if dfc == oil.corba.idl.null then |
270 |
return false, nil |
271 |
end |
272 |
|
273 |
return true, dfc |
274 |
end |
275 |
|
276 |
|
277 |
|
278 |
function obj:stopOwnedEC(member) |
279 |
local ecs = member._eclist |
280 |
for k,ec in ipairs(ecs) do |
281 |
ec:stop() |
282 |
end |
283 |
end |
284 |
|
285 |
|
286 |
|
287 |
function obj:startOwnedEC(member) |
288 |
local ecs = member._eclist |
289 |
for k,ec in ipairs(ecs) do |
290 |
ec:start() |
291 |
end |
292 |
end |
293 |
|
294 |
|
295 |
|
296 |
function obj:addOrganizationToTarget(member) |
297 |
local conf = member._config |
298 |
if conf == oil.corba.idl.null then |
299 |
return |
300 |
end |
301 |
|
302 |
conf:add_organization(self._objref) |
303 |
end |
304 |
|
305 |
|
306 |
|
307 |
function obj:removeOrganizationFromTarget(member) |
308 |
if member._config == oil.corba.idl.null then |
309 |
return |
310 |
end |
311 |
|
312 |
member._config:remove_organization(self._pId) |
313 |
end |
314 |
|
315 |
|
316 |
|
317 |
function obj:addParticipantToEC(member) |
318 |
if self._ec == oil.corba.idl.null or self._ec == nil then |
319 |
local ecs = self._rtobj:get_owned_contexts() |
320 |
if #ecs > 0 then |
321 |
self._ec = ecs[1] |
322 |
else |
323 |
return |
324 |
end |
325 |
|
326 |
end |
327 |
self:addRTCToEC(member._rtobj) |
328 |
end |
329 |
|
330 |
|
331 |
|
332 |
|
333 |
function obj:addRTCToEC(rtobj) |
334 |
|
335 |
|
336 |
local orglist = rtobj:get_owned_organizations() |
337 |
if #orglist == 0 then |
338 |
self._ec:add_component(rtobj) |
339 |
end |
340 |
|
341 |
for k,org in ipairs(orglist) do |
342 |
local sdos = org:get_members() |
343 |
for j,sdo in ipairs(sdos) do |
344 |
local ret,dfc = self:sdoToDFC(sdo) |
345 |
if not ret then |
346 |
else |
347 |
self:addRTCToEC(dfc) |
348 |
end |
349 |
end |
350 |
end |
351 |
end |
352 |
|
353 |
|
354 |
|
355 |
function obj:removeParticipantFromEC(member) |
356 |
if self._ec == oil.corba.idl.null or self._ec == nil then |
357 |
local ecs = self._rtobj:get_owned_contexts() |
358 |
if #ecs > 0 then |
359 |
self._ec = ecs[1] |
360 |
else |
361 |
self._rtcout:RTC_FATAL("no owned EC") |
362 |
end |
363 |
end |
364 |
|
365 |
self._ec:remove_component(member._rtobj) |
366 |
|
367 |
|
368 |
local orglist = member._rtobj:get_owned_organizations() |
369 |
|
370 |
|
371 |
for k,org in ipairs(orglist) do |
372 |
local sdos = org:get_members() |
373 |
for j,sdo in ipairs(sdos) do |
374 |
local ret,dfc = self:sdoToDFC(sdo) |
375 |
if not ret then |
376 |
else |
377 |
self._ec:remove_component(dfc) |
378 |
end |
379 |
end |
380 |
end |
381 |
end |
382 |
|
383 |
|
384 |
|
385 |
|
386 |
function obj:addPort(member, portlist) |
387 |
self._rtcout:RTC_TRACE("addPort(%s)", StringUtil.flatten(portlist)) |
388 |
if #portlist == 0 then |
389 |
return |
390 |
end |
391 |
|
392 |
local plist = member._profile.port_profiles |
393 |
|
394 |
for k,prof in ipairs(plist) do |
395 |
local port_name = prof.name |
396 |
|
397 |
self._rtcout:RTC_DEBUG("port_name: %s is in %s?", port_name,StringUtil.flatten(portlist)) |
398 |
if StringUtil.table_index(portlist, port_name) == -1 then |
399 |
self._rtcout:RTC_DEBUG("Not found: %s is in %s?", port_name,StringUtil.flatten(portlist)) |
400 |
else |
401 |
self._rtcout:RTC_DEBUG("Found: %s is in %s", port_name,StringUtil.flatten(portlist)) |
402 |
self._rtobj:addPortRef(prof.port_ref) |
403 |
self._rtcout:RTC_DEBUG("Port %s was delegated.", port_name) |
404 |
end |
405 |
end |
406 |
end |
407 |
|
408 |
|
409 |
|
410 |
|
411 |
function obj:removePort(member, portlist) |
412 |
self._rtcout:RTC_DEBUG("removePort()") |
413 |
if #portlist == 0 then |
414 |
return |
415 |
end |
416 |
|
417 |
local plist = member._profile.port_profiles |
418 |
|
419 |
for k,prof in ipairs(plist) do |
420 |
local port_name = prof.name |
421 |
|
422 |
self._rtcout:RTC_DEBUG("port_name: %s is in %s?", port_name,StringUtil.flatten(portlist)) |
423 |
if StringUtil.table_index(portlist, port_name) == -1 then |
424 |
self._rtcout:RTC_DEBUG("Not found: %s is in %s?", port_name,StringUtil.flatten(portlist)) |
425 |
else |
426 |
self._rtcout:RTC_DEBUG("Found: %s is in %s", port_name,StringUtil.flatten(portlist)) |
427 |
self._rtobj:removePortRef(prof.port_ref) |
428 |
table.remove(portlist, StringUtil.table_index(portlist, port_name)) |
429 |
self._rtcout:RTC_DEBUG("Port %s was deleted.", port_name) |
430 |
end |
431 |
end |
432 |
end |
433 |
|
434 |
|
435 |
function obj:updateExportedPortsList() |
436 |
local plist = self._rtobj:getProperties():getProperty("conf.default.exported_ports") |
437 |
if #plist > 0 then |
438 |
local p = StringUtil.split(plist, ",") |
439 |
self._expPorts = StringUtil.strip(p) |
440 |
end |
441 |
end |
442 |
|
443 |
|
444 |
function obj:updateDelegatedPorts() |
445 |
local oldPorts = self._expPorts |
446 |
local ports = self._rtobj:getProperties():getProperty("conf.default.exported_ports") |
447 |
local newPorts = StringUtil.split(ports, ",") |
448 |
|
449 |
|
450 |
local removedPorts = StringUtil.difference(oldPorts, newPorts) |
451 |
local createdPorts = StringUtil.difference(newPorts, oldPorts) |
452 |
|
453 |
self._rtcout:RTC_VERBOSE("old ports: %s", StringUtil.flatten(oldPorts)) |
454 |
self._rtcout:RTC_VERBOSE("new ports: %s", StringUtil.flatten(newPorts)) |
455 |
self._rtcout:RTC_VERBOSE("remove ports: %s", StringUtil.flatten(removedPorts)) |
456 |
self._rtcout:RTC_VERBOSE("add ports: %s", StringUtil.flatten(createdPorts)) |
457 |
|
458 |
for k,member in ipairs(self._rtcMembers) do |
459 |
self:removePort(member, removedPorts) |
460 |
self:addPort(member, createdPorts) |
461 |
end |
462 |
|
463 |
self._expPorts = newPorts |
464 |
end |
465 |
|
466 |
return obj |
467 |
end |
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
PeriodicECSharedComposite.new = function(manager) |
474 |
local obj = {} |
475 |
setmetatable(obj, {__index=RTObject.new(manager)}) |
476 |
|
477 |
|
478 |
obj._members = {_value={}} |
479 |
obj:bindParameter("members", obj._members, " ", stringToStrVec) |
480 |
local Manager = require "openrtm.Manager" |
481 |
obj._rtcout = Manager:instance():getLogbuf("rtobject.periodic_ec_shared") |
482 |
|
483 |
|
484 |
|
485 |
|
486 |
obj._properties:setProperty("exec_cxt.periodic.sync_transition","NO") |
487 |
obj._properties:setProperty("exec_cxt.periodic.sync_activation","NO") |
488 |
obj._properties:setProperty("exec_cxt.periodic.sync_deactivation","NO") |
489 |
obj._properties:setProperty("exec_cxt.periodic.sync_reset","NO") |
490 |
|
491 |
local orb = Manager:instance():getORB() |
492 |
obj._ReturnCode_t = orb.types:lookup("::RTC::ReturnCode_t").labelvalue |
493 |
|
494 |
obj._shutdown = obj.shutdown |
495 |
|
496 |
function obj:shutdown() |
497 |
self:_shutdown() |
498 |
local Manager = require "openrtm.Manager" |
499 |
local orb = Manager:instance():getORB() |
500 |
|
501 |
orb:deactivate(self._org._svr) |
502 |
end |
503 |
|
504 |
|
505 |
|
506 |
|
507 |
function obj:onInitialize() |
508 |
self._rtcout:RTC_TRACE("onInitialize()") |
509 |
|
510 |
self._ref = self:getObjRef() |
511 |
self._objref = self._ref |
512 |
self._org = PeriodicECOrganization.new(self) |
513 |
table.insert(self._sdoOwnedOrganizations, self._org:getObjRef()) |
514 |
|
515 |
self._configsets:addConfigurationSetListener( |
516 |
ConfigurationSetListenerType.ON_SET_CONFIG_SET, |
517 |
setCallback.new(self._org)) |
518 |
|
519 |
self._configsets:addConfigurationSetListener( |
520 |
ConfigurationSetListenerType.ON_ADD_CONFIG_SET, |
521 |
addCallback.new(self._org)) |
522 |
|
523 |
|
524 |
local active_set = self._properties:getProperty("configuration.active_config", |
525 |
"default") |
526 |
|
527 |
if self._configsets:haveConfig(active_set) then |
528 |
self._configsets:update(active_set) |
529 |
else |
530 |
self._configsets:update("default") |
531 |
end |
532 |
local Manager = require "openrtm.Manager" |
533 |
local mgr = Manager:instance() |
534 |
local sdos = {} |
535 |
for k,member in ipairs(self._members._value) do |
536 |
member = string.gsub(member, "|","") |
537 |
|
538 |
member = StringUtil.eraseHeadBlank(member) |
539 |
if member == "" then |
540 |
else |
541 |
local rtc = mgr:getComponent(member) |
542 |
if rtc == nil then |
543 |
print("no RTC found: ", member) |
544 |
else |
545 |
sdo = rtc:getObjRef() |
546 |
if sdo == oil.corba.idl.null then |
547 |
else |
548 |
table.insert(sdos, sdo) |
549 |
end |
550 |
end |
551 |
end |
552 |
end |
553 |
local success, exception = oil.pcall( |
554 |
function() |
555 |
self._org:set_members(sdos) |
556 |
end) |
557 |
|
558 |
if not success then |
559 |
self._rtcout:RTC_ERROR(exception) |
560 |
end |
561 |
|
562 |
|
563 |
return self._ReturnCode_t.RTC_OK |
564 |
end |
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
function obj:onActivated(exec_handle) |
571 |
self._rtcout:RTC_TRACE("onActivated(%d)", exec_handle) |
572 |
local sdos = self._org:get_members() |
573 |
|
574 |
for k,sdo in ipairs(sdos) do |
575 |
local Manager = require "openrtm.Manager" |
576 |
local orb = Manager:instance():getORB() |
577 |
local rtc = RTCUtil.newproxy(orb, sdo,"IDL:omg.org/RTC/RTObject:1.0") |
578 |
|
579 |
self:activateChildComp(rtc) |
580 |
end |
581 |
|
582 |
local len_ = #self._members._value |
583 |
|
584 |
local str_ = "" |
585 |
if len_ > 1 then |
586 |
str_ = "s were" |
587 |
else |
588 |
str_ = "was" |
589 |
end |
590 |
|
591 |
self._rtcout:RTC_DEBUG("%d member RTC%s activated.", len_, str_) |
592 |
|
593 |
return self._ReturnCode_t.RTC_OK |
594 |
end |
595 |
|
596 |
|
597 |
|
598 |
|
599 |
function obj:activateChildComp(rtobj) |
600 |
local ecs = self:get_owned_contexts() |
601 |
|
602 |
local orglist = rtobj:get_owned_organizations() |
603 |
|
604 |
if #orglist == 0 then |
605 |
ecs[1]:activate_component(rtobj) |
606 |
end |
607 |
|
608 |
for k,org in ipairs(orglist) do |
609 |
local child_sdos = org:get_members() |
610 |
for j,child_sdo in ipairs(child_sdos) do |
611 |
local Manager = require "openrtm.Manager" |
612 |
local orb = Manager:instance():getORB() |
613 |
local child = RTCUtil.newproxy(orb, child_sdo,"IDL:omg.org/RTC/RTObject:1.0") |
614 |
self:activateChildComp(child) |
615 |
end |
616 |
end |
617 |
|
618 |
end |
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
function obj:onDeactivated(exec_handle) |
625 |
self._rtcout:RTC_TRACE("onDeactivated(%d)", exec_handle) |
626 |
local sdos = self._org:get_members() |
627 |
|
628 |
for k,sdo in ipairs(sdos) do |
629 |
local Manager = require "openrtm.Manager" |
630 |
local orb = Manager:instance():getORB() |
631 |
local rtc = RTCUtil.newproxy(orb, sdo,"IDL:omg.org/RTC/RTObject:1.0") |
632 |
|
633 |
self:deactivateChildComp(rtc) |
634 |
end |
635 |
|
636 |
return self._ReturnCode_t.RTC_OK |
637 |
end |
638 |
|
639 |
|
640 |
|
641 |
|
642 |
function obj:deactivateChildComp(rtobj) |
643 |
local ecs = self:get_owned_contexts() |
644 |
|
645 |
local orglist = rtobj:get_owned_organizations() |
646 |
if #orglist == 0 then |
647 |
ecs[1]:deactivate_component(rtobj) |
648 |
end |
649 |
|
650 |
for k,org in ipairs(orglist) do |
651 |
local child_sdos = org:get_members() |
652 |
for j,child_sdo in ipairs(child_sdos) do |
653 |
local Manager = require "openrtm.Manager" |
654 |
local orb = Manager:instance():getORB() |
655 |
local child = RTCUtil.newproxy(orb, child_sdo,"IDL:omg.org/RTC/RTObject:1.0") |
656 |
self:deactivateChildComp(child) |
657 |
end |
658 |
end |
659 |
|
660 |
end |
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
function obj:onReset(exec_handle) |
668 |
self._rtcout:RTC_TRACE("onReset(%d)", exec_handle) |
669 |
local sdos = self._org:get_members() |
670 |
|
671 |
for k,sdo in ipairs(sdos) do |
672 |
local Manager = require "openrtm.Manager" |
673 |
local orb = Manager:instance():getORB() |
674 |
local rtc = RTCUtil.newproxy(orb, sdo,"IDL:omg.org/RTC/RTObject:1.0") |
675 |
|
676 |
self:resetChildComp(rtc) |
677 |
end |
678 |
|
679 |
return self._ReturnCode_t.RTC_OK |
680 |
end |
681 |
|
682 |
|
683 |
|
684 |
|
685 |
function obj:resetChildComp(rtobj) |
686 |
local ecs = self:get_owned_contexts() |
687 |
|
688 |
local orglist = rtobj:get_owned_organizations() |
689 |
if #orglist == 0 then |
690 |
ecs[1]:reset_component(rtobj) |
691 |
end |
692 |
|
693 |
for k,org in ipairs(orglist) do |
694 |
local child_sdos = org:get_members() |
695 |
for j,child_sdo in ipairs(child_sdos) do |
696 |
local Manager = require "openrtm.Manager" |
697 |
local orb = Manager:instance():getORB() |
698 |
local child = RTCUtil.newproxy(orb, child_sdo,"IDL:omg.org/RTC/RTObject:1.0") |
699 |
self:resetChildComp(child) |
700 |
end |
701 |
end |
702 |
|
703 |
end |
704 |
|
705 |
|
706 |
|
707 |
|
708 |
function obj:onFinalize() |
709 |
self._rtcout:RTC_TRACE("onFinalize()") |
710 |
self._org:removeAllMembers() |
711 |
self._rtcout:RTC_PARANOID("onFinalize() done") |
712 |
return self._ReturnCode_t.RTC_OK |
713 |
end |
714 |
|
715 |
return obj |
716 |
end |
717 |
|
718 |
|
719 |
PeriodicECSharedComposite.Init = function(manager) |
720 |
local prof = Properties.new({defaults_map=periodicecsharedcomposite_spec}) |
721 |
manager:registerFactory(prof, |
722 |
PeriodicECSharedComposite.new, |
723 |
Factory.Delete) |
724 |
end |
725 |
|
726 |
|
727 |
return PeriodicECSharedComposite |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local RTObject= {} |
11 |
|
12 |
|
13 |
local oil = require "oil" |
14 |
local PortAdmin = require "openrtm.PortAdmin" |
15 |
local Properties = require "openrtm.Properties" |
16 |
local ConfigAdmin = require "openrtm.ConfigAdmin" |
17 |
local SdoServiceAdmin = require "openrtm.SdoServiceAdmin" |
18 |
local SdoConfiguration = require "openrtm.SdoConfiguration" |
19 |
local Configuration_impl = SdoConfiguration.Configuration_impl |
20 |
local ComponentActionListener = require "openrtm.ComponentActionListener" |
21 |
local ComponentActionListeners = ComponentActionListener.ComponentActionListeners |
22 |
local PortConnectListener = require "openrtm.PortConnectListener" |
23 |
local PortConnectListeners = PortConnectListener.PortConnectListeners |
24 |
local ManagerConfig = require "openrtm.ManagerConfig" |
25 |
local ExecutionContextBase = require "openrtm.ExecutionContextBase" |
26 |
local ExecutionContextFactory = ExecutionContextBase.ExecutionContextFactory |
27 |
local StringUtil = require "openrtm.StringUtil" |
28 |
local NVUtil = require "openrtm.NVUtil" |
29 |
local CORBA_SeqUtil = require "openrtm.CORBA_SeqUtil" |
30 |
local RTCUtil = require "openrtm.RTCUtil" |
31 |
local PreComponentActionListenerType = ComponentActionListener.PreComponentActionListenerType |
32 |
local PostComponentActionListenerType = ComponentActionListener.PostComponentActionListenerType |
33 |
local PortActionListenerType = ComponentActionListener.PortActionListenerType |
34 |
local ExecutionContextActionListenerType = ComponentActionListener.ExecutionContextActionListenerType |
35 |
local PreComponentActionListener = ComponentActionListener.PreComponentActionListener |
36 |
local PostComponentActionListener = ComponentActionListener.PostComponentActionListener |
37 |
local PortActionListener = ComponentActionListener.PortActionListener |
38 |
local ExecutionContextActionListener = ComponentActionListener.ExecutionContextActionListener |
39 |
local ComponentActionListeners = ComponentActionListener.ComponentActionListeners |
40 |
|
41 |
local uuid = require "uuid" |
42 |
|
43 |
|
44 |
RTObject.ECOTHER_OFFSET = 1000 |
45 |
|
46 |
|
47 |
local default_conf = { |
48 |
["implementation_id"]="", |
49 |
["type_name"]="", |
50 |
["description"]="", |
51 |
["version"]="", |
52 |
["vendor"]="", |
53 |
["category"]="", |
54 |
["activity_type"]="", |
55 |
["max_instance"]="", |
56 |
["language"]="", |
57 |
["lang_type"]="", |
58 |
["conf"]=""} |
59 |
|
60 |
|
61 |
|
62 |
local ec_copy = {} |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
ec_copy.new = function(eclist) |
68 |
local obj = {} |
69 |
obj._eclist = eclist |
70 |
|
71 |
|
72 |
|
73 |
local call_func = function(self, ecs) |
74 |
if ecs ~= nil then |
75 |
table.insert(self._eclist, ecs) |
76 |
end |
77 |
end |
78 |
setmetatable(obj, {__call=call_func}) |
79 |
return obj |
80 |
end |
81 |
|
82 |
|
83 |
|
84 |
local ec_find = {} |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
ec_find.new = function(_ec) |
90 |
local obj = {} |
91 |
obj._ec = _ec |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
local call_func = function(self, ecs) |
99 |
local ret = false |
100 |
local success, exception = oil.pcall( |
101 |
function() |
102 |
if ecs ~= nil then |
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
ret = NVUtil._is_equivalent(self._ec, ecs, self._ec.getObjRef, ecs.getObjRef) |
111 |
|
112 |
|
113 |
|
114 |
return |
115 |
end |
116 |
end) |
117 |
if not success then |
118 |
print(exception) |
119 |
return false |
120 |
end |
121 |
|
122 |
return ret |
123 |
end |
124 |
setmetatable(obj, {__call=call_func}) |
125 |
return obj |
126 |
end |
127 |
|
128 |
|
129 |
local svc_name = function(_id) |
130 |
local obj = {} |
131 |
obj._id = _id |
132 |
|
133 |
local call_func = function(self, prof) |
134 |
return (self._id == prof.id) |
135 |
end |
136 |
setmetatable(obj, {__call=call_func}) |
137 |
return obj |
138 |
end |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
RTObject.new = function(manager) |
144 |
|
145 |
local obj = {} |
146 |
|
147 |
|
148 |
obj._manager = manager |
149 |
obj._orb = obj._manager:getORB() |
150 |
|
151 |
obj._portAdmin = PortAdmin.new(obj._manager:getORB()) |
152 |
obj._rtcout = obj._manager:getLogbuf("rtobject") |
153 |
obj._created = true |
154 |
obj._properties = Properties.new({defaults_map=default_conf}) |
155 |
|
156 |
obj._configsets = ConfigAdmin.new(obj._properties:getNode("conf")) |
157 |
obj._profile = {instance_name="",type_name="", |
158 |
description="description",version="0", vendor="", |
159 |
category="",port_profiles={}, |
160 |
parent=oil.corba.idl.null,properties={ |
161 |
{name="implementation_id",value=""}, {name="type_name",value=""}, |
162 |
{name="description",value=""},{name="version",value=""}, |
163 |
{name="vendor",value=""},{name="category",value=""}, |
164 |
{name="activity_type",value=""},{name="max_instance",value=""}, |
165 |
{name="language",value=""},{name="lang_type",value=""}, |
166 |
{name="instance_name",value=""} |
167 |
} |
168 |
} |
169 |
obj._sdoservice = SdoServiceAdmin.new(obj) |
170 |
obj._SdoConfigImpl = Configuration_impl.new(obj._configsets,obj._sdoservice) |
171 |
obj._SdoConfig = obj._SdoConfigImpl:getObjRef() |
172 |
obj._execContexts = {} |
173 |
|
174 |
obj._sdoOwnedOrganizations = {} |
175 |
obj._sdoSvcProfiles = {} |
176 |
obj._sdoOrganization = {} |
177 |
obj._sdoStatus = {} |
178 |
obj._ecMine = {} |
179 |
obj._ecOther = {} |
180 |
obj._eclist = {} |
181 |
obj._exiting = false |
182 |
obj._readAll = false |
183 |
obj._writeAll = false |
184 |
obj._readAllCompletion = false |
185 |
obj._writeAllCompletion = false |
186 |
obj._inports = {} |
187 |
obj._outports = {} |
188 |
obj._actionListeners = ComponentActionListeners.new() |
189 |
obj._portconnListeners = PortConnectListeners.new() |
190 |
obj._svr = nil |
191 |
|
192 |
obj._ReturnCode_t = obj._orb.types:lookup("::RTC::ReturnCode_t").labelvalue |
193 |
|
194 |
|
195 |
|
196 |
function obj:onInitialize() |
197 |
self._rtcout:RTC_TRACE("onInitialize()") |
198 |
return self._ReturnCode_t.RTC_OK |
199 |
end |
200 |
|
201 |
|
202 |
function obj:onFinalize() |
203 |
self._rtcout:RTC_TRACE("onFinalize()") |
204 |
return self._ReturnCode_t.RTC_OK |
205 |
end |
206 |
|
207 |
|
208 |
|
209 |
function obj:onStartup(ec_id) |
210 |
self._rtcout:RTC_TRACE("onStartup("..ec_id..")") |
211 |
return self._ReturnCode_t.RTC_OK |
212 |
end |
213 |
|
214 |
|
215 |
|
216 |
function obj:onShutdown(ec_id) |
217 |
self._rtcout:RTC_TRACE("onShutdown("..ec_id..")") |
218 |
return self._ReturnCode_t.RTC_OK |
219 |
end |
220 |
|
221 |
|
222 |
|
223 |
function obj:onActivated(ec_id) |
224 |
self._rtcout:RTC_TRACE("onActivated("..ec_id..")") |
225 |
return self._ReturnCode_t.RTC_OK |
226 |
end |
227 |
|
228 |
|
229 |
|
230 |
function obj:onDeactivated(ec_id) |
231 |
self._rtcout:RTC_TRACE("onDeactivated("..ec_id..")") |
232 |
return self._ReturnCode_t.RTC_OK |
233 |
end |
234 |
|
235 |
|
236 |
|
237 |
function obj:onExecute(ec_id) |
238 |
self._rtcout:RTC_TRACE("onExecute("..ec_id..")") |
239 |
return self._ReturnCode_t.RTC_OK |
240 |
end |
241 |
|
242 |
|
243 |
|
244 |
function obj:onAborting(ec_id) |
245 |
self._rtcout:RTC_TRACE("onAborting("..ec_id..")") |
246 |
return self._ReturnCode_t.RTC_OK |
247 |
end |
248 |
|
249 |
|
250 |
|
251 |
function obj:onError(ec_id) |
252 |
self._rtcout:RTC_TRACE("onError("..ec_id..")") |
253 |
return self._ReturnCode_t.RTC_OK |
254 |
end |
255 |
|
256 |
|
257 |
|
258 |
function obj:onReset(ec_id) |
259 |
self._rtcout:RTC_TRACE("onReset("..ec_id..")") |
260 |
return self._ReturnCode_t.RTC_OK |
261 |
end |
262 |
|
263 |
|
264 |
|
265 |
function obj:onStateUpdate(ec_id) |
266 |
self._rtcout:RTC_TRACE("onStateUpdate("..ec_id..")") |
267 |
return self._ReturnCode_t.RTC_OK |
268 |
end |
269 |
|
270 |
|
271 |
|
272 |
function obj:onRateChanged(ec_id) |
273 |
self._rtcout:RTC_TRACE("onRateChanged("..ec_id..")") |
274 |
return self._ReturnCode_t.RTC_OK |
275 |
end |
276 |
|
277 |
|
278 |
function obj:initialize() |
279 |
self._rtcout:RTC_TRACE("initialize()") |
280 |
self:createRef() |
281 |
local ec_args_ = {} |
282 |
if self:getContextOptions(ec_args_) ~= self._ReturnCode_t.RTC_OK then |
283 |
self._rtcout:RTC_ERROR("Valid EC options are not available. Aborting") |
284 |
return self._ReturnCode_t.BAD_PARAMETER |
285 |
end |
286 |
if self:createContexts(ec_args_) ~= self._ReturnCode_t.RTC_OK then |
287 |
self._rtcout:RTC_ERROR("EC creation failed. Maybe out of resources. Aborting.") |
288 |
return self._ReturnCode_t.BAD_PARAMETER |
289 |
end |
290 |
|
291 |
local ret_ = self:on_initialize() |
292 |
self._created = false |
293 |
if ret_ ~= self._ReturnCode_t.RTC_OK then |
294 |
self._rtcout:RTC_ERROR("on_initialize() failed.") |
295 |
return ret_ |
296 |
end |
297 |
self._rtcout:RTC_DEBUG("on_initialize() was properly done.") |
298 |
for idx_, ec_ in ipairs(self._ecMine) do |
299 |
self._rtcout:RTC_DEBUG("EC"..idx_.." starting.") |
300 |
ec_:start() |
301 |
end |
302 |
self._sdoservice:init(self) |
303 |
return self._ReturnCode_t.RTC_OK |
304 |
end |
305 |
|
306 |
|
307 |
function obj:finalize() |
308 |
self._rtcout:RTC_TRACE("finalize()") |
309 |
if self._created or not self._exiting then |
310 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
311 |
end |
312 |
if #self._ecOther ~= 0 then |
313 |
self._ecOther = {} |
314 |
end |
315 |
local ret = self:on_finalize() |
316 |
self:shutdown() |
317 |
return ret |
318 |
end |
319 |
|
320 |
|
321 |
function obj:getProperties() |
322 |
self._rtcout:RTC_TRACE("getProperties()") |
323 |
return self._properties |
324 |
end |
325 |
|
326 |
|
327 |
function obj:getInstanceName() |
328 |
self._rtcout:RTC_TRACE("getInstanceName()") |
329 |
return self._profile.instance_name |
330 |
end |
331 |
|
332 |
|
333 |
function obj:setInstanceName(instance_name) |
334 |
self._rtcout:RTC_TRACE("setInstanceName("..instance_name..")") |
335 |
self._properties:setProperty("instance_name",instance_name) |
336 |
self._profile.instance_name = self._properties:getProperty("instance_name") |
337 |
end |
338 |
|
339 |
|
340 |
function obj:getTypeName() |
341 |
self._rtcout:RTC_TRACE("getTypeName()") |
342 |
return self._profile.type_name |
343 |
end |
344 |
|
345 |
|
346 |
function obj:getCategory() |
347 |
self._rtcout:RTC_TRACE("getCategory()") |
348 |
return self._profile.category |
349 |
end |
350 |
|
351 |
|
352 |
function obj:setProperties(prop) |
353 |
self._rtcout:RTC_TRACE("setProperties()") |
354 |
self._properties:mergeProperties(prop) |
355 |
self._profile.instance_name = self._properties:getProperty("instance_name") |
356 |
self._profile.type_name = self._properties:getProperty("type_name") |
357 |
self._profile.description = self._properties:getProperty("description") |
358 |
self._profile.version = self._properties:getProperty("version") |
359 |
self._profile.vendor = self._properties:getProperty("vendor") |
360 |
self._profile.category = self._properties:getProperty("category") |
361 |
end |
362 |
|
363 |
|
364 |
|
365 |
function obj:getObjRef() |
366 |
self._rtcout:RTC_TRACE("getObjRef()") |
367 |
return self._objref |
368 |
end |
369 |
|
370 |
|
371 |
|
372 |
|
373 |
function obj:getGlobalContextOptions(global_ec_props) |
374 |
self._rtcout:RTC_TRACE("getGlobalContextOptions()") |
375 |
|
376 |
local prop_ = self._properties:findNode("exec_cxt.periodic") |
377 |
if prop_ == nil then |
378 |
self._rtcout:RTC_WARN("No global EC options found.") |
379 |
return self._ReturnCode_t.RTC_ERROR |
380 |
end |
381 |
|
382 |
|
383 |
self._rtcout:RTC_DEBUG("Global EC options are specified.") |
384 |
self._rtcout:RTC_DEBUG(prop_) |
385 |
self:getInheritedECOptions(global_ec_props) |
386 |
global_ec_props:mergeProperties(prop_) |
387 |
return self._ReturnCode_t.RTC_OK |
388 |
end |
389 |
|
390 |
|
391 |
|
392 |
function obj:getPrivateContextOptions(ec_args) |
393 |
self._rtcout:RTC_TRACE("getPrivateContextOptions()") |
394 |
if not self._properties.findNode("execution_contexts") then |
395 |
self._rtcout:RTC_DEBUG("No component specific EC specified.") |
396 |
return self._ReturnCode_t.RTC_ERROR |
397 |
end |
398 |
return self._ReturnCode_t.RTC_OK |
399 |
end |
400 |
|
401 |
|
402 |
|
403 |
function obj:getInheritedECOptions(default_opts) |
404 |
self._rtcout:RTC_TRACE("getPrivateContextOptions()") |
405 |
return self._ReturnCode_t.RTC_OK |
406 |
end |
407 |
|
408 |
|
409 |
|
410 |
|
411 |
function obj:getContextOptions(ec_args) |
412 |
self._rtcout:RTC_DEBUG("getContextOptions()") |
413 |
local global_props_ = Properties.new() |
414 |
local ret_global_ = self:getGlobalContextOptions(global_props_) |
415 |
local ret_private_ = self:getPrivateContextOptions(ec_args) |
416 |
if ret_global_ ~= self._ReturnCode_t.RTC_OK and ret_private_ ~= self._ReturnCode_t.RTC_OK then |
417 |
return self._ReturnCode_t.RTC_ERROR |
418 |
end |
419 |
|
420 |
if ret_global_ == self._ReturnCode_t.RTC_OK and ret_private_ ~= self._ReturnCode_t.RTC_OK then |
421 |
table.insert(ec_args,global_props_) |
422 |
end |
423 |
return self._ReturnCode_t.RTC_OK |
424 |
end |
425 |
|
426 |
|
427 |
|
428 |
function obj:createContexts(ec_args) |
429 |
|
430 |
|
431 |
local ret_ = self._ReturnCode_t.RTC_OK |
432 |
local avail_ec_ = ExecutionContextFactory:instance():getIdentifiers() |
433 |
|
434 |
|
435 |
for i,ec_arg_ in ipairs(ec_args) do |
436 |
local ec_type_ = ec_arg_:getProperty("type") |
437 |
local ec_name_ = ec_arg_:getProperty("name") |
438 |
|
439 |
local ret_aec = false |
440 |
for i,aec in ipairs(avail_ec_) do |
441 |
|
442 |
if ec_type_ == aec then |
443 |
ret_aec = true |
444 |
|
445 |
break |
446 |
end |
447 |
end |
448 |
if not ret_aec then |
449 |
self._rtcout:RTC_WARN("EC "..ec_type_.." is not available.") |
450 |
self._rtcout:RTC_DEBUG("Available ECs: ".. |
451 |
StringUtil.flatten(avail_ec_)) |
452 |
else |
453 |
local ec_ = ExecutionContextFactory:instance():createObject(ec_type_) |
454 |
ec_:init(ec_arg_) |
455 |
table.insert(self._eclist, ec_) |
456 |
ec_:bindComponent(self) |
457 |
end |
458 |
end |
459 |
|
460 |
if #self._eclist == 0 then |
461 |
default_opts = Properties.new() |
462 |
ec_type_ = "PeriodicExecutionContext" |
463 |
local ec_ = ExecutionContextFactory:instance():createObject(ec_type_) |
464 |
ec_:init(default_opts) |
465 |
table.insert(self._eclist, ec_) |
466 |
ec_:bindComponent(self) |
467 |
end |
468 |
return ret_ |
469 |
end |
470 |
|
471 |
|
472 |
function obj:on_initialize() |
473 |
self._rtcout:RTC_TRACE("on_initialize()") |
474 |
local ret = self._ReturnCode_t.RTC_ERROR |
475 |
local success, exception = oil.pcall( |
476 |
function() |
477 |
self:preOnInitialize(0) |
478 |
self._rtcout:RTC_DEBUG("Calling onInitialize().") |
479 |
ret = self:onInitialize() |
480 |
if ret ~= self._ReturnCode_t.RTC_OK then |
481 |
self._rtcout:RTC_ERROR("onInitialize() returns an ERROR ("..ret..")") |
482 |
else |
483 |
self._rtcout:RTC_DEBUG("onInitialize() succeeded.") |
484 |
end |
485 |
end) |
486 |
if not success then |
487 |
self._rtcout:RTC_ERROR(exception) |
488 |
ret = self._ReturnCode_t.RTC_ERROR |
489 |
end |
490 |
local active_set = self._properties:getProperty("configuration.active_config", |
491 |
"default") |
492 |
if self._configsets:haveConfig(active_set) then |
493 |
self._rtcout:RTC_DEBUG("Active configuration set: "..active_set.." exists.") |
494 |
self._configsets:activateConfigurationSet(active_set) |
495 |
self._configsets:update(active_set) |
496 |
self._rtcout:RTC_INFO("Initial active configuration set is "..active_set..".") |
497 |
else |
498 |
self._rtcout:RTC_DEBUG("Active configuration set: "..active_set.." does not exists.") |
499 |
self._configsets:activateConfigurationSet("default") |
500 |
self._configsets:update("default") |
501 |
self._rtcout:RTC_INFO("Initial active configuration set is default-set.") |
502 |
end |
503 |
self:postOnInitialize(0) |
504 |
return ret |
505 |
end |
506 |
|
507 |
|
508 |
|
509 |
|
510 |
function obj:bindContext(exec_context) |
511 |
|
512 |
self._rtcout:RTC_TRACE("bindContext()") |
513 |
if exec_context == nil then |
514 |
return -1 |
515 |
end |
516 |
for i =1,#self._ecMine do |
517 |
if self._ecMine[i] == nil then |
518 |
self._ecMine[i] = exec_context |
519 |
self:onAttachExecutionContext(i) |
520 |
return i-1 |
521 |
end |
522 |
end |
523 |
table.insert(self._ecMine, exec_context) |
524 |
return #self._ecMine - 1 |
525 |
end |
526 |
|
527 |
|
528 |
|
529 |
function obj:on_startup(ec_id) |
530 |
self._rtcout:RTC_TRACE("on_startup("..ec_id..")") |
531 |
local ret = self._ReturnCode_t.RTC_ERROR |
532 |
local success, exception = oil.pcall( |
533 |
function() |
534 |
self:preOnStartup(ec_id) |
535 |
ret = self:onStartup(ec_id) |
536 |
end) |
537 |
if not success then |
538 |
self._rtcout:RTC_ERROR(exception) |
539 |
ret = self._ReturnCode_t.RTC_ERROR |
540 |
end |
541 |
self:postOnStartup(ec_id, ret) |
542 |
return ret |
543 |
end |
544 |
|
545 |
|
546 |
|
547 |
function obj:on_shutdown(ec_id) |
548 |
self._rtcout:RTC_TRACE("on_shutdown("..ec_id..")") |
549 |
local ret = self._ReturnCode_t.RTC_ERROR |
550 |
local success, exception = oil.pcall( |
551 |
function() |
552 |
self:preOnShutdown(ec_id) |
553 |
ret = self:onShutdown(ec_id) |
554 |
end) |
555 |
if not success then |
556 |
self._rtcout:RTC_ERROR(exception) |
557 |
ret = self._ReturnCode_t.RTC_ERROR |
558 |
end |
559 |
self:postOnShutdown(ec_id, ret) |
560 |
return ret |
561 |
end |
562 |
|
563 |
|
564 |
|
565 |
function obj:on_activated(ec_id) |
566 |
self._rtcout:RTC_TRACE("on_activated("..ec_id..")") |
567 |
local ret = self._ReturnCode_t.RTC_ERROR |
568 |
|
569 |
local success, exception = oil.pcall( |
570 |
function() |
571 |
self:preOnActivated(ec_id) |
572 |
self._configsets:update() |
573 |
ret = self:onActivated(ec_id) |
574 |
self._portAdmin:activatePorts() |
575 |
end) |
576 |
if not success then |
577 |
|
578 |
self._rtcout:RTC_ERROR(exception) |
579 |
ret = self._ReturnCode_t.RTC_ERROR |
580 |
end |
581 |
self:postOnActivated(ec_id, ret) |
582 |
|
583 |
return ret |
584 |
end |
585 |
|
586 |
|
587 |
|
588 |
function obj:on_deactivated(ec_id) |
589 |
self._rtcout:RTC_TRACE("on_deactivated("..ec_id..")") |
590 |
local ret = self._ReturnCode_t.RTC_ERROR |
591 |
local success, exception = oil.pcall( |
592 |
function() |
593 |
self:preOnDeactivated(ec_id) |
594 |
self._portAdmin:deactivatePorts() |
595 |
ret = self:onDeactivated(ec_id) |
596 |
end) |
597 |
if not success then |
598 |
self._rtcout:RTC_ERROR(exception) |
599 |
ret = self._ReturnCode_t.RTC_ERROR |
600 |
end |
601 |
self:postOnDeactivated(ec_id, ret) |
602 |
return ret |
603 |
end |
604 |
|
605 |
|
606 |
|
607 |
function obj:on_aborting(ec_id) |
608 |
self._rtcout:RTC_TRACE("on_aborting("..ec_id..")") |
609 |
local ret = self._ReturnCode_t.RTC_ERROR |
610 |
local success, exception = oil.pcall( |
611 |
function() |
612 |
self:preOnAborting(ec_id) |
613 |
ret = self:onAborting(ec_id) |
614 |
end) |
615 |
if not success then |
616 |
self._rtcout:RTC_ERROR(exception) |
617 |
ret = self._ReturnCode_t.RTC_ERROR |
618 |
end |
619 |
self:postOnAborting(ec_id, ret) |
620 |
return ret |
621 |
end |
622 |
|
623 |
|
624 |
|
625 |
function obj:on_error(ec_id) |
626 |
self._rtcout:RTC_TRACE("on_error("..ec_id..")") |
627 |
local ret = self._ReturnCode_t.RTC_ERROR |
628 |
local success, exception = oil.pcall( |
629 |
function() |
630 |
self:preOnError(ec_id) |
631 |
ret = self:onError(ec_id) |
632 |
end) |
633 |
if not success then |
634 |
self._rtcout:RTC_ERROR(exception) |
635 |
ret = self._ReturnCode_t.RTC_ERROR |
636 |
end |
637 |
self._configsets:update() |
638 |
self:postOnError(ec_id, ret) |
639 |
return ret |
640 |
end |
641 |
|
642 |
|
643 |
|
644 |
function obj:on_reset(ec_id) |
645 |
self._rtcout:RTC_TRACE("on_reset("..ec_id..")") |
646 |
local ret = self._ReturnCode_t.RTC_ERROR |
647 |
local success, exception = oil.pcall( |
648 |
function() |
649 |
self:preOnReset(ec_id) |
650 |
ret = self:onReset(ec_id) |
651 |
end) |
652 |
if not success then |
653 |
self._rtcout:RTC_ERROR(exception) |
654 |
ret = self._ReturnCode_t.RTC_ERROR |
655 |
end |
656 |
self:postOnReset(ec_id, ret) |
657 |
return ret |
658 |
end |
659 |
|
660 |
|
661 |
|
662 |
function obj:on_execute(ec_id) |
663 |
self._rtcout:RTC_TRACE("on_execute("..ec_id..")") |
664 |
local ret = self._ReturnCode_t.RTC_ERROR |
665 |
local success, exception = oil.pcall( |
666 |
function() |
667 |
if self._readAll then |
668 |
self:readAll() |
669 |
end |
670 |
self:preOnExecute(ec_id) |
671 |
ret = self:onExecute(ec_id) |
672 |
if self._writeAll then |
673 |
self:writeAll() |
674 |
end |
675 |
end) |
676 |
if not success then |
677 |
self._rtcout:RTC_ERROR(exception) |
678 |
ret = self._ReturnCode_t.RTC_ERROR |
679 |
end |
680 |
self:postOnExecute(ec_id, ret) |
681 |
return ret |
682 |
end |
683 |
|
684 |
|
685 |
|
686 |
function obj:on_state_update(ec_id) |
687 |
self._rtcout:RTC_TRACE("on_state_update("..ec_id..")") |
688 |
local ret = self._ReturnCode_t.RTC_ERROR |
689 |
local success, exception = oil.pcall( |
690 |
function() |
691 |
self:preOnStateUpdate(ec_id) |
692 |
ret = self:onStateUpdate(ec_id) |
693 |
self._configsets:update() |
694 |
end) |
695 |
if not success then |
696 |
self._rtcout:RTC_ERROR(exception) |
697 |
ret = self._ReturnCode_t.RTC_ERROR |
698 |
end |
699 |
|
700 |
self:postOnStateUpdate(ec_id, ret) |
701 |
return ret |
702 |
end |
703 |
|
704 |
|
705 |
|
706 |
function obj:on_rate_changed(ec_id) |
707 |
self._rtcout:RTC_TRACE("on_rate_changed("..ec_id..")") |
708 |
local ret = self._ReturnCode_t.RTC_ERROR |
709 |
local success, exception = oil.pcall( |
710 |
function() |
711 |
self:preOnRateChanged(ec_id) |
712 |
ret = self:onRateChanged(ec_id) |
713 |
end) |
714 |
if not success then |
715 |
self._rtcout:RTC_ERROR(exception) |
716 |
ret = self._ReturnCode_t.RTC_ERROR |
717 |
end |
718 |
self:postOnRateChanged(ec_id, ret) |
719 |
return ret |
720 |
end |
721 |
|
722 |
function obj:readAll() |
723 |
self._rtcout:RTC_TRACE("readAll()") |
724 |
end |
725 |
|
726 |
function obj:writeAll() |
727 |
self._rtcout:RTC_TRACE("writeAll()") |
728 |
end |
729 |
|
730 |
|
731 |
function obj:addPreComponentActionListener(listener_type, memfunc, autoclean) |
732 |
if autoclean == nil then |
733 |
autoclean = true |
734 |
end |
735 |
local Noname = {} |
736 |
|
737 |
Noname.new = function(memfunc) |
738 |
local _obj = {} |
739 |
setmetatable(_obj, {__index=ComponentActionListener.PreComponentActionListener.new()}) |
740 |
_obj._memfunc = memfunc |
741 |
function _obj:call(ec_id) |
742 |
self._memfunc(ec_id) |
743 |
end |
744 |
return _obj |
745 |
end |
746 |
|
747 |
listener = Noname.new(memfunc) |
748 |
self._actionListeners.preaction_[listener_type]:addListener(listener, autoclean) |
749 |
return listener |
750 |
end |
751 |
|
752 |
function obj:removePreComponentActionListener(listener_type, listener) |
753 |
self._actionListeners.preaction_[listener_type]:removeListener(listener) |
754 |
end |
755 |
|
756 |
|
757 |
function obj:addPostComponentActionListener(listener_type, memfunc, autoclean) |
758 |
if autoclean == nil then |
759 |
autoclean = true |
760 |
end |
761 |
local Noname = {} |
762 |
|
763 |
Noname.new = function(memfunc) |
764 |
local _obj = {} |
765 |
setmetatable(_obj, {__index=ComponentActionListener.PostComponentActionListener.new()}) |
766 |
_obj._memfunc = memfunc |
767 |
function _obj:call(ec_id) |
768 |
self._memfunc(ec_id) |
769 |
end |
770 |
return _obj |
771 |
end |
772 |
|
773 |
listener = Noname.new(memfunc) |
774 |
self._actionListeners.postaction_[listener_type]:addListener(listener, autoclean) |
775 |
return listener |
776 |
end |
777 |
|
778 |
function obj:removePostComponentActionListener(listener_type, listener) |
779 |
self._actionListeners.postaction_[listener_type]:removeListener(listener) |
780 |
end |
781 |
|
782 |
|
783 |
|
784 |
function obj:addPortActionListener(listener_type, memfunc, autoclean) |
785 |
if autoclean == nil then |
786 |
autoclean = true |
787 |
end |
788 |
local Noname = {} |
789 |
Noname.new = function(memfunc) |
790 |
local _obj = {} |
791 |
setmetatable(_obj, {__index=ComponentActionListener.PortActionListener.new()}) |
792 |
_obj._memfunc = memfunc |
793 |
function _obj:call(ec_id) |
794 |
self._memfunc(ec_id) |
795 |
end |
796 |
return _obj |
797 |
end |
798 |
|
799 |
listener = Noname.new(memfunc) |
800 |
self._actionListeners.portaction_[listener_type]:addListener(listener, autoclean) |
801 |
return listener |
802 |
end |
803 |
|
804 |
function obj:removePortActionListener(listener_type, listener) |
805 |
self._actionListeners.postaction_[listener_type]:removeListener(listener) |
806 |
end |
807 |
|
808 |
|
809 |
|
810 |
function obj:addExecutionContextActionListener(listener_type, memfunc, autoclean) |
811 |
if autoclean == nil then |
812 |
autoclean = true |
813 |
end |
814 |
local Noname = {} |
815 |
Noname.new = function(memfunc) |
816 |
local _obj = {} |
817 |
setmetatable(_obj, {__index=ComponentActionListener.ExecutionContextActionListener.new()}) |
818 |
_obj._memfunc = memfunc |
819 |
function _obj:call(ec_id) |
820 |
self._memfunc(ec_id) |
821 |
end |
822 |
return _obj |
823 |
end |
824 |
|
825 |
listener = Noname.new(memfunc) |
826 |
self._actionListeners.ecaction_[listener_type]:addListener(listener, autoclean) |
827 |
return listener |
828 |
end |
829 |
|
830 |
function obj:removeExecutionContextActionListener(listener_type, listener) |
831 |
self._actionListeners.ecaction_[listener_type]:removeListener(listener) |
832 |
end |
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
function obj:preOnInitialize(ec_id) |
839 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_INITIALIZE]:notify(ec_id) |
840 |
end |
841 |
|
842 |
|
843 |
function obj:preOnFinalize(ec_id) |
844 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_FINALIZE]:notify(ec_id) |
845 |
end |
846 |
|
847 |
|
848 |
function obj:preOnStartup(ec_id) |
849 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_STARTUP]:notify(ec_id) |
850 |
end |
851 |
|
852 |
|
853 |
function obj:preOnShutdown(ec_id) |
854 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_SHUTDOWN]:notify(ec_id) |
855 |
end |
856 |
|
857 |
|
858 |
function obj:preOnActivated(ec_id) |
859 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_ACTIVATED]:notify(ec_id) |
860 |
end |
861 |
|
862 |
|
863 |
function obj:preOnDeactivated(ec_id) |
864 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_DEACTIVATED]:notify(ec_id) |
865 |
end |
866 |
|
867 |
|
868 |
function obj:preOnAborting(ec_id) |
869 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_ABORTING]:notify(ec_id) |
870 |
end |
871 |
|
872 |
|
873 |
function obj:preOnError(ec_id) |
874 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_ERROR]:notify(ec_id) |
875 |
end |
876 |
|
877 |
|
878 |
function obj:preOnReset(ec_id) |
879 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_RESET]:notify(ec_id) |
880 |
end |
881 |
|
882 |
|
883 |
function obj:preOnExecute(ec_id) |
884 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_EXECUTE]:notify(ec_id) |
885 |
end |
886 |
|
887 |
|
888 |
function obj:preOnStateUpdate(ec_id) |
889 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_STATE_UPDATE]:notify(ec_id) |
890 |
end |
891 |
|
892 |
|
893 |
function obj:preOnRateChanged(ec_id) |
894 |
self._actionListeners.preaction_[PreComponentActionListenerType.PRE_ON_RATE_CHANGED]:notify(ec_id) |
895 |
end |
896 |
|
897 |
|
898 |
|
899 |
function obj:postOnInitialize(ec_id, ret) |
900 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_INITIALIZE]:notify(ec_id, ret) |
901 |
end |
902 |
|
903 |
|
904 |
function obj:postOnFinalize(ec_id, ret) |
905 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_FINALIZE]:notify(ec_id, ret) |
906 |
end |
907 |
|
908 |
|
909 |
function obj:postOnStartup(ec_id, ret) |
910 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_STARTUP]:notify(ec_id, ret) |
911 |
end |
912 |
|
913 |
|
914 |
function obj:postOnShutdown(ec_id, ret) |
915 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_SHUTDOWN]:notify(ec_id, ret) |
916 |
end |
917 |
|
918 |
|
919 |
function obj:postOnActivated(ec_id, ret) |
920 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_ACTIVATED]:notify(ec_id, ret) |
921 |
end |
922 |
|
923 |
|
924 |
function obj:postOnDeactivated(ec_id, ret) |
925 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_DEACTIVATED]:notify(ec_id, ret) |
926 |
end |
927 |
|
928 |
|
929 |
function obj:postOnAborting(ec_id, ret) |
930 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_ABORTING]:notify(ec_id, ret) |
931 |
end |
932 |
|
933 |
|
934 |
function obj:postOnError(ec_id, ret) |
935 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_ERROR]:notify(ec_id, ret) |
936 |
end |
937 |
|
938 |
|
939 |
function obj:postOnReset(ec_id, ret) |
940 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_RESET]:notify(ec_id, ret) |
941 |
end |
942 |
|
943 |
|
944 |
function obj:postOnExecute(ec_id, ret) |
945 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_EXECUTE]:notify(ec_id, ret) |
946 |
end |
947 |
|
948 |
|
949 |
function obj:postOnStateUpdate(ec_id, ret) |
950 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_STATE_UPDATE]:notify(ec_id, ret) |
951 |
end |
952 |
|
953 |
|
954 |
function obj:postOnRateChanged(ec_id, ret) |
955 |
self._actionListeners.postaction_[PostComponentActionListenerType.POST_ON_RATE_CHANGED]:notify(ec_id, ret) |
956 |
end |
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
function obj:bindParameter(param_name, var, def_val, trans) |
965 |
self._rtcout:RTC_TRACE("bindParameter()") |
966 |
if trans == nil then |
967 |
trans = StringUtil.stringTo |
968 |
end |
969 |
|
970 |
self._configsets:bindParameter(param_name, var, def_val, trans) |
971 |
return true |
972 |
end |
973 |
|
974 |
|
975 |
|
976 |
function obj:getConfigService() |
977 |
return self._configsets |
978 |
end |
979 |
|
980 |
|
981 |
|
982 |
function obj:updateParameters(config_set) |
983 |
self._rtcout:RTC_TRACE("updateParameters("..config_set..")") |
984 |
self._configsets:update(config_set) |
985 |
end |
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
function obj:getExecutionContext(ec_id) |
992 |
return self:get_context(ec_id) |
993 |
end |
994 |
|
995 |
|
996 |
|
997 |
|
998 |
function obj:get_context(ec_id) |
999 |
|
1000 |
self._rtcout:RTC_TRACE("get_context("..ec_id..")") |
1001 |
ec_id = ec_id + 1 |
1002 |
if ec_id < RTObject.ECOTHER_OFFSET then |
1003 |
if self._ecMine[ec_id] ~= nil then |
1004 |
return self._ecMine[ec_id] |
1005 |
else |
1006 |
return oil.corba.idl.null |
1007 |
end |
1008 |
end |
1009 |
|
1010 |
|
1011 |
local index = ec_id - ECOTHER_OFFSET |
1012 |
|
1013 |
if self._ecOther[index] ~= nil then |
1014 |
return self._ecOther[index] |
1015 |
end |
1016 |
|
1017 |
return oil.corba.idl.null |
1018 |
end |
1019 |
|
1020 |
|
1021 |
|
1022 |
function obj:get_owned_contexts() |
1023 |
self._rtcout:RTC_TRACE("get_owned_contexts()") |
1024 |
local execlist = {} |
1025 |
CORBA_SeqUtil.for_each(self._ecMine, ec_copy.new(execlist)) |
1026 |
|
1027 |
return execlist |
1028 |
end |
1029 |
|
1030 |
|
1031 |
|
1032 |
function obj:get_participating_contexts() |
1033 |
self._rtcout:RTC_TRACE("get_participating_contexts()") |
1034 |
local execlist = {} |
1035 |
CORBA_SeqUtil.for_each(self._ecOther, ec_copy.new(execlist)) |
1036 |
|
1037 |
return execlist |
1038 |
end |
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
function obj:get_context_handle(cxt) |
1044 |
self._rtcout:RTC_TRACE("get_context_handle()") |
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
local num = CORBA_SeqUtil.find(self._ecMine, ec_find.new(cxt)) |
1050 |
|
1051 |
if num ~= -1 then |
1052 |
return num-1 |
1053 |
end |
1054 |
|
1055 |
num = CORBA_SeqUtil.find(self._ecOther, ec_find.new(cxt)) |
1056 |
if num ~= -1 then |
1057 |
return num-1 + 1000 |
1058 |
end |
1059 |
|
1060 |
return -1 |
1061 |
end |
1062 |
|
1063 |
|
1064 |
|
1065 |
function obj:getNamingNames() |
1066 |
self._rtcout:RTC_TRACE("getNamingNames()") |
1067 |
|
1068 |
local ret_str = StringUtil.split(self._properties:getProperty("naming.names"), ",") |
1069 |
local ret = {} |
1070 |
for k, v in pairs(ret_str) do |
1071 |
v = StringUtil.eraseHeadBlank(v) |
1072 |
v = StringUtil.eraseTailBlank(v) |
1073 |
table.insert(ret, v) |
1074 |
end |
1075 |
return ret |
1076 |
end |
1077 |
|
1078 |
|
1079 |
|
1080 |
function obj:get_configuration() |
1081 |
self._rtcout:RTC_TRACE("get_configuration()") |
1082 |
if self._SdoConfig == nil then |
1083 |
error(self._orb:newexcept{"SDOPackage::InterfaceNotImplemented", |
1084 |
description="InterfaceNotImplemented: get_configuration" |
1085 |
}) |
1086 |
end |
1087 |
return self._SdoConfig |
1088 |
end |
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
function obj:addPort(port) |
1094 |
self._rtcout:RTC_TRACE("addPort()") |
1095 |
self._rtcout:RTC_TRACE("addPort(CorbaPort)") |
1096 |
local propkey = "port.corbaport." |
1097 |
local prop = self._properties:getNode(propkey) |
1098 |
if prop ~= nil then |
1099 |
self._properties:getNode(propkey):mergeProperties(self._properties:getNode("port.corba")) |
1100 |
end |
1101 |
|
1102 |
port:init(self._properties:getNode(propkey)) |
1103 |
port:setOwner(self) |
1104 |
|
1105 |
|
1106 |
return self._portAdmin:addPort(port) |
1107 |
end |
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
function obj:addPortRef(port) |
1113 |
return self._portAdmin:addPortRef(port) |
1114 |
end |
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
function obj:addInPort(name, inport) |
1123 |
self._rtcout:RTC_TRACE("addInPort("..name..")") |
1124 |
|
1125 |
local propkey = "port.inport."..name |
1126 |
local prop_ = Properties.new({prop=self._properties:getNode(propkey)}) |
1127 |
prop_:mergeProperties(self._properties:getNode("port.inport.dataport")) |
1128 |
inport:init(prop_) |
1129 |
|
1130 |
inport:setOwner(self) |
1131 |
inport:setPortConnectListenerHolder(self._portconnListeners) |
1132 |
self:onAddPort(inport:getPortProfile()) |
1133 |
|
1134 |
local ret = self._portAdmin:addPort(inport) |
1135 |
|
1136 |
if not ret then |
1137 |
self._rtcout:RTC_ERROR("addInPort() failed.") |
1138 |
return ret |
1139 |
end |
1140 |
|
1141 |
|
1142 |
table.insert(self._inports, inport) |
1143 |
|
1144 |
|
1145 |
return ret |
1146 |
end |
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 |
function obj:addOutPort(name, outport) |
1154 |
self._rtcout:RTC_TRACE("addOutPort("..name..")") |
1155 |
|
1156 |
local propkey = "port.outport."..name |
1157 |
local prop_ = Properties.new({prop=self._properties:getNode(propkey)}) |
1158 |
prop_:mergeProperties(self._properties:getNode("port.outport.dataport")) |
1159 |
outport:init(prop_) |
1160 |
|
1161 |
outport:setOwner(self) |
1162 |
outport:setPortConnectListenerHolder(self._portconnListeners) |
1163 |
self:onAddPort(outport:getPortProfile()) |
1164 |
|
1165 |
local ret = self._portAdmin:addPort(outport) |
1166 |
|
1167 |
if not ret then |
1168 |
self._rtcout:RTC_ERROR("addOutPort() failed.") |
1169 |
return ret |
1170 |
end |
1171 |
|
1172 |
|
1173 |
table.insert(self._outports, outport) |
1174 |
|
1175 |
|
1176 |
return ret |
1177 |
end |
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
function obj:removeInPort(port) |
1184 |
self._rtcout:RTC_TRACE("removeInPort()") |
1185 |
local ret = self:removePort(port) |
1186 |
|
1187 |
if ret ~= nil then |
1188 |
for i, inport in ipairs(self._inports) do |
1189 |
if port == inport then |
1190 |
table.remove(self._inports, i) |
1191 |
return true |
1192 |
end |
1193 |
end |
1194 |
end |
1195 |
return false |
1196 |
end |
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
function obj:removeOutPort(port) |
1203 |
self._rtcout:RTC_TRACE("removeOutPort()") |
1204 |
local ret = self:removePort(port) |
1205 |
|
1206 |
if ret ~= nil then |
1207 |
for i, outport in ipairs(self._outports) do |
1208 |
if port == outport then |
1209 |
table.remove(self._outports, i) |
1210 |
return true |
1211 |
end |
1212 |
end |
1213 |
end |
1214 |
return false |
1215 |
end |
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 |
function obj:removePort(port) |
1222 |
self._rtcout:RTC_TRACE("removePort()") |
1223 |
self:onRemovePort(port:getPortProfile()) |
1224 |
return self._portAdmin:removePort(port) |
1225 |
end |
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
function obj:removePortRef(port) |
1231 |
self._rtcout:RTC_TRACE("removePort()") |
1232 |
return self._portAdmin:removePortRef(port) |
1233 |
end |
1234 |
|
1235 |
|
1236 |
|
1237 |
function obj:get_component_profile() |
1238 |
self._rtcout:RTC_TRACE("get_component_profile()") |
1239 |
|
1240 |
local prop_ = {instance_name = self._properties:getProperty("instance_name"), |
1241 |
type_name = self._properties:getProperty("type_name"), |
1242 |
description = self._properties:getProperty("description"), |
1243 |
version = self._properties:getProperty("version"), |
1244 |
vendor = self._properties:getProperty("vendor"), |
1245 |
category = self._properties:getProperty("category"), |
1246 |
port_profiles = self._portAdmin:getPortProfileList(), |
1247 |
parent = self._profile.parent, |
1248 |
properties = self._profile.properties} |
1249 |
NVUtil.copyFromProperties(self._profile.properties, self._properties) |
1250 |
|
1251 |
return prop_ |
1252 |
end |
1253 |
|
1254 |
|
1255 |
|
1256 |
function obj:onAddPort(pprof) |
1257 |
self._actionListeners.portaction_[PortActionListenerType.ADD_PORT]:notify(pprof) |
1258 |
end |
1259 |
|
1260 |
|
1261 |
function obj:onRemovePort(pprof) |
1262 |
self._actionListeners.portaction_[PortActionListenerType.REMOVE_PORT]:notify(pprof) |
1263 |
end |
1264 |
|
1265 |
|
1266 |
function obj:onAttachExecutionContext(ec_id) |
1267 |
|
1268 |
self._actionListeners.ecaction_[ExecutionContextActionListenerType.EC_ATTACHED]:notify(ec_id) |
1269 |
end |
1270 |
|
1271 |
|
1272 |
function obj:onDetachExecutionContext(pprof) |
1273 |
self._actionListeners.ecaction_[ExecutionContextActionListenerType.EC_DETACHED]:notify(ec_id) |
1274 |
end |
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 |
function obj:is_alive(exec_context) |
1280 |
self._rtcout:RTC_TRACE("is_alive()") |
1281 |
|
1282 |
for i, ec in ipairs(self._ecMine) do |
1283 |
|
1284 |
local Manager = require "openrtm.Manager" |
1285 |
local orb = Manager:instance():getORB() |
1286 |
|
1287 |
if NVUtil._is_equivalent(exec_context, ec, exec_context.getObjRef, ec.getObjRef) then |
1288 |
return true |
1289 |
end |
1290 |
end |
1291 |
|
1292 |
|
1293 |
for i, ec in ipairs(self._ecOther) do |
1294 |
if ec == nil then |
1295 |
if NVUtil._is_equivalent(exec_context, ec, exec_context.getObjRef, ec.getObjRef) then |
1296 |
return true |
1297 |
end |
1298 |
end |
1299 |
end |
1300 |
|
1301 |
return false |
1302 |
end |
1303 |
|
1304 |
|
1305 |
|
1306 |
function obj:exit() |
1307 |
self._rtcout:RTC_TRACE("exit()") |
1308 |
if self._created then |
1309 |
return self._ReturnCode_t.PRECONDITION_NOT_MET |
1310 |
end |
1311 |
if self._exiting then |
1312 |
return self._ReturnCode_t.RTC_OK |
1313 |
end |
1314 |
|
1315 |
for i, ec in ipairs(self._ecOther) do |
1316 |
if not NVUtil._non_existent(ec) then |
1317 |
ec:remove_component(self:getObjRef()) |
1318 |
end |
1319 |
end |
1320 |
|
1321 |
self._exiting = true |
1322 |
return self:finalize() |
1323 |
end |
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
function obj:attach_context(exec_context) |
1329 |
local ECOTHER_OFFSET = RTObject.ECOTHER_OFFSET |
1330 |
self._rtcout:RTC_TRACE("attach_context()") |
1331 |
|
1332 |
local ecs = exec_context |
1333 |
if ecs == oil.corba.idl.null then |
1334 |
return -1 |
1335 |
end |
1336 |
|
1337 |
|
1338 |
for i,oec in ipairs(self._ecOther) do |
1339 |
if oec == oil.corba.idl.null then |
1340 |
self._ecOther[i] = ecs |
1341 |
local ec_id = i + ECOTHER_OFFSET |
1342 |
self:onAttachExecutionContext(ec_id) |
1343 |
return ec_id |
1344 |
end |
1345 |
end |
1346 |
table.insert(self._ecOther,ecs) |
1347 |
local ec_id = tonumber(#self._ecOther - 1 + ECOTHER_OFFSET) |
1348 |
self:onAttachExecutionContext(ec_id) |
1349 |
return ec_id |
1350 |
end |
1351 |
|
1352 |
|
1353 |
|
1354 |
function obj:detach_context(ec_id) |
1355 |
ec_id = ec_id + 1 |
1356 |
local ECOTHER_OFFSET = RTObject.ECOTHER_OFFSET |
1357 |
self._rtcout:RTC_TRACE("detach_context(%d)", ec_id) |
1358 |
local len_ = #self._ecOther |
1359 |
|
1360 |
if (tonumber(ec_id) < tonumber(ECOTHER_OFFSET)) or (tonumber(ec_id - ECOTHER_OFFSET) > len_) then |
1361 |
return self._ReturnCode_t.BAD_PARAMETER |
1362 |
end |
1363 |
|
1364 |
local index = tonumber(ec_id - ECOTHER_OFFSET) |
1365 |
|
1366 |
if index < 0 or self._ecOther[index] == oil.corba.idl.null then |
1367 |
return self._ReturnCode_t.BAD_PARAMETER |
1368 |
end |
1369 |
|
1370 |
|
1371 |
self._ecOther[index] = oil.corba.idl.null |
1372 |
self:onDetachExecutionContext(ec_id) |
1373 |
return self._ReturnCode_t.RTC_OK |
1374 |
end |
1375 |
|
1376 |
|
1377 |
|
1378 |
function obj:get_ports() |
1379 |
self._rtcout:RTC_TRACE("get_ports()") |
1380 |
return self._portAdmin:getPortServiceList() |
1381 |
end |
1382 |
|
1383 |
|
1384 |
function obj:createRef() |
1385 |
self._svr = self._orb:newservant(self, nil, "IDL:openrtm.aist.go.jp/OpenRTM/DataFlowComponent:1.0") |
1386 |
|
1387 |
self._objref = RTCUtil.getReference(self._orb, self._svr, "IDL:openrtm.aist.go.jp/OpenRTM/DataFlowComponent:1.0") |
1388 |
end |
1389 |
|
1390 |
|
1391 |
|
1392 |
function obj:on_finalize() |
1393 |
self._rtcout:RTC_TRACE("on_finalize()") |
1394 |
local ret = self._ReturnCode_t.RTC_ERROR |
1395 |
local success, exception = oil.pcall( |
1396 |
function() |
1397 |
self:preOnFinalize(0) |
1398 |
ret = self:onFinalize() |
1399 |
end) |
1400 |
if not success then |
1401 |
|
1402 |
self._rtcout:RTC_ERROR(exception) |
1403 |
ret = self._ReturnCode_t.RTC_ERROR |
1404 |
end |
1405 |
self:postOnFinalize(0, ret) |
1406 |
return ret |
1407 |
end |
1408 |
|
1409 |
|
1410 |
function obj:shutdown() |
1411 |
self._rtcout:RTC_TRACE("shutdown()") |
1412 |
local success, exception = oil.pcall( |
1413 |
function() |
1414 |
self:finalizePorts() |
1415 |
self:finalizeContexts() |
1416 |
|
1417 |
|
1418 |
self._SdoConfigImpl:deactivate() |
1419 |
if self._svr ~= nil then |
1420 |
self._orb:deactivate(self._svr) |
1421 |
end |
1422 |
self._sdoservice:exit() |
1423 |
end) |
1424 |
if not success then |
1425 |
|
1426 |
self._rtcout:RTC_ERROR(exception) |
1427 |
end |
1428 |
|
1429 |
if self._manager ~= nil then |
1430 |
self._rtcout:RTC_DEBUG("Cleanup on Manager") |
1431 |
self._manager:notifyFinalized(self) |
1432 |
end |
1433 |
|
1434 |
self._actionListeners = nil |
1435 |
self._portconnListeners = nil |
1436 |
|
1437 |
end |
1438 |
|
1439 |
|
1440 |
function obj:finalizePorts() |
1441 |
self._rtcout:RTC_TRACE("finalizePorts()") |
1442 |
self._portAdmin:finalizePorts() |
1443 |
self._inports = {} |
1444 |
self._outports = {} |
1445 |
end |
1446 |
|
1447 |
|
1448 |
function obj:finalizeContexts() |
1449 |
self._rtcout:RTC_TRACE("finalizeContexts()") |
1450 |
|
1451 |
for i,ec in ipairs(self._eclist) do |
1452 |
ec:stop() |
1453 |
local success, exception = oil.pcall( |
1454 |
function() |
1455 |
self._orb:deactivate(ec._svr) |
1456 |
end) |
1457 |
if not success then |
1458 |
end |
1459 |
ec:exit() |
1460 |
end |
1461 |
|
1462 |
self._eclist = {} |
1463 |
end |
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
function obj:addSdoServiceProvider(prof, provider) |
1470 |
return self._sdoservice:addSdoServiceProvider(prof, provider) |
1471 |
end |
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
function obj:removeSdoServiceProvider(id) |
1477 |
return self._sdoservice:removeSdoServiceProvider(id) |
1478 |
end |
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
function obj:addSdoServiceConsumer(prof) |
1484 |
return self._sdoservice:addSdoServiceConsumer(prof) |
1485 |
end |
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
function obj:removeSdoServiceConsumer(id) |
1491 |
return self._sdoservice:removeSdoServiceConsumer(id) |
1492 |
end |
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
function obj:get_sdo_service(_id) |
1499 |
self._rtcout:RTC_TRACE("get_sdo_service(%s)", _id) |
1500 |
self._sdoSvcProfiles = self._SdoConfigImpl:getServiceProfiles() |
1501 |
|
1502 |
if _id == "" then |
1503 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
1504 |
description="get_service(): Empty name." |
1505 |
}) |
1506 |
end |
1507 |
|
1508 |
local index = CORBA_SeqUtil.find(self._sdoSvcProfiles, svc_name(_id)) |
1509 |
|
1510 |
if index < 0 then |
1511 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
1512 |
description="get_service(): Not found" |
1513 |
}) |
1514 |
end |
1515 |
|
1516 |
|
1517 |
return self._sdoSvcProfiles[index].service |
1518 |
end |
1519 |
|
1520 |
|
1521 |
|
1522 |
function obj:get_owned_organizations() |
1523 |
self._rtcout:RTC_TRACE("get_owned_organizations()") |
1524 |
return self._sdoOwnedOrganizations |
1525 |
end |
1526 |
|
1527 |
|
1528 |
|
1529 |
function obj:get_sdo_id() |
1530 |
self._rtcout:RTC_TRACE("get_sdo_id()") |
1531 |
return self._profile.instance_name |
1532 |
end |
1533 |
|
1534 |
|
1535 |
|
1536 |
function obj:get_sdo_type() |
1537 |
self._rtcout:RTC_TRACE("get_sdo_type()") |
1538 |
return self._profile.description |
1539 |
end |
1540 |
|
1541 |
|
1542 |
|
1543 |
function obj:get_device_profile() |
1544 |
self._rtcout:RTC_TRACE("get_device_profile()") |
1545 |
return self._SdoConfigImpl:getDeviceProfile() |
1546 |
end |
1547 |
|
1548 |
|
1549 |
|
1550 |
function obj:get_service_profiles() |
1551 |
self._rtcout:RTC_TRACE("get_service_profiles()") |
1552 |
self._sdoSvcProfiles = self._SdoConfigImpl:getServiceProfiles() |
1553 |
return self._sdoSvcProfiles |
1554 |
end |
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
function obj:get_service_profile(_id) |
1560 |
self._rtcout:RTC_TRACE("get_service_profile(%s)", _id) |
1561 |
self._sdoSvcProfiles = self._SdoConfigImpl:getServiceProfiles() |
1562 |
if _id == "" then |
1563 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
1564 |
description="get_service_profile(): Empty name." |
1565 |
}) |
1566 |
end |
1567 |
local index = CORBA_SeqUtil.find(self._sdoSvcProfiles, svc_name(_id)) |
1568 |
|
1569 |
if index < 0 then |
1570 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
1571 |
description="get_service_profile(): Not found" |
1572 |
}) |
1573 |
end |
1574 |
|
1575 |
return self._sdoSvcProfiles[index] |
1576 |
end |
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
obj:setInstanceName(uuid()) |
1583 |
|
1584 |
return obj |
1585 |
end |
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
return RTObject |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local SdoConfiguration= {} |
11 |
|
12 |
|
13 |
local oil = require "oil" |
14 |
local NVUtil = require "openrtm.NVUtil" |
15 |
local Properties = require "openrtm.Properties" |
16 |
local RTCUtil = require "openrtm.RTCUtil" |
17 |
local CORBA_SeqUtil = require "openrtm.CORBA_SeqUtil" |
18 |
|
19 |
SdoConfiguration.Configuration_impl = {} |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
local toConfigurationSet = function(conf, prop) |
26 |
conf.description = prop:getProperty("description") |
27 |
conf.id = prop:getName() |
28 |
|
29 |
NVUtil.copyFromProperties(conf.configuration_data, prop) |
30 |
end |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
local toProperties = function(prop, conf) |
36 |
NVUtil.copyToProperties(prop, conf.configuration_data) |
37 |
end |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
SdoConfiguration.Configuration_impl.new = function(configAdmin, sdoServiceAdmin) |
44 |
local obj = {} |
45 |
|
46 |
obj._deviceProfile = {device_type="",manufacturer="",model="",version="",properties={}} |
47 |
obj._serviceProfiles = {} |
48 |
obj._parameters = {} |
49 |
obj._configsets = configAdmin |
50 |
obj._sdoservice = sdoServiceAdmin |
51 |
|
52 |
obj._organizations = {} |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
local Manager = require "openrtm.Manager" |
58 |
obj._orb = Manager:instance():getORB() |
59 |
obj._svr = obj._orb:newservant(obj, nil, "IDL:org.omg/SDOPackage/Configuration:1.0") |
60 |
obj._objref = RTCUtil.getReference(obj._orb, obj._svr, "IDL:org.omg/SDOPackage/Configuration:1.0") |
61 |
|
62 |
obj._rtcout = Manager:instance():getLogbuf("rtobject.sdo_config") |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
function obj:getObjRef() |
68 |
return self._objref |
69 |
end |
70 |
|
71 |
|
72 |
function obj:deactivate() |
73 |
local Manager = require "openrtm.Manager" |
74 |
Manager:instance():getORB():deactivate(self._svr) |
75 |
end |
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
function obj:get_configuration_set(config_id) |
82 |
self._rtcout:RTC_TRACE("get_configuration_set("..config_id..")") |
83 |
if config_id == "" then |
84 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
85 |
description="ID is empty" |
86 |
}) |
87 |
end |
88 |
|
89 |
if not self._configsets:haveConfig(config_id) then |
90 |
self._rtcout:RTC_ERROR("No such ConfigurationSet") |
91 |
error(self._orb:newexcept{"SDOPackage::InternalError", |
92 |
description="No such ConfigurationSet" |
93 |
}) |
94 |
end |
95 |
|
96 |
|
97 |
|
98 |
local configset = self._configsets:getConfigurationSet(config_id) |
99 |
|
100 |
|
101 |
local config = {id="",description="",configuration_data={}} |
102 |
toConfigurationSet(config, configset) |
103 |
return config |
104 |
end |
105 |
|
106 |
|
107 |
|
108 |
function obj:get_active_configuration_set() |
109 |
self._rtcout:RTC_TRACE("get_active_configuration_set()") |
110 |
if not self._configsets:isActive() then |
111 |
error(self._orb:newexcept{"SDOPackage::NotAvailable", |
112 |
description="NotAvailable: Configuration.get_active_configuration_set()" |
113 |
}) |
114 |
end |
115 |
|
116 |
|
117 |
|
118 |
local config = {id="",description="",configuration_data={}} |
119 |
toConfigurationSet(config, self._configsets:getActiveConfigurationSet()) |
120 |
return config |
121 |
end |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
function obj:activate_configuration_set(config_id) |
127 |
self._rtcout:RTC_TRACE("activate_configuration_set("..config_id..")") |
128 |
if config_id == "" then |
129 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
130 |
description="ID is empty." |
131 |
}) |
132 |
end |
133 |
|
134 |
if self._configsets:activateConfigurationSet(config_id) then |
135 |
return true |
136 |
else |
137 |
error(self._orb:newexcept{"SDOPackage::InternalError", |
138 |
description="Configuration.activate_configuration_set()." |
139 |
}) |
140 |
end |
141 |
end |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
function obj:set_configuration_set_values(configuration_set) |
147 |
self._rtcout:RTC_TRACE("set_configuration_set_values()") |
148 |
if configuration_set == nil or configuration_set.id == "" then |
149 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
150 |
description="ID is empty." |
151 |
}) |
152 |
end |
153 |
|
154 |
local ret = nil |
155 |
local success, exception = oil.pcall( |
156 |
function() |
157 |
conf = Properties.new({key=configuration_set.id}) |
158 |
toProperties(conf, configuration_set) |
159 |
|
160 |
ret = self._configsets:setConfigurationSetValues(conf) |
161 |
end) |
162 |
if not success then |
163 |
self._rtcout:RTC_ERROR(exception) |
164 |
error(self._orb:newexcept{"SDOPackage::InternalError", |
165 |
description="Configuration::set_configuration_set_values()" |
166 |
}) |
167 |
end |
168 |
return ret |
169 |
end |
170 |
|
171 |
|
172 |
|
173 |
|
174 |
function obj:set_device_profile(dProfile) |
175 |
self._rtcout:RTC_TRACE("set_device_profile()") |
176 |
if dProfile == nil then |
177 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
178 |
description="dProfile is empty." |
179 |
}) |
180 |
end |
181 |
self._deviceProfile = dProfile |
182 |
return true |
183 |
end |
184 |
|
185 |
|
186 |
|
187 |
|
188 |
function obj:add_service_profile(sProfile) |
189 |
self._rtcout:RTC_TRACE("add_service_profile()") |
190 |
if sProfile == nil then |
191 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
192 |
description="sProfile is empty." |
193 |
}) |
194 |
end |
195 |
local ret = false |
196 |
local success, exception = oil.pcall( |
197 |
function() |
198 |
ret = self._sdoservice:addSdoServiceConsumer(sProfile) |
199 |
end) |
200 |
if not success then |
201 |
self._rtcout:RTC_ERROR(exception) |
202 |
error(self._orb:newexcept{"SDOPackage::InternalError", |
203 |
description="Configuration.add_service_profile" |
204 |
}) |
205 |
end |
206 |
return ret |
207 |
end |
208 |
|
209 |
|
210 |
|
211 |
|
212 |
function obj:add_organization(org) |
213 |
self._rtcout:RTC_TRACE("add_organization()") |
214 |
if org == nil then |
215 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
216 |
description="org is empty." |
217 |
}) |
218 |
end |
219 |
table.insert(self._organizations, org) |
220 |
return true |
221 |
end |
222 |
|
223 |
|
224 |
|
225 |
|
226 |
function obj:remove_service_profile(id_) |
227 |
self._rtcout:RTC_TRACE("remove_service_profile("..id_..")") |
228 |
if id_ == "" then |
229 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
230 |
description="id is empty." |
231 |
}) |
232 |
end |
233 |
local ret = false |
234 |
local success, exception = oil.pcall( |
235 |
function() |
236 |
ret = self._sdoservice:removeSdoServiceConsumer(id_) |
237 |
end) |
238 |
if not success then |
239 |
self._rtcout:RTC_ERROR(exception) |
240 |
error(self._orb:newexcept{"SDOPackage::InternalError", |
241 |
description="Configuration.remove_service_profile" |
242 |
}) |
243 |
end |
244 |
return ret |
245 |
end |
246 |
|
247 |
|
248 |
|
249 |
|
250 |
function obj:remove_organization(organization_id) |
251 |
self._rtcout:RTC_TRACE("remove_organization("..organization_id..")") |
252 |
if organization_id == nil then |
253 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
254 |
description="id is empty." |
255 |
}) |
256 |
end |
257 |
CORBA_SeqUtil.erase_if(self._organizations, self.org_id.new(organization_id)) |
258 |
|
259 |
return true |
260 |
end |
261 |
|
262 |
|
263 |
|
264 |
function obj:get_configuration_parameters() |
265 |
self._rtcout:RTC_TRACE("get_configuration_parameters()") |
266 |
return self._parameters |
267 |
end |
268 |
|
269 |
|
270 |
|
271 |
|
272 |
function obj:get_configuration_parameter_values() |
273 |
self._rtcout:RTC_TRACE("get_configuration_parameter_values()") |
274 |
local nvlist = {} |
275 |
return nvlist |
276 |
end |
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
function obj:set_configuration_parameter(name, value) |
283 |
self._rtcout:RTC_TRACE("set_configuration_parameter("..name..", value)") |
284 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
285 |
description="Name/Value is empty." |
286 |
}) |
287 |
end |
288 |
|
289 |
|
290 |
|
291 |
function obj:get_configuration_sets() |
292 |
self._rtcout:RTC_TRACE("get_configuration_sets()") |
293 |
local config_sets = {} |
294 |
local success, exception = oil.pcall( |
295 |
function() |
296 |
local cf = self._configsets:getConfigurationSets() |
297 |
|
298 |
local len_ = #cf |
299 |
|
300 |
for i = 1,len_ do |
301 |
config_sets[i] = {id="",description="",configuration_data={}} |
302 |
toConfigurationSet(config_sets[i], cf[i]) |
303 |
end |
304 |
end) |
305 |
if not success then |
306 |
|
307 |
self._rtcout:RTC_ERROR(exception) |
308 |
error(self._orb:newexcept{"SDOPackage::InternalError", |
309 |
description="Configuration.get_configuration_sets" |
310 |
}) |
311 |
end |
312 |
|
313 |
return config_sets |
314 |
end |
315 |
|
316 |
|
317 |
|
318 |
function obj:getDeviceProfile() |
319 |
return self._deviceProfile |
320 |
end |
321 |
|
322 |
|
323 |
|
324 |
function obj:getServiceProfiles() |
325 |
return self._serviceProfiles |
326 |
end |
327 |
|
328 |
|
329 |
|
330 |
|
331 |
function obj:getServiceProfile(id) |
332 |
local index = CORBA_SeqUtil.find(self._serviceProfiles, self.service_id(id)) |
333 |
if index < 0 then |
334 |
return {id="", |
335 |
interface_type="", |
336 |
properties={}, |
337 |
service=oil.corba.idl.null} |
338 |
end |
339 |
|
340 |
|
341 |
|
342 |
|
343 |
function obj:getOrganizations() |
344 |
return self._organizations |
345 |
end |
346 |
|
347 |
return self._serviceProfiles[index] |
348 |
end |
349 |
|
350 |
obj.nv_name = {} |
351 |
|
352 |
|
353 |
|
354 |
obj.nv_name.new = function(name_) |
355 |
local obj = {} |
356 |
obj._name = tostring(name_) |
357 |
|
358 |
|
359 |
|
360 |
local call_func = function(self, nv) |
361 |
local name_ = tostring(nv.name) |
362 |
return (self._name == name_) |
363 |
end |
364 |
setmetatable(obj, {__call=call_func}) |
365 |
|
366 |
return obj |
367 |
end |
368 |
|
369 |
obj.service_id = {} |
370 |
|
371 |
|
372 |
|
373 |
obj.service_id.new = function(id_) |
374 |
local obj = {} |
375 |
obj._id = tostring(id_) |
376 |
|
377 |
|
378 |
|
379 |
local call_func = function(self, s) |
380 |
local id_ = tostring(s.id) |
381 |
return (self._id == id_) |
382 |
end |
383 |
setmetatable(obj, {__call=call_func}) |
384 |
return obj |
385 |
end |
386 |
|
387 |
obj.org_id = {} |
388 |
|
389 |
|
390 |
|
391 |
obj.org_id.new = function(id_) |
392 |
local obj = {} |
393 |
obj._id = tostring(id_) |
394 |
|
395 |
|
396 |
|
397 |
local call_func = function(self, o) |
398 |
local id_ = tostring(o:get_organization_id()) |
399 |
return (self._id == id_) |
400 |
end |
401 |
setmetatable(obj, {__call=call_func}) |
402 |
return obj |
403 |
end |
404 |
|
405 |
obj.config_id = {} |
406 |
|
407 |
|
408 |
|
409 |
obj.config_id.new = function(id_) |
410 |
local obj = {} |
411 |
obj._id = tostring(id_) |
412 |
|
413 |
|
414 |
|
415 |
local call_func = function(self, c) |
416 |
local id_ = tostring(c.id) |
417 |
return (self._id == id_) |
418 |
end |
419 |
setmetatable(obj, {__call=call_func}) |
420 |
return obj |
421 |
end |
422 |
|
423 |
|
424 |
|
425 |
|
426 |
return obj |
427 |
end |
428 |
|
429 |
|
430 |
|
431 |
|
432 |
return SdoConfiguration |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local SdoServiceAdmin= {} |
11 |
local StringUtil = require "openrtm.StringUtil" |
12 |
local SdoServiceProviderBase = require "openrtm.SdoServiceProviderBase" |
13 |
local SdoServiceProviderFactory = SdoServiceProviderBase.SdoServiceProviderFactory |
14 |
local StringUtil = require "openrtm.StringUtil" |
15 |
local NVUtil = require "openrtm.NVUtil" |
16 |
local SdoServiceConsumerBase = require "openrtm.SdoServiceConsumerBase" |
17 |
local SdoServiceConsumerFactory = SdoServiceConsumerBase.SdoServiceConsumerFactory |
18 |
local uuid = require "uuid" |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
SdoServiceAdmin.new = function(rtobj) |
27 |
local obj = {} |
28 |
obj._rtobj = rtobj |
29 |
obj._consumerTypes = {} |
30 |
obj._providers = {} |
31 |
obj._consumers = {} |
32 |
obj._allConsumerEnabled = false |
33 |
local Manager = require "openrtm.Manager" |
34 |
obj._manager = Manager:instance() |
35 |
|
36 |
obj._rtcout = obj._manager:getLogbuf("rtobject.sdo_config") |
37 |
|
38 |
|
39 |
function obj:init(rtobj) |
40 |
self._rtcout:RTC_TRACE("SdoServiceAdmin::SdoServiceAdmin(%s)", |
41 |
rtobj:getProperties():getProperty("instance_name")) |
42 |
|
43 |
local prop = self._rtobj:getProperties() |
44 |
|
45 |
local enabledProviderTypes = StringUtil.split(prop:getProperty("sdo.service.provider.enabled_services"),",") |
46 |
enabledProviderTypes = StringUtil.strip(enabledProviderTypes) |
47 |
|
48 |
self._rtcout:RTC_DEBUG("sdo.service.provider.enabled_services: %s", prop:getProperty("sdo.service.provider.enabled_services")) |
49 |
|
50 |
local availableProviderTypes = SdoServiceProviderFactory:instance():getIdentifiers() |
51 |
prop:setProperty("sdo.service.provider.available_services", tostring(StringUtil.flatten(availableProviderTypes))) |
52 |
self._rtcout:RTC_DEBUG("sdo.service.provider.available_services: %s", prop:getProperty("sdo.service.provider.available_services")) |
53 |
|
54 |
|
55 |
local activeProviderTypes = {} |
56 |
|
57 |
for i,ep_type in ipairs(enabledProviderTypes) do |
58 |
local tmp = string.lower(ep_type) |
59 |
|
60 |
if tmp == "all" then |
61 |
|
62 |
activeProviderTypes = availableProviderTypes |
63 |
self._rtcout:RTC_DEBUG("sdo.service.provider.enabled_services: ALL") |
64 |
break |
65 |
end |
66 |
for j,ap_type in ipairs(availableProviderTypes) do |
67 |
if ap_type == ep_type then |
68 |
table.insert(activeProviderTypes, ap_type) |
69 |
end |
70 |
end |
71 |
end |
72 |
|
73 |
local factory = SdoServiceProviderFactory:instance() |
74 |
for i,ap_type in ipairs(activeProviderTypes) do |
75 |
local svc = factory:createObject(ap_type) |
76 |
local propkey = self:ifrToKey(ap_type) |
77 |
local properties = {} |
78 |
NVUtil.copyFromProperties(properties, prop:getNode(tostring(propkey))) |
79 |
local prof = { |
80 |
id = tostring(ap_type), |
81 |
interface_type = tostring(ap_type), |
82 |
properties = properties, |
83 |
service = svc._svr} |
84 |
|
85 |
|
86 |
|
87 |
if not svc:init(rtobj, prof) then |
88 |
svc:finalize() |
89 |
else |
90 |
table.insert(self._providers, svc) |
91 |
end |
92 |
end |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
local constypes = prop:getProperty("sdo.service.consumer.enabled_services") |
98 |
|
99 |
|
100 |
self._consumerTypes = StringUtil.split(constypes,",") |
101 |
self._consumerTypes = StringUtil.strip(self._consumerTypes) |
102 |
self._rtcout:RTC_DEBUG("sdo.service.consumer.enabled_services: %s", tostring(constypes)) |
103 |
|
104 |
prop:setProperty("sdo.service.consumer.available_services", |
105 |
tostring(StringUtil.flatten(SdoServiceConsumerFactory:instance():getIdentifiers()))) |
106 |
self._rtcout:RTC_DEBUG("sdo.service.consumer.available_services: %s", |
107 |
prop:getProperty("sdo.service.consumer.available_services")) |
108 |
|
109 |
|
110 |
|
111 |
for i, ctype in ipairs(self._consumerTypes) do |
112 |
local tmp = string.lower(ctype) |
113 |
if tmp == "all" then |
114 |
self._allConsumerEnabled = true |
115 |
self._rtcout:RTC_DEBUG("sdo_service.consumer_types: ALL") |
116 |
end |
117 |
end |
118 |
end |
119 |
|
120 |
function obj:exit() |
121 |
|
122 |
for i, provider in ipairs(self._providers) do |
123 |
provider:finalize() |
124 |
end |
125 |
|
126 |
self._providers = {} |
127 |
|
128 |
|
129 |
for i, consumer in ipairs(self._consumers) do |
130 |
consumer:finalize() |
131 |
end |
132 |
|
133 |
self._consumers = {} |
134 |
end |
135 |
|
136 |
|
137 |
|
138 |
function obj:getServiceProviderProfiles() |
139 |
local prof = {} |
140 |
for i,provider in ipairs(self._providers) do |
141 |
table.insert(prof, provider:getProfile()) |
142 |
end |
143 |
return prof |
144 |
end |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
function obj:getServiceProviderProfile(id) |
150 |
local idstr = id |
151 |
|
152 |
for i,provider in ipairs(self._providers) do |
153 |
if idstr == tostring(provider:getProfile().id) then |
154 |
return provider:getProfile() |
155 |
end |
156 |
end |
157 |
|
158 |
error(self._orb:newexcept{"SDOPackage::InvalidParameter", |
159 |
description="" |
160 |
}) |
161 |
end |
162 |
|
163 |
|
164 |
|
165 |
function obj:getServiceProvider(id) |
166 |
local prof = self:getServiceProviderProfile(id) |
167 |
return prof.service |
168 |
end |
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
function obj:addSdoServiceProvider(prof, provider) |
175 |
self._rtcout:RTC_TRACE("SdoServiceAdmin::addSdoServiceProvider(if=%s)", |
176 |
prof.interface_type) |
177 |
local id = prof.id |
178 |
for i,provider in ipairs(self._providers) do |
179 |
if id == tostring(provider:getProfile().id) then |
180 |
self._rtcout:RTC_ERROR("SDO service(id=%s, ifr=%s) already exists", |
181 |
tostring(prof.id), tostring(prof.interface_type)) |
182 |
return false |
183 |
end |
184 |
end |
185 |
|
186 |
table.insert(self._providers, provider) |
187 |
return true |
188 |
end |
189 |
|
190 |
|
191 |
|
192 |
|
193 |
function obj:removeSdoServiceProvider(id) |
194 |
self._rtcout:RTC_TRACE("removeSdoServiceProvider(%d)", id) |
195 |
|
196 |
local strid = id |
197 |
|
198 |
for i,provider in ipairs(self._providers) do |
199 |
if strid == tostring(provider:getProfile().id) then |
200 |
provider:finalize() |
201 |
local factory = SdoServiceProviderFactory:instance() |
202 |
factory:deleteObject(self._providers[i]) |
203 |
table.remove(self._providers, i) |
204 |
self._rtcout:RTC_INFO("SDO service provider has been deleted: %s", id) |
205 |
return true |
206 |
end |
207 |
end |
208 |
self._rtcout:RTC_WARN("Specified SDO service provider not found: %s", id) |
209 |
return false |
210 |
end |
211 |
|
212 |
|
213 |
|
214 |
|
215 |
function obj:addSdoServiceConsumer(sProfile) |
216 |
self._rtcout:RTC_TRACE("addSdoServiceConsumer(IFR = %s)", |
217 |
sProfile.interface_type) |
218 |
local profile = sProfile |
219 |
|
220 |
|
221 |
if not self:isEnabledConsumerType(sProfile) then |
222 |
self._rtcout:RTC_ERROR("Not supported consumer type. %s", profile.interface_type) |
223 |
return false |
224 |
end |
225 |
|
226 |
if not self:isExistingConsumerType(sProfile) then |
227 |
self._rtcout:RTC_ERROR("type %s not exists.", profile.interface_type) |
228 |
return false |
229 |
end |
230 |
if tostring(profile.id) == "" then |
231 |
self._rtcout:RTC_WARN("No id specified. It should be given by clients.") |
232 |
return false |
233 |
end |
234 |
|
235 |
|
236 |
local id = tostring(sProfile.id) |
237 |
for i,consumer in ipairs(self._consumers) do |
238 |
if id == tostring(self._consumers[i]:getProfile().id) then |
239 |
self._rtcout:RTC_INFO("Existing consumer is reinitilized.") |
240 |
self._rtcout:RTC_DEBUG("Propeteis are: %s", |
241 |
NVUtil.toString(sProfile.properties)) |
242 |
return consumer:reinit(sProfile) |
243 |
end |
244 |
end |
245 |
|
246 |
|
247 |
local factory = SdoServiceConsumerFactory:instance() |
248 |
local ctype = tostring(profile.interface_type) |
249 |
local consumer = factory:createObject(ctype) |
250 |
|
251 |
|
252 |
if not consumer:init(self._rtobj, sProfile) then |
253 |
self._rtcout:RTC_WARN("SDO service initialization was failed.") |
254 |
self._rtcout:RTC_DEBUG("id: %s", tostring(sProfile.id)) |
255 |
self._rtcout:RTC_DEBUG("IFR: %s", tostring(sProfile.interface_type)) |
256 |
self._rtcout:RTC_DEBUG("properties: %s", NVUtil.toString(sProfile.properties)) |
257 |
factory:deleteObject(consumer) |
258 |
self._rtcout:RTC_INFO("SDO consumer was deleted by initialization failure") |
259 |
return false |
260 |
end |
261 |
|
262 |
|
263 |
table.insert(self._consumers, consumer) |
264 |
|
265 |
return true |
266 |
end |
267 |
|
268 |
|
269 |
|
270 |
|
271 |
function obj:removeSdoServiceConsumer(id) |
272 |
if id == "" then |
273 |
self._rtcout:RTC_ERROR("removeSdoServiceConsumer(): id is invalid.") |
274 |
return false |
275 |
end |
276 |
self._rtcout:RTC_TRACE("removeSdoServiceConsumer(id = %s)", id) |
277 |
|
278 |
local strid = id |
279 |
|
280 |
for idx,cons in ipairs(self._consumers) do |
281 |
if strid == tostring(cons:getProfile().id) then |
282 |
cons:finalize() |
283 |
table.remove(self._consumers, idx) |
284 |
local factory = SdoServiceConsumerFactory:instance() |
285 |
factory:deleteObject(cons) |
286 |
self._rtcout:RTC_INFO("SDO service has been deleted: %s", id) |
287 |
return true |
288 |
end |
289 |
end |
290 |
|
291 |
self._rtcout:RTC_WARN("Specified SDO consumer not found: %s", id) |
292 |
return false |
293 |
end |
294 |
|
295 |
|
296 |
|
297 |
|
298 |
function obj:isEnabledConsumerType(sProfile) |
299 |
if self._allConsumerEnabled then |
300 |
return true |
301 |
end |
302 |
|
303 |
for i, consumer in ipairs(self._consumerTypes) do |
304 |
if consumer == tostring(sProfile.interface_type) then |
305 |
self._rtcout:RTC_DEBUG("%s is supported SDO service.", |
306 |
tostring(sProfile.interface_type)) |
307 |
return true |
308 |
end |
309 |
end |
310 |
|
311 |
self._rtcout:RTC_WARN("Consumer type is not supported: %s", |
312 |
tostring(sProfile.interface_type)) |
313 |
return false |
314 |
end |
315 |
|
316 |
|
317 |
|
318 |
|
319 |
function obj:isExistingConsumerType(sProfile) |
320 |
local factory = SdoServiceConsumerFactory:instance() |
321 |
local consumerTypes = factory:getIdentifiers() |
322 |
|
323 |
for i, consumer in ipairs(consumerTypes) do |
324 |
if consumer == tostring(sProfile.interface_type) then |
325 |
self._rtcout:RTC_DEBUG("%s exists in the SDO service factory.", tostring(sProfile.interface_type)) |
326 |
self._rtcout:RTC_PARANOID("Available SDO serices in the factory: %s", tostring(StringUtil.flatten(consumerTypes))) |
327 |
return true |
328 |
end |
329 |
end |
330 |
self._rtcout:RTC_WARN("No available SDO service in the factory: %s", |
331 |
tostring(sProfile.interface_type)) |
332 |
return false |
333 |
end |
334 |
|
335 |
|
336 |
|
337 |
function obj:getUUID() |
338 |
return uuid() |
339 |
end |
340 |
|
341 |
|
342 |
|
343 |
|
344 |
function obj:ifrToKey(ifr) |
345 |
local ifrvstr = StringUtil.split(ifr, ":") |
346 |
ifrvstr[2] = string.lower(ifrvstr[2]) |
347 |
ifrvstr[2] = string.gsub(ifrvstr[2], "%.", "_") |
348 |
ifrvstr[2] = string.gsub(ifrvstr[2], "/", "%.") |
349 |
return ifrvstr[2] |
350 |
end |
351 |
|
352 |
return obj |
353 |
end |
354 |
|
355 |
|
356 |
return SdoServiceAdmin |
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
local StringUtil= {} |
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
StringUtil.eraseHeadBlank = function(_str) |
18 |
return (string.gsub(_str, "^%s*(.-)$", "%1")) |
19 |
end |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
StringUtil.eraseTailBlank = function(_str) |
25 |
return (string.gsub(_str, "^(.-)%s*$", "%1")) |
26 |
end |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
StringUtil.eraseBothEndsBlank = function(_str) |
32 |
return (string.gsub(_str, "^%s*(.-)%s*$", "%1")) |
33 |
end |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
StringUtil.normalize = function(_str) |
40 |
local ret = string.gsub(_str, "^%s*(.-)%s*$", "%1") |
41 |
return string.lower(ret) |
42 |
end |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
StringUtil.strip = function(str_list) |
48 |
local ret = {} |
49 |
for k,v in ipairs(str_list) do |
50 |
table.insert(ret, StringUtil.eraseBothEndsBlank(v)) |
51 |
end |
52 |
return ret |
53 |
end |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
StringUtil.isEscaped = function(_str, pos) |
60 |
|
61 |
|
62 |
local i = 0 |
63 |
|
64 |
while pos >= 0 and string.sub(_str, pos, pos) == "\\" do |
65 |
i = i+1 |
66 |
pos = pos-1 |
67 |
end |
68 |
|
69 |
return (i % 2 == 1) |
70 |
end |
71 |
|
72 |
|
73 |
local unescape_functor = {} |
74 |
|
75 |
|
76 |
unescape_functor.new = function() |
77 |
local obj = {} |
78 |
obj.count = 0 |
79 |
obj._str = "" |
80 |
|
81 |
|
82 |
|
83 |
local call_func = function(self, c) |
84 |
if c == "\\" then |
85 |
self.count = self.count+1 |
86 |
if self.count % 2 == 0 then |
87 |
self._str = self._str..c |
88 |
end |
89 |
else |
90 |
if self.count > 0 and self.count % 2 == 1 then |
91 |
self.count = 0 |
92 |
if c == 't' then |
93 |
self._str=self._str..'\t' |
94 |
elseif c == 'n' then |
95 |
self._str=self._str..'\n' |
96 |
elseif c == 'f' then |
97 |
self._str=self._str..'\f' |
98 |
elseif c == 'r' then |
99 |
self._str=self._str..'\r' |
100 |
elseif c == '\"' then |
101 |
self._str=self._str..'\"' |
102 |
elseif c == '\'' then |
103 |
self._str=self._str..'\'' |
104 |
else |
105 |
self._str=self._str..c |
106 |
end |
107 |
else |
108 |
self.count = 0 |
109 |
self._str=self._str..c |
110 |
end |
111 |
end |
112 |
end |
113 |
setmetatable(obj, {__call=call_func}) |
114 |
return obj |
115 |
end |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
StringUtil.unescape = function(_str) |
121 |
local functor = unescape_functor.new() |
122 |
for i=1,#_str do |
123 |
functor(string.sub(_str,i,i)) |
124 |
end |
125 |
return functor._str |
126 |
end |
127 |
|
128 |
|
129 |
|
130 |
|
131 |
StringUtil.copy = function(orig) |
132 |
local copy = {} |
133 |
if type(orig) == 'table' then |
134 |
for k, v in ipairs(orig) do |
135 |
copy[k] = v |
136 |
end |
137 |
else |
138 |
copy = orig |
139 |
end |
140 |
return copy |
141 |
end |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
StringUtil.deepcopy = function(orig) |
147 |
local copy = {} |
148 |
if type(orig) == 'table' then |
149 |
for k, v in pairs(orig) do |
150 |
copy[k] = StringUtil.deepcopy(v) |
151 |
end |
152 |
else |
153 |
copy = orig |
154 |
end |
155 |
return copy |
156 |
end |
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
StringUtil.split = function(input, delimiter) |
165 |
|
166 |
if string.find(input, delimiter) == nil then |
167 |
return { input } |
168 |
end |
169 |
local result = {} |
170 |
local pat = "(.-)" .. delimiter .. "()" |
171 |
local lastPos = 0 |
172 |
for part, pos in string.gmatch(input, pat) do |
173 |
table.insert(result, part) |
174 |
lastPos = pos |
175 |
end |
176 |
table.insert(result, string.sub(input, lastPos)) |
177 |
return result |
178 |
end |
179 |
|
180 |
|
181 |
|
182 |
StringUtil.print_table = function(tbl) |
183 |
for k, v in pairs(tbl) do |
184 |
if type(v)=="table" then |
185 |
|
186 |
StringUtil.print_table(v) |
187 |
else |
188 |
print( k, v ) |
189 |
end |
190 |
end |
191 |
end |
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
StringUtil.toBool = function(_str, yes, no, default_value) |
200 |
if default_value == nil then |
201 |
default_value = true |
202 |
end |
203 |
|
204 |
_str = _str:lower() |
205 |
yes = yes:lower() |
206 |
no = no:lower() |
207 |
if _str:match(yes) ~= nil then |
208 |
return true |
209 |
elseif _str:match(no) ~= nil then |
210 |
return false |
211 |
end |
212 |
return default_value |
213 |
end |
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
StringUtil.otos = function(n) |
221 |
return ""..n |
222 |
end |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
StringUtil.in_value = function(tbl, val) |
229 |
for k, v in pairs (tbl) do |
230 |
if v==val then |
231 |
return true |
232 |
end |
233 |
end |
234 |
return false |
235 |
end |
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
StringUtil.in_key = function(tbl, key) |
242 |
if tbl[key] ~= nil then |
243 |
return true |
244 |
end |
245 |
return false |
246 |
end |
247 |
|
248 |
|
249 |
|
250 |
|
251 |
StringUtil.unique_sv = function(sv) |
252 |
local unique_strvec = StringUtil.unique_strvec.new() |
253 |
for i,v in ipairs(sv) do |
254 |
unique_strvec(v) |
255 |
end |
256 |
return unique_strvec._str |
257 |
end |
258 |
|
259 |
StringUtil.unique_strvec = {} |
260 |
|
261 |
|
262 |
|
263 |
StringUtil.unique_strvec.new = function() |
264 |
local obj = {} |
265 |
obj._str = {} |
266 |
|
267 |
|
268 |
|
269 |
|
270 |
local call_func = function(self, s) |
271 |
if not StringUtil.in_value(self._str, s) then |
272 |
table.insert(self._str, s) |
273 |
return self._str |
274 |
end |
275 |
end |
276 |
setmetatable(obj, {__call=call_func}) |
277 |
return obj |
278 |
end |
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
StringUtil.flatten = function(sv, delimiter) |
285 |
if delimiter == nil then |
286 |
delimiter = ", " |
287 |
end |
288 |
if #sv == 0 then |
289 |
return "" |
290 |
end |
291 |
local _str = table.concat(sv, delimiter) |
292 |
|
293 |
return _str |
294 |
end |
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
StringUtil.table_count = function(tbl, value) |
301 |
local count = 0 |
302 |
for i, v in ipairs(tbl) do |
303 |
if value == v then |
304 |
count = count+1 |
305 |
end |
306 |
end |
307 |
return count |
308 |
end |
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
StringUtil.table_index = function(tbl, value) |
315 |
for i, v in ipairs(tbl) do |
316 |
if value == v then |
317 |
return i |
318 |
end |
319 |
end |
320 |
return -1 |
321 |
end |
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
StringUtil.includes = function(_list, value, ignore_case) |
329 |
if ignore_case == nil then |
330 |
ignore_case = true |
331 |
end |
332 |
|
333 |
if not (type(_list) == "table" or type(_list) == "string") then |
334 |
|
335 |
return false |
336 |
end |
337 |
|
338 |
if type(_list) == "string" then |
339 |
_list = StringUtil.split(_list, ",") |
340 |
end |
341 |
|
342 |
|
343 |
local tmp_list = _list |
344 |
if ignore_case then |
345 |
value = string.lower(value) |
346 |
tmp_list = {} |
347 |
for i, v in ipairs(_list) do |
348 |
table.insert(tmp_list, string.lower(v)) |
349 |
end |
350 |
end |
351 |
if StringUtil.table_count(tmp_list, value) > 0 then |
352 |
return true |
353 |
end |
354 |
|
355 |
return false |
356 |
end |
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
StringUtil._stringToList = function(_type, _str) |
363 |
|
364 |
local list_ = StringUtil.split(_str, ",") |
365 |
local ans = {} |
366 |
if #_type < #list_ then |
367 |
local sub = #list_ - #_type |
368 |
for i = 1,sub do |
369 |
table.insert(_type, _type[1]) |
370 |
end |
371 |
elseif #_type > #list_ then |
372 |
local sub = #_type - #list_ |
373 |
for i = #list_,#_type do |
374 |
table.remove(_type, i) |
375 |
end |
376 |
end |
377 |
for i = 1,#list_ do |
378 |
if type(_type[i]) == "number" then |
379 |
table.insert(ans, tonumber(list_[i])) |
380 |
elseif type(_type[i]) == "string" then |
381 |
table.insert(ans, tostring(list_[i])) |
382 |
end |
383 |
end |
384 |
|
385 |
return true, ans |
386 |
|
387 |
|
388 |
end |
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
StringUtil.stringTo = function(_type, _str) |
395 |
if type(_type) == "number" then |
396 |
local value = tonumber(_str) |
397 |
if value ~= nil then |
398 |
return true, value |
399 |
else |
400 |
return false, _type |
401 |
end |
402 |
elseif type(_type) == "string" then |
403 |
local value = tostring(_str) |
404 |
if value ~= nil then |
405 |
return true, value |
406 |
else |
407 |
return false, _type |
408 |
end |
409 |
elseif type(_type) == "table" then |
410 |
return StringUtil._stringToList(_type, _str) |
411 |
else |
412 |
return false, _type |
413 |
end |
414 |
|
415 |
end |
416 |
|
417 |
|
418 |
|
419 |
|
420 |
StringUtil.createopt = function(options) |
421 |
local ret = {} |
422 |
local pos = 1 |
423 |
while pos <= #options do |
424 |
local opt = string.sub(options,pos,pos) |
425 |
ret[opt] = {} |
426 |
pos = pos + 1 |
427 |
if pos <= #options then |
428 |
local opt2 = string.sub(options,pos,pos) |
429 |
if opt2 == ":" then |
430 |
ret[opt].optarg = true |
431 |
pos = pos + 1 |
432 |
else |
433 |
ret[opt].optarg = false |
434 |
end |
435 |
end |
436 |
end |
437 |
return ret |
438 |
end |
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
StringUtil.getopt = function(arg, options) |
445 |
local ret = {} |
446 |
local pos = 1 |
447 |
local opt = StringUtil.createopt(options) |
448 |
|
449 |
|
450 |
|
451 |
while pos <= #arg do |
452 |
arg[pos] = StringUtil.eraseBothEndsBlank(arg[pos]) |
453 |
if #arg[pos] <= 1 then |
454 |
pos = pos + 1 |
455 |
elseif string.sub(arg[pos],1,1) == "-" then |
456 |
local _id = string.sub(arg[pos],2) |
457 |
if opt[_id] ~= nil then |
458 |
local v = {id=_id} |
459 |
if opt[_id].optarg then |
460 |
pos = pos+1 |
461 |
if pos <= #arg then |
462 |
v.optarg = arg[pos] |
463 |
end |
464 |
end |
465 |
|
466 |
table.insert(ret, v) |
467 |
end |
468 |
pos = pos + 1 |
469 |
else |
470 |
pos = pos + 1 |
471 |
end |
472 |
end |
473 |
return ret |
474 |
end |
475 |
|
476 |
|
477 |
|
478 |
|
479 |
StringUtil.dirname = function(path) |
480 |
local delimiter = "\\" |
481 |
if string.find(path, "/", 1, true) ~= nil then |
482 |
delimiter = "/" |
483 |
end |
484 |
local path_list = StringUtil.split(path, delimiter) |
485 |
path_list[#path_list] = nil |
486 |
local ret = StringUtil.flatten(path_list, delimiter) |
487 |
if #ret == 0 then |
488 |
return ret |
489 |
else |
490 |
return ret..delimiter |
491 |
end |
492 |
|
493 |
end |
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
StringUtil.basename = function(path) |
500 |
local delimiter = "\\" |
501 |
if string.find(path, "/", 1, true) ~= nil then |
502 |
delimiter = "/" |
503 |
end |
504 |
local path_list = StringUtil.split(path, delimiter) |
505 |
|
506 |
return path_list[#path_list] |
507 |
end |
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
StringUtil.getKeyCount = function(tbl) |
514 |
local ret = 0 |
515 |
for k,v in pairs(tbl) do |
516 |
ret = ret + 1 |
517 |
end |
518 |
return ret |
519 |
end |
520 |
|
521 |
|
522 |
|
523 |
|
524 |
StringUtil.isURL = function(str) |
525 |
if str == "" then |
526 |
return false |
527 |
end |
528 |
|
529 |
local pos,c = string.find(str, "://") |
530 |
if pos ~= 1 and pos ~= nil then |
531 |
return true |
532 |
end |
533 |
return false |
534 |
end |
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
StringUtil.isAbsolutePath = function(str) |
543 |
if string.sub(str,1,1) == "/" then |
544 |
return true |
545 |
end |
546 |
if string.match(string.sub(str,1,1), '[a-zA-Z]') then |
547 |
if string.sub(str,2,2) == ":" and (string.sub(str,3,3) == "\\" or string.sub(str,3,3) == "/") then |
548 |
return true |
549 |
end |
550 |
end |
551 |
if string.sub(str,1,1) == "\\" and string.sub(str,2,2) == "\\" then |
552 |
return true |
553 |
end |
554 |
|
555 |
return false |
556 |
end |
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
StringUtil.urlparam2map = function(_str) |
563 |
local qpos = string.find(_str, "?") |
564 |
if qpos == nil then |
565 |
qpos = 0 |
566 |
else |
567 |
qpos = qpos+1 |
568 |
end |
569 |
local tmp = StringUtil.split(string.sub(_str, qpos), "&") |
570 |
local retmap = {} |
571 |
for k, v in ipairs(tmp) do |
572 |
pos = string.find(v, "=") |
573 |
if pos ~= nil then |
574 |
retmap[string.sub(v,1,pos-1)] = string.sub(v, pos+1) |
575 |
else |
576 |
retmap[v] = "" |
577 |
end |
578 |
end |
579 |
return retmap |
580 |
end |
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
StringUtil.difference = function(list1, list2) |
588 |
local ret = {} |
589 |
for k,v in ipairs(list1) do |
590 |
if StringUtil.table_count(list2, v) == 0 then |
591 |
table.insert(ret, v) |
592 |
end |
593 |
end |
594 |
return ret |
595 |
end |
596 |
|
597 |
|
598 |
return StringUtil |
Generated by lcovtools in 18.7 seconds.