Skip to content

Commit

Permalink
Merge pull request envoyproxy#9 from qiwzhang/use_attribute
Browse files Browse the repository at this point in the history
Support attributes in the interface.
  • Loading branch information
qiwzhang authored Jan 18, 2017
2 parents 5241c55 + 43511d7 commit 017f722
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mixerclient/include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef MIXERCLIENT_CLIENT_H
#define MIXERCLIENT_CLIENT_H

#include <chrono>
#include <functional>
#include <memory>
#include <string>
Expand Down Expand Up @@ -58,11 +59,42 @@ struct MixerClientOptions {
TransportInterface* transport;
};

struct Attributes {
// A structure to hold different types of value.
struct Value {
// Data type
enum ValueType { STRING, INT64, DOUBLE, BOOL, TIME, BYTES } type;

// Data value
union {
std::string str_v; // for both STRING and BYTES
int64_t int64_v;
double double_v;
bool bool_v;
std::chrono::time_point<std::chrono::system_clock> time_v;
} value;
};

std::map<std::string, Value> attributes;
};

class MixerClient {
public:
// Destructor
virtual ~MixerClient() {}

// Attribute based calls will be used.
// The protobuf message based calls will be removed.
// Callers should pass in the full set of attributes for the call.
// The client will use the full set attributes to check cache. If cache
// miss, an attribute context based on the underline gRPC stream will
// be used to generate attribute_update and send that to Mixer server.
// Callers don't need response data, they only need success or failure.
// The response data from mixer will be consumed by mixer client.
virtual void Check(const Attributes& attributes, DoneFunc on_done) = 0;
virtual void Report(const Attributes& attributes, DoneFunc on_done) = 0;
virtual void Quota(const Attributes& attributes, DoneFunc on_done) = 0;

// The async call.
// on_check_done is called with the check status after cached
// check_response is returned in case of cache hit, otherwise called after
Expand Down
12 changes: 12 additions & 0 deletions mixerclient/src/client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ MixerClientImpl::MixerClientImpl(const MixerClientOptions &options)

MixerClientImpl::~MixerClientImpl() {}

void MixerClientImpl::Check(const Attributes &attributes, DoneFunc on_done) {
on_done(Status(Code::UNIMPLEMENTED, "Method not implemented."));
}

void MixerClientImpl::Report(const Attributes &attributes, DoneFunc on_done) {
on_done(Status(Code::UNIMPLEMENTED, "Method not implemented."));
}

void MixerClientImpl::Quota(const Attributes &attributes, DoneFunc on_done) {
on_done(Status(Code::UNIMPLEMENTED, "Method not implemented."));
}

void MixerClientImpl::Check(const CheckRequest &request,
CheckResponse *response, DoneFunc on_done) {
check_transport_.Call(request, response, on_done);
Expand Down
4 changes: 4 additions & 0 deletions mixerclient/src/client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class MixerClientImpl : public MixerClient {
// Destructor
virtual ~MixerClientImpl();

virtual void Check(const Attributes& attributes, DoneFunc on_done);
virtual void Report(const Attributes& attributes, DoneFunc on_done);
virtual void Quota(const Attributes& attributes, DoneFunc on_done);

// The async call.
// on_check_done is called with the check status after cached
// check_response is returned in case of cache hit, otherwise called after
Expand Down

0 comments on commit 017f722

Please sign in to comment.