diff --git a/mixerclient/BUILD b/mixerclient/BUILD index 901451cf3738..cab781e4e0fe 100644 --- a/mixerclient/BUILD +++ b/mixerclient/BUILD @@ -42,6 +42,7 @@ cc_library( "include/attribute.h", "include/client.h", "include/options.h", + "include/timer.h", ], visibility = ["//visibility:public"], deps = [ diff --git a/mixerclient/include/client.h b/mixerclient/include/client.h index 596c438112a4..10e4a26df56d 100644 --- a/mixerclient/include/client.h +++ b/mixerclient/include/client.h @@ -20,6 +20,7 @@ #include "google/protobuf/stubs/status.h" #include "mixer/v1/service.pb.h" #include "options.h" +#include "timer.h" namespace istio { namespace mixer_client { @@ -64,6 +65,9 @@ struct MixerClientOptions { TransportCheckFunc check_transport; TransportReportFunc report_transport; TransportQuotaFunc quota_transport; + + // Timer create function. + TimerCreateFunc timer_create_func; }; class MixerClient { diff --git a/mixerclient/include/timer.h b/mixerclient/include/timer.h new file mode 100644 index 000000000000..04af96fd4c67 --- /dev/null +++ b/mixerclient/include/timer.h @@ -0,0 +1,47 @@ +/* Copyright 2017 Istio Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MIXERCLIENT_TIMER_H +#define MIXERCLIENT_TIMER_H + +#include + +namespace istio { +namespace mixer_client { + +// Represent a timer created by caller's environment. +class Timer { + public: + // Delete the timer, stopping it first if needed. + virtual ~Timer() {} + + // Stop a pending timeout without destroying the underlying timer. + virtual void Stop() = 0; + + // Start a pending timeout. If a timeout is already pending, + // it will be reset to the new timeout. + virtual void Start(int interval_ms) = 0; +}; + +// Defines a function to create a timer calling the function +// with desired interval. The returned object can be used to stop +// the timer. +using TimerCreateFunc = + std::function(std::function timer_func)>; + +} // namespace mixer_client +} // namespace istio + +#endif // MIXERCLIENT_TIMER_H