|
| 1 | +/* Copyright 2017 Google Inc. All Rights Reserved. |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | +#include "src/client_impl.h" |
| 16 | +#include "mixer/api/v1/service.pb.h" |
| 17 | + |
| 18 | +using ::istio::mixer::v1::CheckRequest; |
| 19 | +using ::istio::mixer::v1::CheckResponse; |
| 20 | +using ::istio::mixer::v1::ReportRequest; |
| 21 | +using ::istio::mixer::v1::ReportResponse; |
| 22 | +using ::istio::mixer::v1::QuotaRequest; |
| 23 | +using ::istio::mixer::v1::QuotaResponse; |
| 24 | + |
| 25 | +using ::google::protobuf::util::Status; |
| 26 | +using ::google::protobuf::util::error::Code; |
| 27 | + |
| 28 | +namespace istio { |
| 29 | +namespace mixer_client { |
| 30 | + |
| 31 | +MixerClientImpl::MixerClientImpl(MixerClientOptions &options) |
| 32 | + : options_(options) {} |
| 33 | + |
| 34 | +MixerClientImpl::~MixerClientImpl() {} |
| 35 | + |
| 36 | +void MixerClientImpl::Check(const CheckRequest &check_request, |
| 37 | + CheckResponse *check_response, |
| 38 | + DoneFunc on_check_done) { |
| 39 | + if (options_.check_transport == NULL) { |
| 40 | + on_check_done(Status(Code::INVALID_ARGUMENT, "transport is NULL.")); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + options_.check_transport(check_request, check_response, on_check_done); |
| 45 | +} |
| 46 | + |
| 47 | +void MixerClientImpl::Report(const ReportRequest &report_request, |
| 48 | + ReportResponse *report_response, |
| 49 | + DoneFunc on_report_done) { |
| 50 | + if (options_.report_transport == NULL) { |
| 51 | + on_report_done(Status(Code::INVALID_ARGUMENT, "transport is NULL.")); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + options_.report_transport(report_request, report_response, on_report_done); |
| 56 | +} |
| 57 | + |
| 58 | +void MixerClientImpl::Quota(const QuotaRequest "a_request, |
| 59 | + QuotaResponse *quota_response, |
| 60 | + DoneFunc on_quota_done) { |
| 61 | + if (options_.quota_transport == NULL) { |
| 62 | + on_quota_done(Status(Code::INVALID_ARGUMENT, "transport is NULL.")); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + options_.quota_transport(quota_request, quota_response, on_quota_done); |
| 67 | +} |
| 68 | + |
| 69 | +// Creates a MixerClient object. |
| 70 | +std::unique_ptr<MixerClient> CreateMixerClient(MixerClientOptions &options) { |
| 71 | + return std::unique_ptr<MixerClient>(new MixerClientImpl(options)); |
| 72 | +} |
| 73 | + |
| 74 | +} // namespace mixer_client |
| 75 | +} // namespace istio |
0 commit comments