27 #include "dynamic_protobuf_manager.h"
28 #include "exception.h"
31 std::shared_ptr<dccl::DynamicProtobufManager> dccl::DynamicProtobufManager::inst_;
36 const google::protobuf::Descriptor*
40 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
41 const google::protobuf::Descriptor* desc =
nullptr;
45 desc = get_instance()->user_descriptor_pool_->FindMessageTypeByName(protobuf_type_name);
51 desc = google::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName(
59 desc = get_instance()->user_descriptor_pool_->FindMessageTypeByName(protobuf_type_name);
65 std::shared_ptr<google::protobuf::Message>
68 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
69 return new_protobuf_message<std::shared_ptr<google::protobuf::Message>>(desc);
72 std::shared_ptr<google::protobuf::Message>
75 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
76 return new_protobuf_message<std::shared_ptr<google::protobuf::Message>>(protobuf_type_name);
80 std::shared_ptr<google::protobuf::DescriptorDatabase> database)
82 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
83 get_instance()->databases_.push_back(database);
84 get_instance()->update_databases();
89 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
91 if (!get_instance()->disk_source_tree_)
92 throw(std::runtime_error(
93 "Must called enable_compilation() before loading proto files directly"));
95 get_instance()->disk_source_tree_->MapPath(
"", path);
100 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
101 void* handle = dlopen(shared_lib_path.c_str(), RTLD_LAZY);
103 get_instance()->dl_handles_.push_back(handle);
112 const google::protobuf::FileDescriptor*
115 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
117 if (!get_instance()->source_database_)
119 "Must called enable_compilation() before loading proto files directly"));
121 return get_instance()->user_descriptor_pool_->FindFileByName(protofile_absolute_path);
124 const google::protobuf::FileDescriptor*
127 DCCL_LOCK_DYNAMIC_PROTOBUF_MANAGER_MUTEX
128 get_instance()->simple_database_->Add(proto);
130 const google::protobuf::FileDescriptor* return_desc =
131 get_instance()->user_descriptor_pool_->FindFileByName(proto.name());
139 void dccl::DynamicProtobufManager::enable_disk_source_database()
141 if (disk_source_tree_)
144 disk_source_tree_.reset(
new google::protobuf::compiler::DiskSourceTree);
145 source_database_.reset(
146 new google::protobuf::compiler::SourceTreeDescriptorDatabase(disk_source_tree_.get()));
147 error_collector_.reset(
new DLogMultiFileErrorCollector);
149 source_database_->RecordErrorsTo(error_collector_.get());
150 disk_source_tree_->MapPath(
"/",
"/");
151 disk_source_tree_->MapPath(
"",
"");
152 add_database(source_database_);
156 void dccl::DynamicProtobufManager::DLogMultiFileErrorCollector::AddError(
157 const std::string& filename,
int line,
int column,
const std::string& message)
159 std::stringstream ss;
160 ss <<
"File: " << filename <<
" has error (line: " << line <<
", column: " << column