Program Listing for File Event.hpp

Return to documentation for file (/tmp/ws/src/rmf_task/rmf_task/include/rmf_task/Event.hpp)

/*
 * Copyright (C) 2021 Open Source Robotics Foundation
 *
 * 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 RMF_TASK__EVENT_HPP
#define RMF_TASK__EVENT_HPP

#include <rmf_task/Log.hpp>
#include <rmf_task/VersionedString.hpp>

#include <rmf_utils/impl_ptr.hpp>

#include <chrono>
#include <memory>
#include <string>
#include <vector>

namespace rmf_task {

//==============================================================================
class Event
{
public:

  enum class Status : uint32_t
  {
    Uninitialized = 0,

    Blocked,

    Error,

    Failed,

    Standby,

    Underway,

    Delayed,

    Skipped,

    Canceled,

    Killed,

    Completed,
  };

  static Status sequence_status(Status earlier, Status later);

  class State;
  using ConstStatePtr = std::shared_ptr<const State>;

  class Snapshot;
  using ConstSnapshotPtr = std::shared_ptr<const Snapshot>;

  class AssignID;
  using AssignIDPtr = std::shared_ptr<const AssignID>;
};

//==============================================================================
class Event::State
{
public:

  using Status = Event::Status;
  using ConstStatePtr = Event::ConstStatePtr;

  virtual uint64_t id() const = 0;

  virtual Status status() const = 0;

  bool finished() const;

  virtual VersionedString::View name() const = 0;

  virtual VersionedString::View detail() const = 0;

  virtual Log::View log() const = 0;

  virtual std::vector<ConstStatePtr> dependencies() const = 0;

  // Virtual destructor
  virtual ~State() = default;
};

//==============================================================================
class Event::Snapshot : public Event::State
{
public:

  static ConstSnapshotPtr make(const State& other);

  // Documentation inherited
  uint64_t id() const final;

  // Documentation inherited
  Status status() const final;

  // Documentation inherited
  VersionedString::View name() const final;

  // Documentation inherited
  VersionedString::View detail() const final;

  // Documentation inherited
  Log::View log() const final;

  // Documentation inherited
  std::vector<ConstStatePtr> dependencies() const final;

  class Implementation;
private:
  Snapshot();
  rmf_utils::impl_ptr<Implementation> _pimpl;
};

//==============================================================================
class Event::AssignID
{
public:

  static AssignIDPtr make();

  AssignID();

  uint64_t assign() const;

  class Implementation;
private:
  rmf_utils::unique_impl_ptr<Implementation> _pimpl;
};

} // namespace rmf_task

#endif // RMF_TASK__EVENT_HPP