Browse files

Add a means of retrieving attribute types

  • Loading branch information...
1 parent a4e03be commit efd08ecd7b4803b84d8b4c37cf76aa0e56768107 @rescrv committed Jul 14, 2012
Showing with 64 additions and 0 deletions.
  1. +28 −0 hyperclient/hyperclient.cc
  2. +14 −0 hyperclient/hyperclient.h
  3. +22 −0 hyperclient/hyperclient_c_wrappers.cc
View
28 hyperclient/hyperclient.cc
@@ -560,6 +560,34 @@ hyperclient :: loop(int timeout, hyperclient_returncode* status)
abort();
}
+enum hyperdatatype
+hyperclient :: attribute_type(const char* space, const char* name,
+ enum hyperclient_returncode* status)
+{
+ if (maintain_coord_connection(status) < 0)
+ {
+ return HYPERDATATYPE_GARBAGE;
+ }
+
+ schema* sc = m_config->get_schema(space);
+
+ if (!sc)
+ {
+ *status = HYPERCLIENT_UNKNOWNSPACE;
+ return HYPERDATATYPE_GARBAGE;
+ }
+
+ uint16_t attrnum = sc->lookup_attr(name);
+
+ if (attrnum == sc->attrs_sz)
+ {
+ *status = HYPERCLIENT_UNKNOWNATTR;
+ return HYPERDATATYPE_GARBAGE;
+ }
+
+ return sc->attrs[attrnum].type;
+}
+
// XXX If we lose the coord connection, this whole thing fails.
// It would be better if we could stay alive when the coordinator dies (assuming
// the config does not change).
View
14 hyperclient/hyperclient.h
@@ -670,6 +670,17 @@ int64_t
hyperclient_loop(struct hyperclient* client, int timeout,
enum hyperclient_returncode* status);
+/* Retrieve the datatype for the attribute "name" in the space "space".
+ *
+ * This will return a valid attribute, or return HYPERDATATYPE_GARBAGE if either
+ * "space" or "name" do not exist. If it returns an error, "status" will
+ * indicate the problem.
+ */
+enum hyperdatatype
+hyperclient_attribute_type(struct hyperclient* client,
+ const char* space, const char* name,
+ enum hyperclient_returncode* status);
+
/* Free an array of hyperclient_attribute objects. This typically corresponds
* to the value returned by the get call.
*
@@ -814,6 +825,9 @@ class hyperclient
const struct hyperclient_range_query* rn, size_t rn_sz,
enum hyperclient_returncode* status, uint64_t* result);
int64_t loop(int timeout, hyperclient_returncode* status);
+ // Introspect things
+ hyperdatatype attribute_type(const char* space, const char* name,
+ enum hyperclient_returncode* status);
private:
class completedop;
View
22 hyperclient/hyperclient_c_wrappers.cc
@@ -316,6 +316,28 @@ hyperclient_loop(struct hyperclient* client, int timeout, hyperclient_returncode
}
}
+enum hyperdatatype
+hyperclient_attribute_type(struct hyperclient* client,
+ const char* space, const char* name,
+ enum hyperclient_returncode* status)
+{
+ try
+ {
+ return client->attribute_type(space, name, status);
+ }
+ catch (po6::error& e)
+ {
+ errno = e;
+ *status = HYPERCLIENT_EXCEPTION;
+ return HYPERDATATYPE_GARBAGE;
+ }
+ catch (...)
+ {
+ *status = HYPERCLIENT_EXCEPTION;
+ return HYPERDATATYPE_GARBAGE;
+ }
+}
+
void
hyperclient_destroy_attrs(struct hyperclient_attribute* attrs, size_t /*attrs_sz*/)
{

0 comments on commit efd08ec

Please sign in to comment.