7#include "TypeService.h"
11#include "Connection.h"
12#include "Exceptions.h"
15#include <Atlas/Objects/Operation.h>
16#include <Atlas/Objects/RootEntity.h>
17#include <Atlas/Objects/RootOperation.h>
18#include <Atlas/Objects/Anonymous.h>
20using namespace Atlas::Objects::Operation;
21using Atlas::Objects::Root;
22using Atlas::Objects::Entity::RootEntity;
23using Atlas::Objects::Entity::Anonymous;
24using Atlas::Objects::smart_dynamic_cast;
29TypeService::TypeService(Connection &con) :
33 defineBuiltin(
"root",
nullptr);
36TypeService::~TypeService() =
default;
38void TypeService::init()
46 for (
auto& type : m_types) {
47 if (!type.second->isBound()) sendRequest(type.second->getName());
51TypeInfo* TypeService::findTypeByName(
const std::string &
id)
53 auto T = m_types.find(
id);
54 if (T != m_types.end()) {
55 return T->second.get();
61TypeInfo* TypeService::getTypeByName(
const std::string &
id)
63 auto T = m_types.find(
id);
64 if (T != m_types.end()) {
65 return T->second.get();
71 m_types[id] = std::unique_ptr<TypeInfo>(node);
77TypeInfo* TypeService::getTypeForAtlas(
const Root &obj)
80 if (obj->getParent().empty()) {
82 return getTypeByName(
"root");
85 return getTypeByName(obj->getParent());
88void TypeService::handleOperation(
const RootOperation& op)
90 if (op->instanceOf(ERROR_NO)) {
91 auto message = getErrorMessage(op);
92 notice() <<
"Error from server when requesting type: " << message;
93 auto& args = op->getArgs();
94 for (
const auto& arg : args) {
95 Get request = smart_dynamic_cast<Get>(arg);
100 }
else if (op->instanceOf(CHANGE_NO)) {
101 const std::vector<Root>& args(op->getArgs());
102 for (
const auto& arg : args) {
103 if (!arg->isDefaultObjtype()) {
104 auto& objType = arg->getObjtype();
105 if ((objType ==
"meta") ||
106 (objType ==
"class") ||
107 (objType ==
"op_definition") ||
108 (objType ==
"archetype")) {
113 }
else if (op->instanceOf(INFO_NO)) {
114 const std::vector<Root>& args(op->getArgs());
115 for (
const auto& arg : args) {
116 if (!arg->isDefaultObjtype()) {
117 auto& objType = arg->getObjtype();
119 if ((objType ==
"meta") ||
120 (objType ==
"class") ||
121 (objType ==
"op_definition") ||
122 (objType ==
"archetype")) {
128 error() <<
"type service got op that wasn't info or error";
132void TypeService::recvTypeInfo(
const Root &atype)
134 auto T = m_types.find(atype->getId());
135 if (T == m_types.end()) {
136 error() <<
"received type object with unknown ID " << atype->getId();
140 T->second->processTypeData(atype);
143void TypeService::recvTypeUpdate(
const Root &atype)
147 auto T = m_types.find(atype->getId());
148 if (T == m_types.end()) {
152 sendRequest(atype->getId());
155void TypeService::sendRequest(
const std::string &
id)
159 if (!m_inited)
return;
167 if (!m_type_provider_id.empty()) {
168 get->setFrom(m_type_provider_id);
171 m_con.getResponder().await(get->getSerialno(),
this, &TypeService::handleOperation);
175void TypeService::recvError(
const Get& get)
177 const std::vector<Root>& args = get->getArgs();
179 for (
const auto& request: args) {
180 if (!request->isDefaultId()) {
181 auto T = m_types.find(request->getId());
182 if (T == m_types.end()) {
184 error() <<
"got ERROR(GET()) with request for unknown type: " + request->getId();
188 warning() <<
"type " << request->getId() <<
" undefined on server";
189 BadType.emit(T->second.get());
197TypeInfo* TypeService::defineBuiltin(
const std::string& name, TypeInfo* parent)
199 assert(m_types.count(name) == 0);
201 auto type =
new TypeInfo(name, *
this);
202 m_types[name] = std::unique_ptr<TypeInfo>(type);
205 type->setParent(parent);
207 type->validateBind();
209 assert(type->isBound());
213void TypeService::setTypeProviderId(std::string
id) {
214 m_type_provider_id = std::move(
id);
The representation of an Atlas type (i.e a class or operation definition). This class supports effice...
std::int64_t getNewSerialno()
operation serial number sequencing