chromium/third_party/mediapipe/src/mediapipe/framework/status_handler.h

// Copyright 2019 The MediaPipe Authors.
//
// 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 MEDIAPIPE_FRAMEWORK_STATUS_HANDLER_H_
#define MEDIAPIPE_FRAMEWORK_STATUS_HANDLER_H_

#include <memory>
#include <string>
#include <type_traits>

#include "mediapipe/framework/deps/registration.h"
#include "mediapipe/framework/mediapipe_options.pb.h"
#include "mediapipe/framework/packet_set.h"
#include "mediapipe/framework/packet_type.h"
#include "mediapipe/framework/port.h"
#include "mediapipe/framework/port/status.h"

namespace mediapipe {

// Pure virtual base class for status handlers.
//
// These classes take any number of input side packet packets and process the
// status resulting from a calculator graph run. The status may be OK (if the
// graph run was successful), or may indicate the failure of a PacketGenerator
// or Calculator.
//
// IMPORTANT: If a failure of a PacketGenerator results in missing external
// inputs that were requested (i.e., input side packets that should have been
// generated by a failing PacketGenerator or by a PacketGenerator that had not
// yet executed), the affected StatusHandler will be skipped.
class StatusHandler {};

// Details for the registration of a StatusHandler follow. A user of
// StatusHandler does not need to know about the following code; its purpose is
// to provide functionality akin to virtual static functions.
namespace internal {

class StaticAccessToStatusHandler {};

using StaticAccessToStatusHandlerRegistry =
    GlobalFactoryRegistry<std::unique_ptr<StaticAccessToStatusHandler>>;

// Functions for checking that the StatusHandler has the proper functions
// defined.
template <class T>
constexpr bool StatusHandlerHasFillExpectations(
    decltype(&T::FillExpectations) /* unused */) {}
template <class T>
constexpr bool StatusHandlerHasFillExpectations(...) {}
template <class T>
constexpr bool StatusHandlerHasHandlePreRunStatus(
    decltype(&T::HandlePreRunStatus) /* unused */) {}
template <class T>
constexpr bool StatusHandlerHasHandleStatus(
    decltype(&T::HandleStatus) /* unused */) {}
template <class T>
constexpr bool StatusHandlerHasHandleStatus(...) {}

// Provides access to the static functions within a specific sublcass of
// StatusHandler. See the same mechanism in calculator.h for a more detailed
// explanation.
template <typename StatusHandlerSubclass>
class StaticAccessToStatusHandlerTyped : public StaticAccessToStatusHandler {};

}  // namespace internal

// Macro for registering StatusHandlers. It actually just registers the
// StaticAccessToStatusHandlerTyped class.
#define REGISTER_STATUS_HANDLER(name)

}  // namespace mediapipe

#endif  // MEDIAPIPE_FRAMEWORK_STATUS_HANDLER_H_