Skip to content

Commit

Permalink
Add a means of retrieving attribute types
Browse files Browse the repository at this point in the history
  • Loading branch information
rescrv committed Jul 15, 2012
1 parent a4e03be commit efd08ec
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
28 changes: 28 additions & 0 deletions hyperclient/hyperclient.cc
Expand Up @@ -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).
Expand Down
14 changes: 14 additions & 0 deletions hyperclient/hyperclient.h
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions hyperclient/hyperclient_c_wrappers.cc
Expand Up @@ -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*/)
{
Expand Down

0 comments on commit efd08ec

Please sign in to comment.