Skip to content

Commit 65197e3

Browse files
authored
Remove dependency of uuid, add an option (istio#94)
1 parent dd6b65a commit 65197e3

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

mixerclient/include/client.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ using TransportReportFunc = std::function<void(
4040
const ::istio::mixer::v1::ReportRequest& request,
4141
::istio::mixer::v1::ReportResponse* response, DoneFunc on_done)>;
4242

43+
// Defines a function prototype to generate an UUID
44+
using UUIDGenerateFunc = std::function<std::string()>;
45+
4346
// Defines the options to create an instance of MixerClient interface.
4447
struct MixerClientOptions {
4548
// Default constructor with default values.
@@ -69,6 +72,9 @@ struct MixerClientOptions {
6972
// Don't call it at program start, or init time, it is not ready.
7073
// It is safe to call during Check() or Report() calls.
7174
TimerCreateFunc timer_create_func;
75+
76+
// UUID generating function
77+
UUIDGenerateFunc uuid_generate_func;
7278
};
7379

7480
class MixerClient {

mixerclient/src/client_impl.cc

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include "src/client_impl.h"
1616
#include "utils/protobuf.h"
1717

18-
#include <uuid/uuid.h>
19-
20-
using namespace std::chrono;
2118
using ::istio::mixer::v1::CheckRequest;
2219
using ::istio::mixer::v1::CheckResponse;
2320
using ::istio::mixer::v1::ReportRequest;
@@ -27,21 +24,6 @@ using ::google::protobuf::util::error::Code;
2724

2825
namespace istio {
2926
namespace mixer_client {
30-
namespace {
31-
32-
// Maximum 36 byte string for UUID
33-
const int kMaxUUIDBufSize = 40;
34-
35-
// Genereates a UUID string
36-
std::string GenerateUUID() {
37-
char uuid_buf[kMaxUUIDBufSize];
38-
uuid_t uuid;
39-
uuid_generate(uuid);
40-
uuid_unparse(uuid, uuid_buf);
41-
return uuid_buf;
42-
}
43-
44-
} // namespace
4527

4628
MixerClientImpl::MixerClientImpl(const MixerClientOptions &options)
4729
: options_(options) {
@@ -53,7 +35,9 @@ MixerClientImpl::MixerClientImpl(const MixerClientOptions &options)
5335
quota_cache_ =
5436
std::unique_ptr<QuotaCache>(new QuotaCache(options.quota_options));
5537

56-
deduplication_id_base_ = GenerateUUID();
38+
if (options_.uuid_generate_func) {
39+
deduplication_id_base_ = options_.uuid_generate_func();
40+
}
5741
}
5842

5943
MixerClientImpl::~MixerClientImpl() {}

0 commit comments

Comments
 (0)