diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-02-19 19:50:17 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-02-19 19:50:17 (GMT) |
commit | bbec87d314f5b706afda260d04f3180b1f848d6b (patch) | |
tree | 6d720ab67a7213e10756ca234ccc53ad31034e2e /src/uscxml/plugins/invoker/umundo | |
parent | 6926b730e79e1e7bbb5080c4182d8c2862b08fdc (diff) | |
download | uscxml-bbec87d314f5b706afda260d04f3180b1f848d6b.zip uscxml-bbec87d314f5b706afda260d04f3180b1f848d6b.tar.gz uscxml-bbec87d314f5b706afda260d04f3180b1f848d6b.tar.bz2 |
More work on prolog datamodel
Diffstat (limited to 'src/uscxml/plugins/invoker/umundo')
-rw-r--r-- | src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp index 1861db7..a6a2df3 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp @@ -73,79 +73,80 @@ void UmundoInvoker::send(const SendRequest& req) { } else { msg.putMeta("event", "umundo"); } + + try { + Data data = req.data; + + if (!data && req.content.length()) + data = _interpreter->getDataModel().getStringAsData(req.content); + + if (!data) { + LOG(ERROR) << "Cannot transform content to data object per datamodel or no data given"; + return; + } + +// std::cout << Data::toJSON(data) << std::endl; + + std::string type; + if (req.params.find("type") != req.params.end()) { + // we are supposed to build a typed object + type = req.params.find("type")->second.atom; - if (req.content.length()) { - try { - Data data = _interpreter->getDataModel().getStringAsData(req.content); - if (!data) { - LOG(ERROR) << "Cannot transform content to data object per datamodel"; + const google::protobuf::Message* protoMsg = umundo::PBSerializer::getProto(type); + if (protoMsg == NULL) { + LOG(ERROR) << "No type '" << type << "' is known, pass a directory with proto .desc files via types param when invoking"; return; } - std::string type; - if (req.params.find("type") != req.params.end()) { - // we are supposed to build a typed object - type = req.params.find("type")->second.atom; - - const google::protobuf::Message* protoMsg = umundo::PBSerializer::getProto(type); - if (protoMsg == NULL) { - LOG(ERROR) << "No type '" << type << "' is known, pass a directory with proto .desc files via types param when invoking"; - return; - } - - google::protobuf::Message* pbMsg = protoMsg->New(); - if (!dataToProtobuf(pbMsg, data)) { - LOG(ERROR) << "Cannot create message from JSON - not sending"; - return; - } + google::protobuf::Message* pbMsg = protoMsg->New(); + if (!dataToProtobuf(pbMsg, data)) { + LOG(ERROR) << "Cannot create message from JSON - not sending"; + return; + } - if (!_isService) { - // add all s11n properties - _pub->prepareMsg(&msg, type, pbMsg); - _pub->send(&msg); - } else { - // invoke as service - std::map<umundo::ServiceDescription, umundo::ServiceStub*>::iterator svcIter = _svcs.begin(); - while(svcIter != _svcs.end()) { - umundo::ServiceStub* stub = svcIter->second; - Event event; - void* rv = NULL; - stub->callStubMethod(req.name, pbMsg, type, rv, ""); - protobufToData(event.data, *(const google::protobuf::Message*)rv); - - event.name = _invokeId + ".reply." + req.name; - event.origin = msg.getMeta("um.channel"); - event.origintype = "umundo"; - event.eventType = Event::EXTERNAL; - - returnEvent(event); - svcIter++; - } - } + if (!_isService) { + // add all s11n properties + _pub->prepareMsg(&msg, type, pbMsg); + _pub->send(&msg); } else { - // just encode JSON - JSONProto* jsonProtoMsg = new JSONProto(); - if (!dataToJSONbuf(jsonProtoMsg, data)) { - LOG(ERROR) << "Cannot create message from JSON - not sending"; - return; - } - - if (!_isService) { - // add all s11n properties - _pub->prepareMsg(&msg, "JSON", jsonProtoMsg); - _pub->send(&msg); - } else { - LOG(ERROR) << "Cannot invoke services with untyped JSON"; - return; + // invoke as service + std::map<umundo::ServiceDescription, umundo::ServiceStub*>::iterator svcIter = _svcs.begin(); + while(svcIter != _svcs.end()) { + umundo::ServiceStub* stub = svcIter->second; + Event event; + void* rv = NULL; + stub->callStubMethod(req.name, pbMsg, type, rv, ""); + protobufToData(event.data, *(const google::protobuf::Message*)rv); + + event.name = _invokeId + ".reply." + req.name; + event.origin = msg.getMeta("um.channel"); + event.origintype = "umundo"; + event.eventType = Event::EXTERNAL; + + returnEvent(event); + svcIter++; } + } + } else { + // just encode JSON + JSONProto* jsonProtoMsg = new JSONProto(); + if (!dataToJSONbuf(jsonProtoMsg, data)) { + LOG(ERROR) << "Cannot create message from JSON - not sending"; + return; + } + if (!_isService) { + // add all s11n properties + _pub->prepareMsg(&msg, "JSON", jsonProtoMsg); + _pub->send(&msg); + } else { + LOG(ERROR) << "Cannot invoke services with untyped JSON"; + return; } - } catch (Event e) { - LOG(ERROR) << "Syntax error when invoking umundo:" << std::endl << e << std::endl; - return; + } - } else { - LOG(ERROR) << "Required JSON object in content" << std::endl; + } catch (Event e) { + LOG(ERROR) << "Syntax error when invoking umundo:" << std::endl << e << std::endl; return; } } @@ -534,7 +535,7 @@ bool UmundoInvoker::dataToProtobuf(google::protobuf::Message* msg, Data& data) { if (data.compound.find(key) == data.compound.end()) { if (fieldDesc->is_required()) { - LOG(ERROR) << "required field " << key << " not given in JSON"; + LOG(ERROR) << "required field " << key << " not given"; return false; } continue; |