--- /dev/null
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd 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 UTILS_CALLBACK_PAIR_H
+#define UTILS_CALLBACK_PAIR_H
+
+#include <functional>
+
+namespace Utils
+{
+ /**
+ * @brief Represents two callbacks to be called subsequently.
+ * @details Next callback is called each time when operator() is used.
+ */
+ class CallbackPair
+ {
+ public:
+ typedef std::function<void()> Callback;
+
+ /**
+ * @brief Create callback pair.
+ * @param[in] first First callback
+ * @param[in] second Second callback
+ */
+ CallbackPair(Callback first, Callback second)
+ : m_Callbacks{ std::move(first), std::move(second) }, m_IsFirst(true)
+ {
+ }
+
+ /**
+ * @brief Call next callback.
+ */
+ void operator()()
+ {
+ if (m_IsFirst) {
+ m_Callbacks.first();
+ } else {
+ m_Callbacks.second();
+ }
+ m_IsFirst = !m_IsFirst;
+ }
+
+ private:
+ std::pair<Callback, Callback> m_Callbacks;
+ bool m_IsFirst;
+ };
+
+ /**
+ * @brief Provides possibility to pass a result from first callback to the second.
+ * @see CallbackPair.
+ */
+ template <typename ResultType>
+ class CallbackPairWithResult
+ {
+ public:
+ /**
+ * @brief First callback.
+ * @return Result to pass to the second callback.
+ */
+ typedef std::function<ResultType()> FirstCallback;
+
+ /**
+ * @brief Second callback.
+ * @param[in] Result received from the first callback.
+ */
+ typedef std::function<void(ResultType)> SecondCallback;
+
+ /**
+ * @brief Create callback pair.
+ * @param[in] first First callback
+ * @param[in] second Second callback
+ */
+ CallbackPairWithResult(FirstCallback first, SecondCallback second)
+ : m_Callbacks{ std::move(first), std::move(second) }, m_IsFirst(true)
+ {
+ }
+
+ /**
+ * @brief Call next callback.
+ */
+ void operator()()
+ {
+ if (m_IsFirst) {
+ m_Result = m_Callbacks.first();
+ } else {
+ m_Callbacks.second(std::move(m_Result));
+ }
+ m_IsFirst = !m_IsFirst;
+ }
+
+ private:
+ std::pair<FirstCallback, SecondCallback> m_Callbacks;
+ ResultType m_Result;
+ bool m_IsFirst;
+ };
+}
+
+#endif /* UTILS_CALLBACK_PAIR_H */