Commit c53ca2f3 authored by Kenton Varda's avatar Kenton Varda

Associate 'Capability' type with null interface schema.

parent c6712690
......@@ -55,14 +55,6 @@ public:
RemotePromise& operator=(RemotePromise&& other) = default;
};
struct Capability {
// A capability without type-safe methods. Typed capability clients wrap `Client` and typed
// capability servers subclass `Server` to dispatch to the regular, typed methods.
class Client;
class Server;
};
// =======================================================================================
class RequestHook;
......
......@@ -107,6 +107,20 @@ namespace _ { // private
template <typename T, Kind k> struct Kind_<List<T, k>> { static constexpr Kind kind = Kind::LIST; };
} // namespace _ (private)
struct Capability {
// A capability without type-safe methods. Typed capability clients wrap `Client` and typed
// capability servers subclass `Server` to dispatch to the regular, typed methods.
//
// Contents defined in capability.h. Declared here just so we can specialize Kind_.
class Client;
class Server;
};
namespace _ { // private
template <> struct Kind_<Capability> { static constexpr Kind kind = Kind::INTERFACE; };
} // namespace _ (private)
template <typename T, Kind k = kind<T>()> struct ReaderFor_ { typedef typename T::Reader Type; };
template <typename T> struct ReaderFor_<T, Kind::PRIMITIVE> { typedef T Type; };
template <typename T> struct ReaderFor_<T, Kind::ENUM> { typedef T Type; };
......
......@@ -108,8 +108,13 @@ inline const RawSchema& rawSchema() {
return RawSchema_<T>::get();
}
template <typename T>
struct TypeId_;
template <typename T> struct TypeId_;
extern const RawSchema NULL_INTERFACE_SCHEMA; // defined in schema.c++
template <> struct TypeId_<Capability> { static constexpr uint64_t typeId = 0x03; };
template <> struct RawSchema_<Capability> {
static inline const RawSchema& get() { return NULL_INTERFACE_SCHEMA; }
};
template <typename T>
struct UnionMemberIndex_;
......
......@@ -262,6 +262,9 @@ TEST(Schema, NullSchemas) {
EXPECT_EQ("(null enum schema)", EnumSchema().getProto().getDisplayName());
EXPECT_EQ("(null interface schema)", InterfaceSchema().getProto().getDisplayName());
EXPECT_EQ("(null const schema)", ConstSchema().getProto().getDisplayName());
EXPECT_TRUE(Schema::from<Capability>() == InterfaceSchema());
EXPECT_EQ(InterfaceSchema().getProto().getId(), typeId<Capability>());
}
} // namespace
......
......@@ -31,7 +31,7 @@ namespace _ { // private
// Null schemas generated using the below schema file with:
//
// capnp eval -Isrc null-schemas.capnp interface --flat |
// capnp eval -Isrc null-schemas.capnp node --flat |
// hexdump -v -e '8/1 "0x%02x, "' -e '1/8 "\n"'; echo
//
// I totally don't understand hexdump format strings and came up with this command based on trial
......@@ -428,6 +428,10 @@ InterfaceSchema::Method InterfaceSchema::getMethodByName(kj::StringPtr name) con
}
bool InterfaceSchema::extends(InterfaceSchema other) const {
if (other.raw == &_::NULL_INTERFACE_SCHEMA) {
// We consider all interfaces to extend the null schema.
return true;
}
uint counter = 0;
return extends(other, counter);
}
......@@ -453,6 +457,10 @@ bool InterfaceSchema::extends(InterfaceSchema other, uint& counter) const {
}
kj::Maybe<InterfaceSchema> InterfaceSchema::findSuperclass(uint64_t typeId) const {
if (typeId == _::NULL_INTERFACE_SCHEMA.id) {
// We consider all interfaces to extend the null schema.
return InterfaceSchema();
}
uint counter = 0;
return findSuperclass(typeId, counter);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment