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> 21 using Atlas::Objects::Root;
22 using Atlas::Objects::Entity::RootEntity;
23 using Atlas::Objects::Entity::Anonymous;
24 using Atlas::Objects::smart_dynamic_cast;
29 TypeService::TypeService(Connection &con) :
33 defineBuiltin(
"root",
nullptr);
36 TypeService::~TypeService() =
default;
38 void TypeService::init()
47 if (!type.second->isBound())
sendRequest(type.second->getName());
53 auto T = m_types.find(
id);
54 if (T != m_types.end()) {
55 return T->second.get();
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);
80 if (obj->getParent().empty()) {
88 void 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";
132 void 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);
143 void TypeService::recvTypeUpdate(
const Root &atype)
147 auto T = m_types.find(atype->getId());
148 if (T == m_types.end()) {
159 if (!m_inited)
return;
171 m_con.getResponder().await(get->getSerialno(),
this, &TypeService::handleOperation);
175 void 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";
197 TypeInfo* 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());
std::unordered_map< std::string, std::unique_ptr< TypeInfo > > m_types
The representation of an Atlas type (i.e a class or operation definition). This class supports effice...
sigc::signal< void, TypeInfo * > BadType
TypeInfo * findTypeByName(const std::string &tynm)
void setTypeProviderId(std::string id)
Set another provider of type data than the connection.
virtual void send(const Atlas::Objects::Root &obj)
Transmit an Atlas::Objects instance to the server.
TypeInfo * getTypeForAtlas(const Atlas::Objects::Root &obj)
std::int64_t getNewSerialno()
operation serial number sequencing
std::string m_type_provider_id
void sendRequest(const std::string &id)
TypeInfo * getTypeByName(const std::string &tynm)