wpilibc: Remove direct CameraServer dependency (#1989)

This makes linking easier, particularly for third party vendors and other language wrappers.
This commit is contained in:
Thad House
2019-10-27 08:37:30 -07:00
committed by Peter Johnson
parent 8e333c0aad
commit 936627bd94
10 changed files with 142 additions and 62 deletions

View File

@@ -7,19 +7,34 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <cscore_c.h>
#ifndef DYNAMIC_CAMERA_SERVER
#include <cscore_oo.h>
#else
namespace cs {
class VideoSource;
} // namespace cs
typedef int CS_Handle;
typedef CS_Handle CS_Source;
#endif
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace cs {
class VideoSource;
} // namespace cs
namespace frc {
class SendableCameraWrapper;
namespace detail {
constexpr const char* kProtocol = "camera_server://";
std::shared_ptr<SendableCameraWrapper>& GetSendableCameraWrapper(
CS_Source source);
void AddToSendableRegistry(Sendable* sendable, std::string name);
} // namespace detail
/**
* A wrapper to make video sources sendable and usable from Shuffleboard.
*/
@@ -54,4 +69,27 @@ class SendableCameraWrapper : public Sendable,
std::string m_uri;
};
#ifndef DYNAMIC_CAMERA_SERVER
inline SendableCameraWrapper::SendableCameraWrapper(CS_Source source,
const private_init&)
: m_uri(detail::kProtocol) {
CS_Status status = 0;
auto name = cs::GetSourceName(source, &status);
detail::AddToSendableRegistry(this, name);
m_uri += name;
}
inline SendableCameraWrapper& SendableCameraWrapper::Wrap(
const cs::VideoSource& source) {
return Wrap(source.GetHandle());
}
inline SendableCameraWrapper& SendableCameraWrapper::Wrap(CS_Source source) {
auto& wrapper = detail::GetSendableCameraWrapper(source);
if (!wrapper)
wrapper = std::make_shared<SendableCameraWrapper>(source, private_init{});
return *wrapper;
}
#endif
} // namespace frc

View File

@@ -501,3 +501,17 @@ class ShuffleboardContainer : public virtual ShuffleboardValue,
#include "frc/shuffleboard/ComplexWidget.h"
#include "frc/shuffleboard/ShuffleboardLayout.h"
#include "frc/shuffleboard/SimpleWidget.h"
#ifndef DYNAMIC_CAMERA_SERVER
#include "frc/shuffleboard/SendableCameraWrapper.h"
inline frc::ComplexWidget& frc::ShuffleboardContainer::Add(
const cs::VideoSource& video) {
return Add(frc::SendableCameraWrapper::Wrap(video));
}
inline frc::ComplexWidget& frc::ShuffleboardContainer::Add(
const wpi::Twine& title, const cs::VideoSource& video) {
return Add(title, frc::SendableCameraWrapper::Wrap(video));
}
#endif