11 #include <shared_mutex> 13 #include <unordered_map> 15 #include "../macros.h" 16 #include "../misc_p.h" 23 std::unordered_map<std::string, std::shared_ptr<VariantHelperBase>> types_;
24 mutable std::shared_timed_mutex mutex_;
27 VariantTypeRegistry::VariantTypeRegistry()
28 : d_ptr(std::make_unique<VariantTypeRegistryPrivate>()) {
29 registerType<std::string>();
30 registerType<uint8_t>();
32 registerType<int16_t>();
33 registerType<uint16_t>();
34 registerType<int32_t>();
35 registerType<uint32_t>();
36 registerType<int64_t>();
37 registerType<uint64_t>();
39 registerType<FCITX_STRING_TO_DBUS_TYPE(
"a{sv}")>();
40 registerType<FCITX_STRING_TO_DBUS_TYPE(
"as")>();
41 registerType<ObjectPath>();
42 registerType<Variant>();
45 void VariantTypeRegistry::registerTypeImpl(
46 const std::string &signature, std::shared_ptr<VariantHelperBase> helper) {
48 std::lock_guard<std::shared_timed_mutex> lock(d->mutex_);
49 if (d->types_.count(signature)) {
52 d->types_.emplace(signature, std::move(helper));
55 std::shared_ptr<VariantHelperBase>
56 VariantTypeRegistry::lookupType(
const std::string &signature)
const {
58 std::shared_lock<std::shared_timed_mutex> lock(d->mutex_);
59 const auto *v = findValue(d->types_, signature);
60 return v ? *v :
nullptr;
68 std::shared_ptr<VariantHelperBase>
69 lookupVariantType(
const std::string &signature) {
70 return VariantTypeRegistry::defaultRegistry().lookupType(signature);
74 helper_->serialize(msg, data_.get());
Basic DBus type of a DBus message.
API for dbus variant type.
We need to "predefine some of the variant type that we want to handle".