From 8ff81f5a2a638d429d84dbac4007eb31e0767cd0 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 23 Oct 2018 22:59:47 -0700 Subject: [PATCH] cscore: Separate platform-specific sources (#1387) --- cscore/.styleguide | 3 + cscore/CMakeLists.txt | 19 +++++ cscore/build.gradle | 33 ++++++++ cscore/src/main/native/cpp/HttpCameraImpl.cpp | 9 --- .../main/native/cpp/UsbCameraImplCommon.cpp | 52 +++++++++++++ cscore/src/main/native/cpp/cscore_cpp.cpp | 42 ---------- .../main/native/cpp/jni/CameraServerJNI.cpp | 22 ------ .../native/{cpp => linux}/NetworkListener.cpp | 0 cscore/src/main/native/linux/NetworkUtil.cpp | 44 +++++++++++ .../native/{cpp => linux}/UsbCameraBuffer.h | 4 - .../native/{cpp => linux}/UsbCameraImpl.cpp | 76 ------------------- .../native/{cpp => linux}/UsbCameraImpl.h | 8 -- .../{cpp => linux}/UsbCameraProperty.cpp | 4 - .../native/{cpp => linux}/UsbCameraProperty.h | 4 - .../main/native/{cpp => linux}/UsbUtil.cpp | 7 -- .../src/main/native/{cpp => linux}/UsbUtil.h | 4 - .../src/main/native/osx/NetworkListener.cpp | 37 +++++++++ cscore/src/main/native/osx/NetworkUtil.cpp | 20 +++++ cscore/src/main/native/osx/UsbCameraImpl.cpp | 34 +++++++++ .../main/native/windows/NetworkListener.cpp | 37 +++++++++ .../src/main/native/windows/NetworkUtil.cpp | 20 +++++ .../src/main/native/windows/UsbCameraImpl.cpp | 34 +++++++++ 22 files changed, 333 insertions(+), 180 deletions(-) create mode 100644 cscore/src/main/native/cpp/UsbCameraImplCommon.cpp rename cscore/src/main/native/{cpp => linux}/NetworkListener.cpp (100%) create mode 100644 cscore/src/main/native/linux/NetworkUtil.cpp rename cscore/src/main/native/{cpp => linux}/UsbCameraBuffer.h (97%) rename cscore/src/main/native/{cpp => linux}/UsbCameraImpl.cpp (95%) rename cscore/src/main/native/{cpp => linux}/UsbCameraImpl.h (98%) rename cscore/src/main/native/{cpp => linux}/UsbCameraProperty.cpp (99%) rename cscore/src/main/native/{cpp => linux}/UsbCameraProperty.h (98%) rename cscore/src/main/native/{cpp => linux}/UsbUtil.cpp (98%) rename cscore/src/main/native/{cpp => linux}/UsbUtil.h (96%) create mode 100644 cscore/src/main/native/osx/NetworkListener.cpp create mode 100644 cscore/src/main/native/osx/NetworkUtil.cpp create mode 100644 cscore/src/main/native/osx/UsbCameraImpl.cpp create mode 100644 cscore/src/main/native/windows/NetworkListener.cpp create mode 100644 cscore/src/main/native/windows/NetworkUtil.cpp create mode 100644 cscore/src/main/native/windows/UsbCameraImpl.cpp diff --git a/cscore/.styleguide b/cscore/.styleguide index f3e6dffe0d..f38c85000a 100644 --- a/cscore/.styleguide +++ b/cscore/.styleguide @@ -19,6 +19,9 @@ licenseUpdateExclude { includeGuardRoots { cscore/src/main/native/cpp/ cscore/src/main/native/include/ + cscore/src/main/native/linux/ + cscore/src/main/native/osx/ + cscore/src/main/native/windows/ cscore/src/main/test/native/cpp/ } diff --git a/cscore/CMakeLists.txt b/cscore/CMakeLists.txt index d742dbcc0d..31fb2f27f6 100644 --- a/cscore/CMakeLists.txt +++ b/cscore/CMakeLists.txt @@ -54,10 +54,29 @@ endif() file(GLOB cscore_native_src src/main/native/cpp/*.cpp) +file(GLOB cscore_linux_src src/main/native/linux/*.cpp) +file(GLOB cscore_osx_src src/main/native/osx/*.cpp) +file(GLOB cscore_windows_src src/main/native/windows/*.cpp) + add_library(cscore ${cscore_native_src} ${cscore_jni_src}) + +if(NOT MSVC) + if (APPLE) + target_sources(cscore PRIVATE ${cscore_osx_src}) + else() + target_sources(cscore PRIVATE ${cscore_linux_src}) + endif() + target_compile_options(cscore PRIVATE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE) +else() + target_sources(cscore PRIVATE ${cscore_windows_src}) + target_compile_options(cscore PUBLIC -DNOMINMAX) + target_compile_options(cscore PRIVATE -D_CRT_SECURE_NO_WARNINGS) +endif() + target_include_directories(cscore PUBLIC $ $) +target_include_directories(cscore PRIVATE src/main/native/cpp) target_link_libraries(cscore PUBLIC wpiutil ${OpenCV_LIBS}) set_property(TARGET cscore PROPERTY FOLDER "libraries") diff --git a/cscore/build.gradle b/cscore/build.gradle index c13040a8b4..6dda16ea3e 100644 --- a/cscore/build.gradle +++ b/cscore/build.gradle @@ -31,6 +31,39 @@ ext { srcDirs 'src/main/native/include' } } + cscoreMacCpp(CppSourceSet) { + source { + srcDirs 'src/main/native/osx' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/main/native/include', 'src/main/native/cpp' + } + } + } + } else if (it.targetPlatform.operatingSystem.name == 'linux') { + it.sources { + cscoreLinuxCpp(CppSourceSet) { + source { + srcDirs 'src/main/native/linux' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/main/native/include', 'src/main/native/cpp' + } + } + } + } else if (it.targetPlatform.operatingSystem.name == 'windows') { + it.sources { + cscoreWindowsCpp(CppSourceSet) { + source { + srcDirs 'src/main/native/windows' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/main/native/include', 'src/main/native/cpp' + } + } } } } diff --git a/cscore/src/main/native/cpp/HttpCameraImpl.cpp b/cscore/src/main/native/cpp/HttpCameraImpl.cpp index 6052cd47b7..464be8dede 100644 --- a/cscore/src/main/native/cpp/HttpCameraImpl.cpp +++ b/cscore/src/main/native/cpp/HttpCameraImpl.cpp @@ -53,15 +53,6 @@ void HttpCameraImpl::Start() { m_settingsThread = std::thread(&HttpCameraImpl::SettingsThreadMain, this); } -#ifdef __linux__ -static inline void DoFdSet(int fd, fd_set* set, int* nfds) { - if (fd >= 0) { - FD_SET(fd, set); - if ((fd + 1) > *nfds) *nfds = fd + 1; - } -} -#endif - void HttpCameraImpl::StreamThreadMain() { while (m_active) { SetConnected(false); diff --git a/cscore/src/main/native/cpp/UsbCameraImplCommon.cpp b/cscore/src/main/native/cpp/UsbCameraImplCommon.cpp new file mode 100644 index 0000000000..6308e80366 --- /dev/null +++ b/cscore/src/main/native/cpp/UsbCameraImplCommon.cpp @@ -0,0 +1,52 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "cscore_c.h" // NOLINT(build/include_order) + +#include "c_util.h" +#include "cscore_cpp.h" + +using namespace cs; + +extern "C" { + +CS_Source CS_CreateUsbCameraDev(const char* name, int dev, CS_Status* status) { + return cs::CreateUsbCameraDev(name, dev, status); +} + +CS_Source CS_CreateUsbCameraPath(const char* name, const char* path, + CS_Status* status) { + return cs::CreateUsbCameraPath(name, path, status); +} + +char* CS_GetUsbCameraPath(CS_Source source, CS_Status* status) { + return ConvertToC(cs::GetUsbCameraPath(source, status)); +} + +CS_UsbCameraInfo* CS_EnumerateUsbCameras(int* count, CS_Status* status) { + auto cameras = cs::EnumerateUsbCameras(status); + CS_UsbCameraInfo* out = static_cast( + wpi::CheckedMalloc(cameras.size() * sizeof(CS_UsbCameraInfo))); + *count = cameras.size(); + for (size_t i = 0; i < cameras.size(); ++i) { + out[i].dev = cameras[i].dev; + out[i].path = ConvertToC(cameras[i].path); + out[i].name = ConvertToC(cameras[i].name); + } + return out; +} + +void CS_FreeEnumeratedUsbCameras(CS_UsbCameraInfo* cameras, int count) { + if (!cameras) return; + for (int i = 0; i < count; ++i) { + std::free(cameras[i].path); + std::free(cameras[i].name); + } + std::free(cameras); +} + +} // extern "C" diff --git a/cscore/src/main/native/cpp/cscore_cpp.cpp b/cscore/src/main/native/cpp/cscore_cpp.cpp index b8e699cae3..f5b6ab0511 100644 --- a/cscore/src/main/native/cpp/cscore_cpp.cpp +++ b/cscore/src/main/native/cpp/cscore_cpp.cpp @@ -7,13 +7,6 @@ #include "cscore_cpp.h" -#if defined(__linux__) -#include -#include -#include -#include -#endif - #include #include "Handle.h" @@ -693,39 +686,4 @@ wpi::ArrayRef EnumerateSinkHandles(wpi::SmallVectorImpl& vec, return Sinks::GetInstance().GetAll(vec); } -std::string GetHostname() { -#ifdef __linux__ - char name[256]; - if (::gethostname(name, sizeof(name)) != 0) return ""; - name[255] = '\0'; // Per POSIX, may not be null terminated if too long - return name; -#else - return ""; // TODO -#endif -} - -std::vector GetNetworkInterfaces() { -#ifdef __linux__ - struct ifaddrs* ifa; - if (::getifaddrs(&ifa) != 0) return std::vector{}; - - std::vector rv; - char buf[256]; - for (struct ifaddrs* i = ifa; i; i = i->ifa_next) { - if (!i->ifa_addr) continue; // no address - if (i->ifa_addr->sa_family != AF_INET) continue; // only return IPv4 - struct sockaddr_in* addr_in = reinterpret_cast(i->ifa_addr); - const char* addr = - ::inet_ntop(addr_in->sin_family, &addr_in->sin_addr, buf, sizeof(buf)); - if (!addr) continue; // error converting address - rv.emplace_back(addr); - } - - ::freeifaddrs(ifa); - return rv; -#else - return std::vector{}; // TODO -#endif -} - } // namespace cs diff --git a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp index 128ca0059a..ebdb3a4429 100644 --- a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp +++ b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp @@ -181,7 +181,6 @@ static inline bool CheckStatus(JNIEnv* env, CS_Status status) { return status == CS_OK; } -#ifdef __linux__ static jobject MakeJObject(JNIEnv* env, const cs::UsbCameraInfo& info) { static jmethodID constructor = env->GetMethodID( usbCameraInfoCls, "", "(ILjava/lang/String;Ljava/lang/String;)V"); @@ -190,7 +189,6 @@ static jobject MakeJObject(JNIEnv* env, const cs::UsbCameraInfo& info) { return env->NewObject(usbCameraInfoCls, constructor, static_cast(info.dev), path.obj(), name.obj()); } -#endif static jobject MakeJObject(JNIEnv* env, const cs::VideoMode& videoMode) { static jmethodID constructor = @@ -406,10 +404,6 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraDev (JNIEnv* env, jclass, jstring name, jint dev) { -#ifndef __linux__ - unsupportedEx.Throw(env, "USB is not supported yet"); - return 0; -#else if (!name) { nullPointerEx.Throw(env, "name cannot be null"); return 0; @@ -418,7 +412,6 @@ Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraDev auto val = cs::CreateUsbCameraDev(JStringRef{env, name}.str(), dev, &status); CheckStatus(env, status); return val; -#endif } /* @@ -430,10 +423,6 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath (JNIEnv* env, jclass, jstring name, jstring path) { -#ifndef __linux__ - unsupportedEx.Throw(env, "USB is not supported yet"); - return 0; -#else if (!name) { nullPointerEx.Throw(env, "name cannot be null"); return 0; @@ -447,7 +436,6 @@ Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath JStringRef{env, path}.str(), &status); CheckStatus(env, status); return val; -#endif } /* @@ -949,15 +937,10 @@ JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraPath (JNIEnv* env, jclass, jint source) { -#ifndef __linux__ - unsupportedEx.Throw(env, "USB is not supported yet"); - return 0; -#else CS_Status status = 0; auto str = cs::GetUsbCameraPath(source, &status); if (!CheckStatus(env, status)) return nullptr; return MakeJString(env, str); -#endif } /* @@ -1582,10 +1565,6 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateUsbCameras (JNIEnv* env, jclass) { -#ifndef __linux__ - unsupportedEx.Throw(env, "USB is not supported yet"); - return 0; -#else CS_Status status = 0; auto arr = cs::EnumerateUsbCameras(&status); if (!CheckStatus(env, status)) return nullptr; @@ -1597,7 +1576,6 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateUsbCameras env->SetObjectArrayElement(jarr, i, jelem); } return jarr; -#endif } /* diff --git a/cscore/src/main/native/cpp/NetworkListener.cpp b/cscore/src/main/native/linux/NetworkListener.cpp similarity index 100% rename from cscore/src/main/native/cpp/NetworkListener.cpp rename to cscore/src/main/native/linux/NetworkListener.cpp diff --git a/cscore/src/main/native/linux/NetworkUtil.cpp b/cscore/src/main/native/linux/NetworkUtil.cpp new file mode 100644 index 0000000000..c8cde8cddd --- /dev/null +++ b/cscore/src/main/native/linux/NetworkUtil.cpp @@ -0,0 +1,44 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "cscore_cpp.h" // NOLINT(build/include_order) + +#include +#include +#include +#include + +namespace cs { + +std::string GetHostname() { + char name[256]; + if (::gethostname(name, sizeof(name)) != 0) return ""; + name[255] = '\0'; // Per POSIX, may not be null terminated if too long + return name; +} + +std::vector GetNetworkInterfaces() { + struct ifaddrs* ifa; + if (::getifaddrs(&ifa) != 0) return std::vector{}; + + std::vector rv; + char buf[256]; + for (struct ifaddrs* i = ifa; i; i = i->ifa_next) { + if (!i->ifa_addr) continue; // no address + if (i->ifa_addr->sa_family != AF_INET) continue; // only return IPv4 + struct sockaddr_in* addr_in = reinterpret_cast(i->ifa_addr); + const char* addr = + ::inet_ntop(addr_in->sin_family, &addr_in->sin_addr, buf, sizeof(buf)); + if (!addr) continue; // error converting address + rv.emplace_back(addr); + } + + ::freeifaddrs(ifa); + return rv; +} + +} // namespace cs diff --git a/cscore/src/main/native/cpp/UsbCameraBuffer.h b/cscore/src/main/native/linux/UsbCameraBuffer.h similarity index 97% rename from cscore/src/main/native/cpp/UsbCameraBuffer.h rename to cscore/src/main/native/linux/UsbCameraBuffer.h index 9adf6e94e2..98ac14982f 100644 --- a/cscore/src/main/native/cpp/UsbCameraBuffer.h +++ b/cscore/src/main/native/linux/UsbCameraBuffer.h @@ -8,9 +8,7 @@ #ifndef CSCORE_USBCAMERABUFFER_H_ #define CSCORE_USBCAMERABUFFER_H_ -#ifdef __linux__ #include -#endif #include @@ -29,7 +27,6 @@ class UsbCameraBuffer { UsbCameraBuffer(const UsbCameraBuffer&) = delete; UsbCameraBuffer& operator=(const UsbCameraBuffer&) = delete; -#ifdef __linux__ UsbCameraBuffer(int fd, size_t length, off_t offset) noexcept : m_length{length} { m_data = @@ -43,7 +40,6 @@ class UsbCameraBuffer { ~UsbCameraBuffer() { if (m_data) munmap(m_data, m_length); } -#endif friend void swap(UsbCameraBuffer& first, UsbCameraBuffer& second) noexcept { using std::swap; diff --git a/cscore/src/main/native/cpp/UsbCameraImpl.cpp b/cscore/src/main/native/linux/UsbCameraImpl.cpp similarity index 95% rename from cscore/src/main/native/cpp/UsbCameraImpl.cpp rename to cscore/src/main/native/linux/UsbCameraImpl.cpp index 4d7363f79a..3fe1963306 100644 --- a/cscore/src/main/native/cpp/UsbCameraImpl.cpp +++ b/cscore/src/main/native/linux/UsbCameraImpl.cpp @@ -7,7 +7,6 @@ #include "UsbCameraImpl.h" -#ifdef __linux__ #include #include #include @@ -22,8 +21,6 @@ #include #include #include -#elif defined(_WIN32) -#endif #include @@ -38,13 +35,10 @@ #include "Notifier.h" #include "Telemetry.h" #include "UsbUtil.h" -#include "c_util.h" #include "cscore_cpp.h" using namespace cs; -#ifdef __linux__ - static constexpr char const* kPropWbAuto = "white_balance_temperature_auto"; static constexpr char const* kPropWbValue = "white_balance_temperature"; static constexpr char const* kPropExAuto = "exposure_auto"; @@ -1320,73 +1314,3 @@ std::vector EnumerateUsbCameras(CS_Status* status) { } } // namespace cs - -extern "C" { - -CS_Source CS_CreateUsbCameraDev(const char* name, int dev, CS_Status* status) { - return cs::CreateUsbCameraDev(name, dev, status); -} - -CS_Source CS_CreateUsbCameraPath(const char* name, const char* path, - CS_Status* status) { - return cs::CreateUsbCameraPath(name, path, status); -} - -char* CS_GetUsbCameraPath(CS_Source source, CS_Status* status) { - return ConvertToC(cs::GetUsbCameraPath(source, status)); -} - -CS_UsbCameraInfo* CS_EnumerateUsbCameras(int* count, CS_Status* status) { - auto cameras = cs::EnumerateUsbCameras(status); - CS_UsbCameraInfo* out = static_cast( - wpi::CheckedMalloc(cameras.size() * sizeof(CS_UsbCameraInfo))); - *count = cameras.size(); - for (size_t i = 0; i < cameras.size(); ++i) { - out[i].dev = cameras[i].dev; - out[i].path = ConvertToC(cameras[i].path); - out[i].name = ConvertToC(cameras[i].name); - } - return out; -} - -void CS_FreeEnumeratedUsbCameras(CS_UsbCameraInfo* cameras, int count) { - if (!cameras) return; - for (int i = 0; i < count; ++i) { - std::free(cameras[i].path); - std::free(cameras[i].name); - } - std::free(cameras); -} - -} // extern "C" - -#else - -extern "C" { - -CS_Source CS_CreateUsbCameraDev(const char* name, int dev, CS_Status* status) { - *status = CS_INVALID_HANDLE; - return 0; -} - -CS_Source CS_CreateUsbCameraPath(const char* name, const char* path, - CS_Status* status) { - *status = CS_INVALID_HANDLE; - return 0; -} - -char* CS_GetUsbCameraPath(CS_Source source, CS_Status* status) { - *status = CS_INVALID_HANDLE; - return nullptr; -} - -CS_UsbCameraInfo* CS_EnumerateUsbCameras(int* count, CS_Status* status) { - *status = CS_INVALID_HANDLE; - return nullptr; -} - -void CS_FreeEnumeratedUsbCameras(CS_UsbCameraInfo* cameras, int count) {} - -} // extern "C" - -#endif // __linux__ diff --git a/cscore/src/main/native/cpp/UsbCameraImpl.h b/cscore/src/main/native/linux/UsbCameraImpl.h similarity index 98% rename from cscore/src/main/native/cpp/UsbCameraImpl.h rename to cscore/src/main/native/linux/UsbCameraImpl.h index 6037033743..fecd1c0992 100644 --- a/cscore/src/main/native/cpp/UsbCameraImpl.h +++ b/cscore/src/main/native/linux/UsbCameraImpl.h @@ -8,9 +8,7 @@ #ifndef CSCORE_USBCAMERAIMPL_H_ #define CSCORE_USBCAMERAIMPL_H_ -#ifdef __linux__ #include -#endif #include #include @@ -145,24 +143,18 @@ class UsbCameraImpl : public SourceImpl { bool m_modeSetResolution{false}; bool m_modeSetFPS{false}; int m_connectVerbose{1}; -#ifdef __linux__ unsigned m_capabilities = 0; -#endif // Number of buffers to ask OS for static constexpr int kNumBuffers = 4; -#ifdef __linux__ std::array m_buffers; -#endif // // Path never changes, so not protected by mutex. // std::string m_path; -#ifdef __linux__ std::atomic_int m_fd; std::atomic_int m_command_fd; // for command eventfd -#endif std::atomic_bool m_active; // set to false to terminate thread std::thread m_cameraThread; diff --git a/cscore/src/main/native/cpp/UsbCameraProperty.cpp b/cscore/src/main/native/linux/UsbCameraProperty.cpp similarity index 99% rename from cscore/src/main/native/cpp/UsbCameraProperty.cpp rename to cscore/src/main/native/linux/UsbCameraProperty.cpp index c58280beb5..6976095e11 100644 --- a/cscore/src/main/native/cpp/UsbCameraProperty.cpp +++ b/cscore/src/main/native/linux/UsbCameraProperty.cpp @@ -14,8 +14,6 @@ using namespace cs; -#ifdef __linux__ - static int GetIntCtrlIoctl(int fd, unsigned id, int type, int64_t* value) { unsigned ctrl_class = V4L2_CTRL_ID2CLASS(id); if (type == V4L2_CTRL_TYPE_INTEGER64 || V4L2_CTRL_DRIVER_PRIV(id) || @@ -322,5 +320,3 @@ bool UsbCameraProperty::DeviceSet(std::unique_lock& lock, int fd, return rv >= 0; } - -#endif // __linux__ diff --git a/cscore/src/main/native/cpp/UsbCameraProperty.h b/cscore/src/main/native/linux/UsbCameraProperty.h similarity index 98% rename from cscore/src/main/native/cpp/UsbCameraProperty.h rename to cscore/src/main/native/linux/UsbCameraProperty.h index fd804f56b7..446deab613 100644 --- a/cscore/src/main/native/cpp/UsbCameraProperty.h +++ b/cscore/src/main/native/linux/UsbCameraProperty.h @@ -8,9 +8,7 @@ #ifndef CSCORE_USBCAMERAPROPERTY_H_ #define CSCORE_USBCAMERAPROPERTY_H_ -#ifdef __linux__ #include -#endif #include @@ -50,7 +48,6 @@ class UsbCameraProperty : public PropertyImpl { maximum = 100; } -#ifdef __linux__ #ifdef VIDIOC_QUERY_EXT_CTRL explicit UsbCameraProperty(const struct v4l2_query_ext_ctrl& ctrl); #endif @@ -62,7 +59,6 @@ class UsbCameraProperty : public PropertyImpl { bool DeviceSet(std::unique_lock& lock, int fd) const; bool DeviceSet(std::unique_lock& lock, int fd, int newValue, const wpi::Twine& newValueStr) const; -#endif // If this is a device (rather than software) property bool device{true}; diff --git a/cscore/src/main/native/cpp/UsbUtil.cpp b/cscore/src/main/native/linux/UsbUtil.cpp similarity index 98% rename from cscore/src/main/native/cpp/UsbUtil.cpp rename to cscore/src/main/native/linux/UsbUtil.cpp index 07b8eddf29..1ecb887500 100644 --- a/cscore/src/main/native/cpp/UsbUtil.cpp +++ b/cscore/src/main/native/linux/UsbUtil.cpp @@ -8,11 +8,8 @@ #include "UsbUtil.h" #include - -#ifdef __linux__ #include #include -#endif #include #include @@ -23,8 +20,6 @@ namespace cs { -#ifdef __linux__ - static wpi::StringRef GetUsbNameFromFile(int vendor, int product, wpi::SmallVectorImpl& buf) { int fd = open("/var/lib/usbutils/usb.ids", O_RDONLY); @@ -161,6 +156,4 @@ int CheckedIoctl(int fd, unsigned long req, void* data, // NOLINT(runtime/int) return retval; } -#endif // __linux__ - } // namespace cs diff --git a/cscore/src/main/native/cpp/UsbUtil.h b/cscore/src/main/native/linux/UsbUtil.h similarity index 96% rename from cscore/src/main/native/cpp/UsbUtil.h rename to cscore/src/main/native/linux/UsbUtil.h index 6ecb0a8afa..4f1d9d8bc1 100644 --- a/cscore/src/main/native/cpp/UsbUtil.h +++ b/cscore/src/main/native/linux/UsbUtil.h @@ -15,8 +15,6 @@ namespace cs { -#ifdef __linux__ - wpi::StringRef GetUsbNameFromId(int vendor, int product, wpi::SmallVectorImpl& buf); @@ -28,8 +26,6 @@ int CheckedIoctl(int fd, unsigned long req, void* data, // NOLINT(runtime/int) #define TryIoctl(fd, req, data) \ CheckedIoctl(fd, req, data, #req, __FILE__, __LINE__, true) -#endif // __linux__ - } // namespace cs #endif // CSCORE_USBUTIL_H_ diff --git a/cscore/src/main/native/osx/NetworkListener.cpp b/cscore/src/main/native/osx/NetworkListener.cpp new file mode 100644 index 0000000000..e52d105813 --- /dev/null +++ b/cscore/src/main/native/osx/NetworkListener.cpp @@ -0,0 +1,37 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "NetworkListener.h" + +#include "Log.h" +#include "Notifier.h" + +using namespace cs; + +class NetworkListener::Thread : public wpi::SafeThread { + public: + void Main(); +}; + +NetworkListener::~NetworkListener() { Stop(); } + +void NetworkListener::Start() { + auto thr = m_owner.GetThread(); + if (!thr) m_owner.Start(); +} + +void NetworkListener::Stop() { + // Wake up thread + if (auto thr = m_owner.GetThread()) { + thr->m_active = false; + } + m_owner.Stop(); +} + +void NetworkListener::Thread::Main() { + // TODO +} diff --git a/cscore/src/main/native/osx/NetworkUtil.cpp b/cscore/src/main/native/osx/NetworkUtil.cpp new file mode 100644 index 0000000000..654b801a79 --- /dev/null +++ b/cscore/src/main/native/osx/NetworkUtil.cpp @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "cscore_cpp.h" + +namespace cs { + +std::string GetHostname() { + return ""; // TODO +} + +std::vector GetNetworkInterfaces() { + return std::vector{}; // TODO +} + +} // namespace cs diff --git a/cscore/src/main/native/osx/UsbCameraImpl.cpp b/cscore/src/main/native/osx/UsbCameraImpl.cpp new file mode 100644 index 0000000000..e9a47c889b --- /dev/null +++ b/cscore/src/main/native/osx/UsbCameraImpl.cpp @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "cscore_cpp.h" + +namespace cs { + +CS_Source CreateUsbCameraDev(const wpi::Twine& name, int dev, + CS_Status* status) { + *status = CS_INVALID_HANDLE; + return 0; +} + +CS_Source CreateUsbCameraPath(const wpi::Twine& name, const wpi::Twine& path, + CS_Status* status) { + *status = CS_INVALID_HANDLE; + return 0; +} + +std::string GetUsbCameraPath(CS_Source source, CS_Status* status) { + *status = CS_INVALID_HANDLE; + return std::string{}; +} + +std::vector EnumerateUsbCameras(CS_Status* status) { + *status = CS_INVALID_HANDLE; + return std::vector{}; +} + +} // namespace cs diff --git a/cscore/src/main/native/windows/NetworkListener.cpp b/cscore/src/main/native/windows/NetworkListener.cpp new file mode 100644 index 0000000000..e52d105813 --- /dev/null +++ b/cscore/src/main/native/windows/NetworkListener.cpp @@ -0,0 +1,37 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "NetworkListener.h" + +#include "Log.h" +#include "Notifier.h" + +using namespace cs; + +class NetworkListener::Thread : public wpi::SafeThread { + public: + void Main(); +}; + +NetworkListener::~NetworkListener() { Stop(); } + +void NetworkListener::Start() { + auto thr = m_owner.GetThread(); + if (!thr) m_owner.Start(); +} + +void NetworkListener::Stop() { + // Wake up thread + if (auto thr = m_owner.GetThread()) { + thr->m_active = false; + } + m_owner.Stop(); +} + +void NetworkListener::Thread::Main() { + // TODO +} diff --git a/cscore/src/main/native/windows/NetworkUtil.cpp b/cscore/src/main/native/windows/NetworkUtil.cpp new file mode 100644 index 0000000000..654b801a79 --- /dev/null +++ b/cscore/src/main/native/windows/NetworkUtil.cpp @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "cscore_cpp.h" + +namespace cs { + +std::string GetHostname() { + return ""; // TODO +} + +std::vector GetNetworkInterfaces() { + return std::vector{}; // TODO +} + +} // namespace cs diff --git a/cscore/src/main/native/windows/UsbCameraImpl.cpp b/cscore/src/main/native/windows/UsbCameraImpl.cpp new file mode 100644 index 0000000000..e9a47c889b --- /dev/null +++ b/cscore/src/main/native/windows/UsbCameraImpl.cpp @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "cscore_cpp.h" + +namespace cs { + +CS_Source CreateUsbCameraDev(const wpi::Twine& name, int dev, + CS_Status* status) { + *status = CS_INVALID_HANDLE; + return 0; +} + +CS_Source CreateUsbCameraPath(const wpi::Twine& name, const wpi::Twine& path, + CS_Status* status) { + *status = CS_INVALID_HANDLE; + return 0; +} + +std::string GetUsbCameraPath(CS_Source source, CS_Status* status) { + *status = CS_INVALID_HANDLE; + return std::string{}; +} + +std::vector EnumerateUsbCameras(CS_Status* status) { + *status = CS_INVALID_HANDLE; + return std::vector{}; +} + +} // namespace cs