Fix the conflict

This commit is contained in:
kalman
2018-11-24 16:43:38 +08:00
264 changed files with 29737 additions and 970 deletions

View File

@@ -0,0 +1 @@
#include "mynteye/api/api.h"

View File

@@ -0,0 +1 @@
#include "mynteye/device/callbacks.h"

View File

@@ -0,0 +1 @@
#include "mynteye/device/context.h"

View File

@@ -0,0 +1 @@
#include "mynteye/device/device.h"

View File

@@ -0,0 +1 @@
#include "mynteye/util/files.h"

View File

@@ -0,0 +1 @@
#include "mynteye/logger.h"

View File

@@ -0,0 +1 @@
#include "mynteye/api/object.h"

View File

@@ -0,0 +1 @@
#include "mynteye/api/plugin.h"

View File

@@ -0,0 +1 @@
#include "mynteye/util/strings.h"

View File

@@ -0,0 +1 @@
#include "mynteye/util/times.h"

View File

@@ -0,0 +1 @@
#include "mynteye/device/utils.h"

297
include/mynteye/api/api.h Normal file
View File

@@ -0,0 +1,297 @@
// Copyright 2018 Slightech 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 MYNTEYE_API_API_H_
#define MYNTEYE_API_API_H_
#pragma once
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <opencv2/core/core.hpp>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
class Device;
class Synthetic;
namespace device {
class Frame;
} // namespace device
namespace api {
/**
* @ingroup datatypes
* API stream data.
*/
struct MYNTEYE_API StreamData {
/** ImgData. */
std::shared_ptr<ImgData> img;
/** Frame. */
cv::Mat frame;
/** Raw frame. */
std::shared_ptr<device::Frame> frame_raw;
/** Frame ID. */
std::uint16_t frame_id;
bool operator==(const StreamData &other) const {
if (img && other.img) {
return img->frame_id == other.img->frame_id &&
img->timestamp == other.img->timestamp;
}
return false;
}
};
/**
* @ingroup datatypes
* API motion data.
*/
struct MYNTEYE_API MotionData {
/** ImuData. */
std::shared_ptr<ImuData> imu;
bool operator==(const MotionData &other) const {
if (imu && other.imu) {
return imu->timestamp == other.imu->timestamp;
}
return false;
}
};
} // namespace api
/**
* The API class to communicate with MYNT® EYE device.
*/
class MYNTEYE_API API {
public:
/** The api::StreamData callback. */
using stream_callback_t = std::function<void(const api::StreamData &data)>;
/** The api::MotionData callback. */
using motion_callback_t = std::function<void(const api::MotionData &data)>;
explicit API(std::shared_ptr<Device> device);
virtual ~API();
/**
* Create the API instance.
* @return the API instance.
* @note This will call device::select() to select a device.
*/
static std::shared_ptr<API> Create(Resolution res);
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(
std::shared_ptr<Device> device, Resolution res);
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @return the API instance.
* @note This will init glog with args and call device::select() to select a
* device.
*/
static std::shared_ptr<API> Create(int argc, char *argv[]);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @param device the selected device.
* @return the API instance.
* @note This will init glog with args.
*/
static std::shared_ptr<API> Create(
int argc, char *argv[], std::shared_ptr<Device> device);
/**
* Get the model.
*/
Model GetModel() const;
/**
* Supports the stream or not.
*/
bool Supports(const Stream &stream) const;
/**
* Supports the capability or not.
*/
bool Supports(const Capabilities &capability) const;
/**
* Supports the option or not.
*/
bool Supports(const Option &option) const;
/**
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
/**
* set the stream request.
*/
void SetStreamRequest(const Format &format, const FrameRate &rate);
/**
* Get all stream requests of the capability.
*/
const std::vector<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;
/**
* Config the stream request to the capability.
*/
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
/**
* Get the device info.
*/
std::string GetInfo(const Info &info) const;
/**
* Get the intrinsics of stream.
*/
Intrinsics GetIntrinsics(const Stream &stream) const;
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics() const;
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from) const;
/**
* Log all option infos.
*/
void LogOptionInfos() const;
/**
* Get the option info.
*/
OptionInfo GetOptionInfo(const Option &option) const;
/**
* Get the option value.
*/
std::int32_t GetOptionValue(const Option &option) const;
/**
* Set the option value.
*/
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Run the option action.
*/
bool RunOptionAction(const Option &option) const;
/**
* Set the callback of stream.
*/
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
/**
* Set the callback of motion.
*/
void SetMotionCallback(motion_callback_t callback);
/**
* Has the callback of stream.
*/
bool HasStreamCallback(const Stream &stream) const;
/**
* Has the callback of motion.
*/
bool HasMotionCallback() const;
/**
* Start capturing the source.
*/
void Start(const Source &source);
/**
* Stop capturing the source.
*/
void Stop(const Source &source);
/**
* Wait the streams are ready.
*/
void WaitForStreams();
/**
* Enable the data of stream.
* @note must enable the stream if it's a synthetic one. This means the stream
* in not native, the device has the capability to provide this stream, but
* still support this stream.
*/
void EnableStreamData(const Stream &stream);
/**
* Disable the data of stream.
*/
void DisableStreamData(const Stream &stream);
/**
* Get the latest data of stream.
*/
api::StreamData GetStreamData(const Stream &stream);
/**
* Get the datas of stream.
* @note default cache 4 datas at most.
*/
std::vector<api::StreamData> GetStreamDatas(const Stream &stream);
/**
* Enable cache motion datas.
*/
void EnableMotionDatas(
std::size_t max_size = std::numeric_limits<std::size_t>::max());
/**
* Get the motion datas.
*/
std::vector<api::MotionData> GetMotionDatas();
/**
* Enable the plugin.
*/
void EnablePlugin(const std::string &path);
std::shared_ptr<Device> device();
private:
std::shared_ptr<Device> device_;
std::unique_ptr<Synthetic> synthetic_;
void CheckImageParams();
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_API_API_H_

View File

@@ -0,0 +1,129 @@
// Copyright 2018 Slightech 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 MYNTEYE_API_OBJECT_H_
#define MYNTEYE_API_OBJECT_H_
#pragma once
#include <memory>
#include <opencv2/core/core.hpp>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
struct ImgData;
/**
* Input & output object.
*/
struct MYNTEYE_API Object {
Object() = default;
virtual ~Object() = default;
virtual Object *Clone() const = 0;
virtual bool DecValidity() const = 0;
/** Cast the obj to T pointer */
template <typename T>
static T *Cast(Object *obj) {
return dynamic_cast<T *>(obj);
}
/** Cast the obj to const T pointer */
template <typename T>
static const T *Cast(const Object *obj) {
return dynamic_cast<const T *>(obj);
}
template <typename T>
static std::shared_ptr<T> Cast(const std::shared_ptr<Object> &obj) {
return std::dynamic_pointer_cast<T>(obj);
}
};
/**
* Input & output object of one cv::Mat.
*/
struct MYNTEYE_API ObjMat : public Object {
ObjMat() = default;
ObjMat(const cv::Mat &value, std::uint16_t id,
const std::shared_ptr<ImgData> &data)
: value(value), id(id), data(data) {}
/** The value */
cv::Mat value;
/** The id **/
std::uint16_t id;
/** The data **/
std::shared_ptr<ImgData> data;
Object *Clone() const {
ObjMat *mat = new ObjMat;
mat->value = value.clone();
mat->id = id;
mat->data = data;
return mat;
}
bool DecValidity() const {
return !value.empty();
}
};
/**
* Input & output object of two cv::Mat.
*/
struct MYNTEYE_API ObjMat2 : public Object {
ObjMat2() = default;
ObjMat2(const cv::Mat &first, std::uint16_t first_id,
const std::shared_ptr<ImgData> &first_data,
const cv::Mat &second, std::uint16_t second_id,
const std::shared_ptr<ImgData> &second_data)
: first(first), first_id(first_id), first_data(first_data),
second(second), second_id(second_id), second_data(second_data) {}
/** The first value */
cv::Mat first;
/** The first id **/
std::uint16_t first_id;
/** The first data **/
std::shared_ptr<ImgData> first_data;
/** The second value */
cv::Mat second;
/** The second id **/
std::uint16_t second_id;
/** The second data **/
std::shared_ptr<ImgData> second_data;
Object *Clone() const {
ObjMat2 *mat2 = new ObjMat2;
mat2->first = first.clone();
mat2->first_id = first_id;
mat2->first_data = first_data;
mat2->second = second.clone();
mat2->second_id = second_id;
mat2->second_data = second_data;
return mat2;
}
bool DecValidity() const {
return !first.empty() && !second.empty();
}
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_API_OBJECT_H_

View File

@@ -0,0 +1,141 @@
// Copyright 2018 Slightech 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 MYNTEYE_API_PLUGIN_H_
#define MYNTEYE_API_PLUGIN_H_
#pragma once
#include <cstdint>
#include <opencv2/core/core.hpp>
#include "mynteye/mynteye.h"
#ifndef MYNTEYE_PLUGIN_VERSION_CODE
#define MYNTEYE_PLUGIN_VERSION_CODE 0
#endif
MYNTEYE_BEGIN_NAMESPACE
class API;
struct Object;
/**
* The plugin which could implement processing by yourself.
*/
class MYNTEYE_API Plugin {
public:
Plugin() = default;
virtual ~Plugin() = 0;
/**
* Called when plugin created.
* @param api the API instacne.
*/
virtual void OnCreate(API *api) {
api_ = api;
}
/**
* Called when process rectify.
* @param in input object.
* @param out output object.
* @return `true` if you process rectify.
*/
virtual bool OnRectifyProcess(Object *const in, Object *const out) {
MYNTEYE_UNUSED(in)
MYNTEYE_UNUSED(out)
return false;
}
/**
* Called when process disparity.
* @param in input object.
* @param out output object.
* @return `true` if you process disparity.
*/
virtual bool OnDisparityProcess(Object *const in, Object *const out) {
MYNTEYE_UNUSED(in)
MYNTEYE_UNUSED(out)
return false;
}
/**
* Called when process normalized disparity.
* @param in input object.
* @param out output object.
* @return `true` if you process normalized disparity.
*/
virtual bool OnDisparityNormalizedProcess(
Object *const in, Object *const out) {
MYNTEYE_UNUSED(in)
MYNTEYE_UNUSED(out)
return false;
}
/**
* Called when process points.
* @param in input object.
* @param out output object.
* @return `true` if you process points.
*/
virtual bool OnPointsProcess(Object *const in, Object *const out) {
MYNTEYE_UNUSED(in)
MYNTEYE_UNUSED(out)
return false;
}
/**
* Called when process depth.
* @param in input object.
* @param out output object.
* @return `true` if you process depth.
*/
virtual bool OnDepthProcess(Object *const in, Object *const out) {
MYNTEYE_UNUSED(in)
MYNTEYE_UNUSED(out)
return false;
}
protected:
API *api_;
};
inline Plugin::~Plugin() = default;
using plugin_version_code_t = std::uint32_t();
using plugin_create_t = Plugin *();
using plugin_destroy_t = void(Plugin *);
MYNTEYE_END_NAMESPACE
extern "C" {
/**
* Get the plugin version code.
*/
MYNTEYE_API std::uint32_t plugin_version_code();
/**
* Create the plugin.
*/
MYNTEYE_API mynteye::Plugin *plugin_create();
/**
* Destroy the plugin.
*/
MYNTEYE_API void plugin_destroy(mynteye::Plugin *plugin);
}
#endif // MYNTEYE_API_PLUGIN_H_

View File

@@ -11,8 +11,8 @@
// 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 MYNTEYE_CALLBACKS_H_ // NOLINT
#define MYNTEYE_CALLBACKS_H_
#ifndef MYNTEYE_DEVICE_CALLBACKS_H_
#define MYNTEYE_DEVICE_CALLBACKS_H_
#pragma once
#include <cstdint>
@@ -113,6 +113,8 @@ struct MYNTEYE_API StreamData {
std::shared_ptr<ImgData> img;
/** Frame. */
std::shared_ptr<Frame> frame;
/** Frame ID. */
std::uint16_t frame_id;
};
/**
@@ -131,4 +133,4 @@ using MotionCallback = std::function<void(const MotionData &data)>;
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_CALLBACKS_H_ NOLINT
#endif // MYNTEYE_DEVICE_CALLBACKS_H_

View File

@@ -0,0 +1,56 @@
// Copyright 2018 Slightech 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 MYNTEYE_DEVICE_CONTEXT_H_
#define MYNTEYE_DEVICE_CONTEXT_H_
#pragma once
#include <memory>
#include <vector>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
namespace uvc {
struct context;
} // namespace uvc
class Device;
/**
* The context about devices.
*/
class MYNTEYE_API Context {
public:
Context();
~Context();
/**
* Get all devices now.
* @return a vector of all devices.
*/
std::vector<std::shared_ptr<Device>> devices() const {
return devices_;
}
private:
std::shared_ptr<uvc::context> context_;
std::vector<std::shared_ptr<Device>> devices_;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DEVICE_CONTEXT_H_

View File

@@ -0,0 +1,343 @@
// Copyright 2018 Slightech 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 MYNTEYE_DEVICE_DEVICE_H_
#define MYNTEYE_DEVICE_DEVICE_H_
#pragma once
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
#include "mynteye/device/callbacks.h"
MYNTEYE_BEGIN_NAMESPACE
namespace uvc {
struct device;
} // namespace uvc
namespace tools {
class DeviceWriter;
} // namespace tools
struct DeviceInfo;
class API;
class Channels;
class Motions;
class Streams;
template <class Data>
class AsyncCallback;
/**
* The Device class to communicate with MYNT® EYE device.
*/
class MYNTEYE_API Device {
public:
/** The device::StreamData callback. */
using stream_callback_t = device::StreamCallback;
/** The device::MotionData callback. */
using motion_callback_t = device::MotionCallback;
using stream_callbacks_t = std::map<Stream, stream_callback_t>;
using stream_async_callback_t = AsyncCallback<device::StreamData>;
using motion_async_callback_t = AsyncCallback<device::MotionData>;
using stream_async_callback_ptr_t = std::shared_ptr<stream_async_callback_t>;
using motion_async_callback_ptr_t = std::shared_ptr<motion_async_callback_t>;
Device(const Model &model, std::shared_ptr<uvc::device> device);
virtual ~Device();
/**
* Create the Device instance.
* @param name the device name.
* @param device the device from uvc.
* @return the Device instance.
*/
static std::shared_ptr<Device> Create(
const std::string &name, std::shared_ptr<uvc::device> device);
/**
* Get the model.
*/
Model GetModel() const {
return model_;
}
/**
* Supports the stream or not.
*/
bool Supports(const Stream &stream) const;
/**
* Supports the capability or not.
*/
bool Supports(const Capabilities &capability) const;
/**
* Supports the option or not.
*/
bool Supports(const Option &option) const;
/**
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
/**
* Init device resolution.
*/
void InitResolution(const Resolution &res);
/**
* set the stream request.
*/
void SetStreamRequest(const Format &format, const FrameRate &rate);
/**
* Get all stream requests of the capability.
*/
const std::vector<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;
/**
* Config the stream request to the capability.
*/
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
/**
* Get the device info.
*/
std::shared_ptr<DeviceInfo> GetInfo() const;
/**
* Get the device info of a field.
*/
std::string GetInfo(const Info &info) const;
/**
* Get the intrinsics of stream.
*/
Intrinsics GetIntrinsics(const Stream &stream) const;
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics() const;
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from) const;
/**
* Get the intrinsics of stream.
*/
Intrinsics GetIntrinsics(const Stream &stream, bool *ok) const;
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(
const Stream &from, const Stream &to, bool *ok) const;
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics(bool *ok) const;
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from, bool *ok) const;
/**
* Set the intrinsics of stream.
*/
void SetIntrinsics(const Stream &stream, const Intrinsics &in);
/**
* Set the extrinsics from one stream to another.
*/
void SetExtrinsics(
const Stream &from, const Stream &to, const Extrinsics &ex);
/**
* Set the intrinsics of motion.
*/
void SetMotionIntrinsics(const MotionIntrinsics &in);
/**
* Set the extrinsics from one stream to motion.
*/
void SetMotionExtrinsics(const Stream &from, const Extrinsics &ex);
/**
* Log all option infos.
*/
void LogOptionInfos() const;
/**
* Get the option info.
*/
OptionInfo GetOptionInfo(const Option &option) const;
/**
* Get the option value.
*/
std::int32_t GetOptionValue(const Option &option) const;
/**
* Set the option value.
*/
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Run the option action.
*/
bool RunOptionAction(const Option &option) const;
/**
* Set the callback of stream.
*/
void SetStreamCallback(
const Stream &stream, stream_callback_t callback, bool async = false);
/**
* Set the callback of motion.
*/
void SetMotionCallback(motion_callback_t callback, bool async = false);
/**
* Has the callback of stream.
*/
bool HasStreamCallback(const Stream &stream) const;
/**
* Has the callback of motion.
*/
bool HasMotionCallback() const;
/**
* Start capturing the source.
*/
virtual void Start(const Source &source);
/**
* Stop capturing the source.
*/
virtual void Stop(const Source &source);
/**
* Wait the streams are ready.
*/
void WaitForStreams();
/**
* Get the datas of stream.
* @note default cache 4 datas at most.
*/
std::vector<device::StreamData> GetStreamDatas(const Stream &stream);
/**
* Get the latest data of stream.
*/
device::StreamData GetLatestStreamData(const Stream &stream);
/**
* Enable cache motion datas.
*/
void EnableMotionDatas();
/**
* Enable cache motion datas.
*/
void EnableMotionDatas(std::size_t max_size);
/**
* Get the motion datas.
*/
std::vector<device::MotionData> GetMotionDatas();
/**
* Get the device img params
*/
Channels::img_params_t GetImgParams();
protected:
std::shared_ptr<uvc::device> device() const {
return device_;
}
std::shared_ptr<Streams> streams() const {
return streams_;
}
std::shared_ptr<Channels> channels() const {
return channels_;
}
std::shared_ptr<Motions> motions() const {
return motions_;
}
const StreamRequest &GetStreamRequest(const Capabilities &capability);
virtual void StartVideoStreaming();
virtual void StopVideoStreaming();
virtual void StartMotionTracking();
virtual void StopMotionTracking();
virtual void OnStereoStreamUpdate();
virtual std::vector<Stream> GetKeyStreams() const = 0;
bool video_streaming_;
bool motion_tracking_;
private:
Model model_;
Resolution res_ = Resolution::RES_752x480;
StreamRequest request_;
std::shared_ptr<uvc::device> device_;
std::shared_ptr<DeviceInfo> device_info_;
std::map<Stream, Intrinsics> stream_intrinsics_;
std::map<Stream, std::map<Stream, Extrinsics>> stream_from_extrinsics_;
std::shared_ptr<MotionIntrinsics> motion_intrinsics_;
std::map<Stream, Extrinsics> motion_from_extrinsics_;
Channels::img_params_t img_params_;
stream_callbacks_t stream_callbacks_;
motion_callback_t motion_callback_;
std::map<Stream, stream_async_callback_ptr_t> stream_async_callbacks_;
motion_async_callback_ptr_t motion_async_callback_;
std::shared_ptr<Streams> streams_;
std::map<Capabilities, StreamRequest> stream_config_requests_;
std::mutex mtx_streams_;
std::shared_ptr<Channels> channels_;
std::shared_ptr<Motions> motions_;
void ReadAllInfos();
void ConfigIntrinsics(const Resolution &res);
void CallbackPushedStreamData(const Stream &stream);
void CallbackMotionData(const device::MotionData &data);
friend API;
friend tools::DeviceWriter;
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DEVICE_DEVICE_H_

View File

@@ -11,11 +11,12 @@
// 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 MYNTEYE_UTILS_H_ // NOLINT
#define MYNTEYE_UTILS_H_
#ifndef MYNTEYE_DEVICE_UTILS_H_
#define MYNTEYE_DEVICE_UTILS_H_
#pragma once
#include <memory>
#include <string>
#include "mynteye/mynteye.h"
@@ -55,8 +56,22 @@ namespace utils {
MYNTEYE_API float get_real_exposure_time(
std::int32_t frame_rate, std::uint16_t exposure_time);
/**
* @ingroup utils
*
* Get sdk root dir.
*/
MYNTEYE_API std::string get_sdk_root_dir();
/**
* @ingroup utils
*
* Get sdk install dir.
*/
MYNTEYE_API std::string get_sdk_install_dir();
} // namespace utils
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_UTILS_H_ NOLINT
#endif // MYNTEYE_DEVICE_UTILS_H_

View File

@@ -16,72 +16,70 @@
#pragma once
#ifdef _WIN32
#define OS_WIN
#ifdef _WIN64
#define OS_WIN64
#else
#define OS_WIN32
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#define OS_MINGW
#ifdef __MINGW64__
#define OS_MINGW64
#else
#define OS_MINGW32
#endif
#elif defined(__CYGWIN__) || defined(__CYGWIN32__)
#define OS_CYGWIN
#endif
#define MYNTEYE_OS_WIN
#ifdef _WIN64
#define MYNTEYE_OS_WIN64
#else
#define MYNTEYE_OS_WIN32
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#define MYNTEYE_OS_MINGW
#ifdef __MINGW64__
#define MYNTEYE_OS_MINGW64
#else
#define MYNTEYE_OS_MINGW32
#endif
#elif defined(__CYGWIN__) || defined(__CYGWIN32__)
#define MYNTEYE_OS_CYGWIN
#endif
#elif __APPLE__
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
#define OS_IPHONE
#define OS_IPHONE_SIMULATOR
#elif TARGET_OS_IPHONE
#define OS_IPHONE
#elif TARGET_OS_MAC
#define OS_MAC
#else
#error "Unknown Apple platform"
#endif
#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR
#define MYNTEYE_OS_IPHONE
#define MYNTEYE_OS_IPHONE_SIMULATOR
#elif TARGET_OS_IPHONE
#define MYNTEYE_OS_IPHONE
#elif TARGET_OS_MAC
#define MYNTEYE_OS_MAC
#else
#error "Unknown Apple platform"
#endif
#elif __ANDROID__
#define OS_ANDROID
#define MYNTEYE_OS_ANDROID
#elif __linux__
#define OS_LINUX
#define MYNTEYE_OS_LINUX
#elif __unix__
#define OS_UNIX
#define MYNTEYE_OS_UNIX
#elif defined(_POSIX_VERSION)
#define OS_POSIX
#define MYNTEYE_OS_POSIX
#else
#error "Unknown compiler"
#error "Unknown compiler"
#endif
#ifdef OS_WIN
#define DECL_EXPORT __declspec(dllexport)
#define DECL_IMPORT __declspec(dllimport)
#define DECL_HIDDEN
#ifdef MYNTEYE_OS_WIN
#define MYNTEYE_DECL_EXPORT __declspec(dllexport)
#define MYNTEYE_DECL_IMPORT __declspec(dllimport)
#define MYNTEYE_DECL_HIDDEN
#else
#define DECL_EXPORT __attribute__((visibility("default")))
#define DECL_IMPORT __attribute__((visibility("default")))
#define DECL_HIDDEN __attribute__((visibility("hidden")))
#define MYNTEYE_DECL_EXPORT __attribute__((visibility("default")))
#define MYNTEYE_DECL_IMPORT __attribute__((visibility("default")))
#define MYNTEYE_DECL_HIDDEN __attribute__((visibility("hidden")))
#endif
#if defined(OS_WIN) && !defined(OS_MINGW) && !defined(OS_CYGWIN)
#if defined(MYNTEYE_OS_WIN) && !defined(MYNTEYE_OS_MINGW) && \
!defined(MYNTEYE_OS_CYGWIN)
#define MYNTEYE_OS_SEP "\\"
#else
#define MYNTEYE_OS_SEP "/"
#endif
#define STRINGIFY_HELPER(X) #X
#define STRINGIFY(X) STRINGIFY_HELPER(X)
#define MYNTEYE_STRINGIFY_HELPER(X) #X
#define MYNTEYE_STRINGIFY(X) MYNTEYE_STRINGIFY_HELPER(X)
#define DISABLE_COPY(Class) \
#define MYNTEYE_DISABLE_COPY(Class) \
Class(const Class &) = delete; \
Class &operator=(const Class &) = delete;
#define UNUSED(x) (void)x;
template <typename... T>
void unused(T &&...) {}
#define MYNTEYE_UNUSED(x) (void)x;
#endif // MYNTEYE_GLOBAL_H_

View File

@@ -103,25 +103,25 @@
#include "mynteye/mynteye.h"
#ifdef MYNTEYE_OS_ANDROID
#include <android/log.h>
# include <android/log.h>
#endif // ANDROID
// Log severity level constants.
#ifdef MYNTEYE_OS_WIN
const int FATAL = -1;
const int FATAL = -1;
#ifndef ERROR // NOT windows.h
const int ERROR = 0;
const int ERROR = 0;
#endif
const int WARNING = 1;
const int INFO = 2;
const int INFO = 2;
#else
const int FATAL = -3;
const int ERROR = -2;
const int FATAL = -3;
const int ERROR = -2;
const int WARNING = -1;
const int INFO = 0;
const int INFO = 0;
#endif
@@ -130,12 +130,12 @@ const int INFO = 0;
namespace google {
typedef int LogSeverity;
const int FATAL = ::FATAL;
const int FATAL = ::FATAL;
#ifndef ERROR // NOT windows.h
const int ERROR = ::ERROR;
const int ERROR = ::ERROR;
#endif
const int WARNING = ::WARNING;
const int INFO = ::INFO;
const int INFO = ::INFO;
// Sink class used for integration with mock and test functions. If sinks are
// added, all log output is also sent to each sink through the send function.
@@ -144,10 +144,13 @@ const int INFO = ::INFO;
class MYNTEYE_API LogSink {
public:
virtual ~LogSink() {}
virtual void send(
LogSeverity severity, const char *full_filename,
const char *base_filename, int line, const struct tm *tm_time,
const char *message, size_t message_len) = 0;
virtual void send(LogSeverity severity,
const char* full_filename,
const char* base_filename,
int line,
const struct tm* tm_time,
const char* message,
size_t message_len) = 0;
virtual void WaitTillSent() = 0;
};
@@ -157,7 +160,7 @@ MYNTEYE_API extern std::set<LogSink *> log_sinks_global;
// Added by chachi - a runtime global maximum log level. Defined in logging.cc
MYNTEYE_API extern int log_severity_global;
inline void InitGoogleLogging(char * /*argv*/) {
inline void InitGoogleLogging(char */*argv*/) {
// Do nothing; this is ignored.
}
@@ -183,7 +186,7 @@ inline void RemoveLogSink(LogSink *sink) {
class MYNTEYE_API MessageLogger {
public:
MessageLogger(const char *file, int line, const char *tag, int severity)
: file_(file), line_(line), tag_(tag), severity_(severity) {
: file_(file), line_(line), tag_(tag), severity_(severity) {
// Pre-pend the stream with the file and line number.
StripBasename(std::string(file), &filename_only_);
stream_ << SeverityLabel() << "/" << filename_only_ << ":" << line << " ";
@@ -205,8 +208,8 @@ class MYNTEYE_API MessageLogger {
// Bound the logging level.
const int kMaxVerboseLevel = 2;
int android_level_index =
std::min(std::max(FATAL, severity_), kMaxVerboseLevel) - FATAL;
int android_level_index = std::min(std::max(FATAL, severity_),
kMaxVerboseLevel) - FATAL;
int android_log_level = android_log_levels[android_level_index];
// Output the log string the Android log at the appropriate level.
@@ -214,7 +217,9 @@ class MYNTEYE_API MessageLogger {
// Indicate termination if needed.
if (severity_ == FATAL) {
__android_log_write(ANDROID_LOG_FATAL, tag_.c_str(), "terminating.\n");
__android_log_write(ANDROID_LOG_FATAL,
tag_.c_str(),
"terminating.\n");
}
#else
// If not building on Android, log all output to std::cerr.
@@ -232,24 +237,21 @@ class MYNTEYE_API MessageLogger {
}
// Return the stream associated with the logger object.
std::stringstream &stream() {
return stream_;
}
std::stringstream &stream() { return stream_; }
private:
void LogToSinks(int severity) {
time_t rawtime;
struct tm *timeinfo;
struct tm* timeinfo;
time(&rawtime);
time (&rawtime);
timeinfo = localtime(&rawtime);
std::set<google::LogSink *>::iterator iter;
std::set<google::LogSink*>::iterator iter;
// Send the log message to all sinks.
for (iter = google::log_sinks_global.begin();
iter != google::log_sinks_global.end(); ++iter) {
(*iter)->send(
severity, file_.c_str(), filename_only_.c_str(), line_, timeinfo,
stream_.str().c_str(), stream_.str().size());
(*iter)->send(severity, file_.c_str(), filename_only_.c_str(), line_,
timeinfo, stream_.str().c_str(), stream_.str().size());
}
}
@@ -305,19 +307,17 @@ class MYNTEYE_API MessageLogger {
// is not used" and "statement has no effect".
class MYNTEYE_API LoggerVoidify {
public:
LoggerVoidify() {}
LoggerVoidify() { }
// This has to be an operator with a precedence lower than << but
// higher than ?:
void operator&(const std::ostream & /*s*/) {}
void operator&(const std::ostream &/*s*/) { }
};
// Log only if condition is met. Otherwise evaluates to void.
#define LOG_IF(severity, condition) \
(static_cast<int>(severity) > google::log_severity_global || !(condition)) \
? (void)0 \
: LoggerVoidify() & \
MessageLogger((char *)__FILE__, __LINE__, "native", severity) \
.stream()
#define LOG_IF(severity, condition) \
(static_cast<int>(severity) > google::log_severity_global || !(condition)) ? \
(void) 0 : LoggerVoidify() & \
MessageLogger((char *)__FILE__, __LINE__, "native", severity).stream()
// Log only if condition is NOT met. Otherwise evaluates to void.
#define LOG_IF_FALSE(severity, condition) LOG_IF(severity, !(condition))
@@ -326,23 +326,23 @@ class MYNTEYE_API LoggerVoidify {
// google3 code is discouraged and the following shortcut exists for
// backward compatibility with existing code.
#ifdef MYNTEYE_MAX_LOG_LEVEL
#define LOG(n) LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL))
#define VLOG(n) LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL))
#define LG LOG_IF(INFO, (INFO <= MYNTEYE_MAX_LOG_LEVEL))
#define VLOG_IF(n, condition) \
LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL) && condition)
# define LOG(n) LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL))
# define VLOG(n) LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL))
# define LG LOG_IF(INFO, (INFO <= MYNTEYE_MAX_LOG_LEVEL))
# define VLOG_IF(n, condition) \
LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL) && condition)
#else
#define LOG(n) LOG_IF(n, true)
#define VLOG(n) LOG_IF(n, true)
#define LG LOG_IF(INFO, true)
#define VLOG_IF(n, condition) LOG_IF(n, condition)
# define LOG(n) LOG_IF(n, true)
# define VLOG(n) LOG_IF(n, true)
# define LG LOG_IF(INFO, true)
# define VLOG_IF(n, condition) LOG_IF(n, condition)
#endif
// Currently, VLOG is always on for levels below MYNTEYE_MAX_LOG_LEVEL.
#ifndef MYNTEYE_MAX_LOG_LEVEL
#define VLOG_IS_ON(x) (1)
# define VLOG_IS_ON(x) (1)
#else
#define VLOG_IS_ON(x) (x <= MYNTEYE_MAX_LOG_LEVEL)
# define VLOG_IS_ON(x) (x <= MYNTEYE_MAX_LOG_LEVEL)
#endif
#ifdef MYNTEYE_OS_WIN // INFO is 2, change VLOG(2) to VLOG(4)
@@ -351,34 +351,32 @@ class MYNTEYE_API LoggerVoidify {
#undef VLOG_IS_ON
#ifdef MYNTEYE_MAX_LOG_LEVEL
#define VLOG(n) LOG_IF(n + 2, (n + 2 <= MYNTEYE_MAX_LOG_LEVEL))
#define VLOG_IF(n, condition) \
LOG_IF(n + 2, (n + 2 <= MYNTEYE_MAX_LOG_LEVEL) && condition)
# define VLOG(n) LOG_IF(n+2, (n+2 <= MYNTEYE_MAX_LOG_LEVEL))
# define VLOG_IF(n, condition) \
LOG_IF(n+2, (n+2 <= MYNTEYE_MAX_LOG_LEVEL) && condition)
#else
#define VLOG(n) LOG_IF(n + 2, true)
#define VLOG_IF(n, condition) LOG_IF(n + 2, condition)
# define VLOG(n) LOG_IF(n+2, true)
# define VLOG_IF(n, condition) LOG_IF(n+2, condition)
#endif
#ifndef MYNTEYE_MAX_LOG_LEVEL
#define VLOG_IS_ON(x) (1 + 2)
# define VLOG_IS_ON(x) (1+2)
#else
#define VLOG_IS_ON(x) (x + 2 <= MYNTEYE_MAX_LOG_LEVEL)
# define VLOG_IS_ON(x) (x+2 <= MYNTEYE_MAX_LOG_LEVEL)
#endif
#endif
#ifndef NDEBUG
#define DLOG LOG
# define DLOG LOG
#else
#define DLOG(severity) \
true ? (void)0 \
: LoggerVoidify() & \
MessageLogger((char *)__FILE__, __LINE__, "native", severity) \
.stream()
# define DLOG(severity) true ? (void) 0 : LoggerVoidify() & \
MessageLogger((char *)__FILE__, __LINE__, "native", severity).stream()
#endif
// Log a message and terminate.
template <class T>
template<class T>
void LogMessageFatal(const char *file, int line, const T &message) {
MessageLogger(file, line, "native", FATAL).stream() << message;
}
@@ -386,27 +384,25 @@ void LogMessageFatal(const char *file, int line, const T &message) {
// ---------------------------- CHECK macros ---------------------------------
// Check for a given boolean condition.
#define CHECK(condition) \
LOG_IF_FALSE(FATAL, condition) << "Check failed: " #condition " "
#define CHECK(condition) LOG_IF_FALSE(FATAL, condition) \
<< "Check failed: " #condition " "
#ifndef NDEBUG
// Debug only version of CHECK
#define DCHECK(condition) \
LOG_IF_FALSE(FATAL, condition) << "Check failed: " #condition " "
# define DCHECK(condition) LOG_IF_FALSE(FATAL, condition) \
<< "Check failed: " #condition " "
#else
// Optimized version - generates no code.
#define DCHECK(condition) \
if (false) \
LOG_IF_FALSE(FATAL, condition) << "Check failed: " #condition " "
# define DCHECK(condition) if (false) LOG_IF_FALSE(FATAL, condition) \
<< "Check failed: " #condition " "
#endif // NDEBUG
// ------------------------- CHECK_OP macros ---------------------------------
// Generic binary operator check macro. This should not be directly invoked,
// instead use the binary comparison macros defined below.
#define CHECK_OP(val1, val2, op) \
LOG_IF_FALSE(FATAL, (val1 op val2)) \
<< "Check failed: " #val1 " " #op " " #val2 " "
#define CHECK_OP(val1, val2, op) LOG_IF_FALSE(FATAL, (val1 op val2)) \
<< "Check failed: " #val1 " " #op " " #val2 " "
// Check_op macro definitions
#define CHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==)
@@ -418,32 +414,20 @@ void LogMessageFatal(const char *file, int line, const T &message) {
#ifndef NDEBUG
// Debug only versions of CHECK_OP macros.
#define DCHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==)
#define DCHECK_NE(val1, val2) CHECK_OP(val1, val2, !=)
#define DCHECK_LE(val1, val2) CHECK_OP(val1, val2, <=)
#define DCHECK_LT(val1, val2) CHECK_OP(val1, val2, <)
#define DCHECK_GE(val1, val2) CHECK_OP(val1, val2, >=)
#define DCHECK_GT(val1, val2) CHECK_OP(val1, val2, >)
# define DCHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==)
# define DCHECK_NE(val1, val2) CHECK_OP(val1, val2, !=)
# define DCHECK_LE(val1, val2) CHECK_OP(val1, val2, <=)
# define DCHECK_LT(val1, val2) CHECK_OP(val1, val2, <)
# define DCHECK_GE(val1, val2) CHECK_OP(val1, val2, >=)
# define DCHECK_GT(val1, val2) CHECK_OP(val1, val2, >)
#else
// These versions generate no code in optimized mode.
#define DCHECK_EQ(val1, val2) \
if (false) \
CHECK_OP(val1, val2, ==)
#define DCHECK_NE(val1, val2) \
if (false) \
CHECK_OP(val1, val2, !=)
#define DCHECK_LE(val1, val2) \
if (false) \
CHECK_OP(val1, val2, <=)
#define DCHECK_LT(val1, val2) \
if (false) \
CHECK_OP(val1, val2, <)
#define DCHECK_GE(val1, val2) \
if (false) \
CHECK_OP(val1, val2, >=)
#define DCHECK_GT(val1, val2) \
if (false) \
CHECK_OP(val1, val2, >)
# define DCHECK_EQ(val1, val2) if (false) CHECK_OP(val1, val2, ==)
# define DCHECK_NE(val1, val2) if (false) CHECK_OP(val1, val2, !=)
# define DCHECK_LE(val1, val2) if (false) CHECK_OP(val1, val2, <=)
# define DCHECK_LT(val1, val2) if (false) CHECK_OP(val1, val2, <)
# define DCHECK_GE(val1, val2) if (false) CHECK_OP(val1, val2, >=)
# define DCHECK_GT(val1, val2) if (false) CHECK_OP(val1, val2, >)
#endif // NDEBUG
// ---------------------------CHECK_NOTNULL macros ---------------------------
@@ -451,7 +435,7 @@ void LogMessageFatal(const char *file, int line, const T &message) {
// Helpers for CHECK_NOTNULL(). Two are necessary to support both raw pointers
// and smart pointers.
template <typename T>
T &CheckNotNullCommon(const char *file, int line, const char *names, T &t) {
T& CheckNotNullCommon(const char *file, int line, const char *names, T& t) {
if (t == NULL) {
LogMessageFatal(file, line, std::string(names));
}
@@ -459,12 +443,12 @@ T &CheckNotNullCommon(const char *file, int line, const char *names, T &t) {
}
template <typename T>
T *CheckNotNull(const char *file, int line, const char *names, T *t) {
T* CheckNotNull(const char *file, int line, const char *names, T* t) {
return CheckNotNullCommon(file, line, names, t);
}
template <typename T>
T &CheckNotNull(const char *file, int line, const char *names, T &t) {
T& CheckNotNull(const char *file, int line, const char *names, T& t) {
return CheckNotNullCommon(file, line, names, t);
}
@@ -478,8 +462,7 @@ T &CheckNotNull(const char *file, int line, const char *names, T &t) {
CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val))
#else
// Optimized version - generates no code.
#define DCHECK_NOTNULL(val) \
if (false) \
#define DCHECK_NOTNULL(val) if (false)\
CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val))
#endif // NDEBUG

View File

@@ -21,9 +21,9 @@
# define MYNTEYE_API
#else
# ifdef MYNTEYE_EXPORTS
# define MYNTEYE_API DECL_EXPORT
# define MYNTEYE_API MYNTEYE_DECL_EXPORT
# else
# define MYNTEYE_API DECL_IMPORT
# define MYNTEYE_API MYNTEYE_DECL_IMPORT
# endif
#endif
@@ -45,7 +45,7 @@ MYNTEYE_API_VERSION_CHECK( \
((major<<16)|(minor<<8)|(patch)) // NOLINT
/* MYNTEYE_API_VERSION in "X.Y.Z" format */
#define MYNTEYE_API_VERSION_STR (STRINGIFY(MYNTEYE_API_VERSION_MAJOR.MYNTEYE_API_VERSION_MINOR.MYNTEYE_API_VERSION_PATCH)) // NOLINT
#define MYNTEYE_API_VERSION_STR (MYNTEYE_STRINGIFY(MYNTEYE_API_VERSION_MAJOR.MYNTEYE_API_VERSION_MINOR.MYNTEYE_API_VERSION_PATCH)) // NOLINT
#cmakedefine MYNTEYE_NAMESPACE @MYNTEYE_NAMESPACE@
#if defined(MYNTEYE_NAMESPACE)
@@ -58,7 +58,14 @@ MYNTEYE_API_VERSION_CHECK( \
# define MYNTEYE_USE_NAMESPACE
#endif
constexpr char MYNTEYE_SDK_ROOT_DIR[] = "@MYNTEYE_SDK_ROOT_DIR@";
constexpr char MYNTEYE_SDK_INSTALL_DIR[] = "@MYNTEYE_SDK_INSTALL_DIR@";
const char MYNTEYE_SDK_ROOT_DIR[] = "@MYNTEYE_SDK_ROOT_DIR@";
const char MYNTEYE_SDK_INSTALL_DIR[] = "@MYNTEYE_SDK_INSTALL_DIR@";
MYNTEYE_BEGIN_NAMESPACE
template <typename... T>
void UNUSED(T &&...) {}
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_MYNTEYE_H_

View File

@@ -11,7 +11,7 @@
// 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 MYNTEYE_TYPES_H_ // NOLINT
#ifndef MYNTEYE_TYPES_H_
#define MYNTEYE_TYPES_H_
#pragma once
@@ -198,6 +198,7 @@ enum class Option : std::uint8_t {
/** Erase chip */
ERASE_CHIP,
/**
<<<<<<< HEAD
* min exposure time, valid if auto-exposure
*
* range: [0,1000], default: 0
@@ -207,11 +208,17 @@ enum class Option : std::uint8_t {
* The range of accelerometer
*
* values: {6,12,24,48}, default: 6
=======
* The range of accelerometer
*
* values: {4,8,16,32}, default: 8
>>>>>>> origin/develop
*/
ACCELEROMETER_RANGE,
/**
* The range of gyroscope
*
<<<<<<< HEAD
* values: {250,500,1000,2000,4000}, default: 1000
*/
GYROSCOPE_RANGE,
@@ -227,6 +234,11 @@ enum class Option : std::uint8_t {
* values: {23,64}, default: 64
*/
GYROSCOPE_LOW_PASS_FILTER,
=======
* values: {500,1000,2000,4000}, default: 1000
*/
GYROSCOPE_RANGE,
>>>>>>> origin/develop
/** Last guard */
LAST
};
@@ -601,4 +613,4 @@ std::ostream &operator<<(std::ostream &os, const OptionInfo &info);
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_TYPES_H_ NOLINT
#endif // MYNTEYE_TYPES_H_

View File

@@ -0,0 +1,32 @@
// Copyright 2018 Slightech 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 MYNTEYE_UTIL_FILES_H_
#define MYNTEYE_UTIL_FILES_H_
#pragma once
#include <string>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
namespace files {
MYNTEYE_API bool mkdir(const std::string &path);
} // namespace files
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_UTIL_FILES_H_

View File

@@ -0,0 +1,62 @@
// Copyright 2018 Slightech 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 MYNTEYE_UTIL_STRINGS_H_
#define MYNTEYE_UTIL_STRINGS_H_
#pragma once
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
/** The strings error */
class MYNTEYE_API strings_error : public std::runtime_error {
public:
explicit strings_error(const std::string &what_arg) noexcept
: std::runtime_error(std::move(what_arg)) {}
explicit strings_error(const char *what_arg) noexcept
: std::runtime_error(std::move(what_arg)) {}
};
namespace strings {
MYNTEYE_API
int hex2int(const std::string &text);
MYNTEYE_API
bool starts_with(const std::string &text, const std::string &prefix);
MYNTEYE_API
bool ends_with(const std::string &text, const std::string &suffix);
MYNTEYE_API
std::vector<std::string> split(
const std::string &text, const std::string &delimiters);
MYNTEYE_API void ltrim(std::string &s); // NOLINT
MYNTEYE_API void rtrim(std::string &s); // NOLINT
MYNTEYE_API void trim(std::string &s); // NOLINT
MYNTEYE_API
std::string trim_copy(const std::string &text);
} // namespace strings
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_UTIL_STRINGS_H_

View File

@@ -0,0 +1,223 @@
// Copyright 2018 Slightech 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 MYNTEYE_UTIL_TIMES_H_
#define MYNTEYE_UTIL_TIMES_H_
#pragma once
#include <chrono>
#include <cmath>
#include <cstdint>
#include <ctime>
#include <iomanip>
#include <ratio>
#include <sstream>
#include <string>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
namespace times {
using system_clock = std::chrono::system_clock;
using nanoseconds = std::chrono::nanoseconds;
using microseconds = std::chrono::microseconds;
using milliseconds = std::chrono::milliseconds;
using seconds = std::chrono::seconds;
using minutes = std::chrono::minutes;
using hours = std::chrono::hours;
using days = std::chrono::duration<std::int64_t, std::ratio<86400>>;
// to
template <typename Duration>
inline Duration to_duration(const std::int64_t &t) {
return Duration{t};
}
template <typename Duration>
inline system_clock::time_point to_time_point(const Duration &d) {
return system_clock::time_point(d);
}
template <typename Duration>
inline system_clock::time_point to_time_point(const std::int64_t &t) {
return system_clock::time_point(Duration{t});
}
inline system_clock::time_point to_time_point(std::tm *tm) {
return system_clock::from_time_t(std::mktime(tm));
}
inline struct std::tm *to_local_tm(const system_clock::time_point &t) {
auto t_c = system_clock::to_time_t(t);
return std::localtime(&t_c);
}
inline struct std::tm *to_utc_tm(const system_clock::time_point &t) {
auto t_c = system_clock::to_time_t(t);
return std::gmtime(&t_c);
}
// cast
template <typename FromDuration, typename ToDuration>
inline ToDuration cast(const FromDuration &d) {
return std::chrono::duration_cast<ToDuration>(d);
}
template <typename Duration>
inline Duration cast(const system_clock::duration &d) {
return cast<system_clock::duration, Duration>(d);
}
template <typename FromDuration, typename ToDuration>
inline std::int64_t cast(const std::int64_t &t) {
return cast<FromDuration, ToDuration>(FromDuration{t}).count();
}
template <typename Duration>
inline system_clock::time_point cast(const system_clock::time_point &d) {
// C++17, floor
return std::chrono::time_point_cast<Duration>(d);
}
template <typename Duration>
inline system_clock::duration cast_mod(const system_clock::time_point &t) {
return t - cast<Duration>(t);
}
// count
template <typename FromDuration, typename ToDuration>
inline std::int64_t count(const FromDuration &d) {
return cast<FromDuration, ToDuration>(d).count();
}
template <typename Duration>
inline std::int64_t count(const system_clock::duration &d) {
return cast<Duration>(d).count();
}
// day
inline std::tm *day_beg(std::tm *tm) {
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
return tm;
}
inline std::tm *day_end(std::tm *tm) {
tm->tm_hour = 23;
tm->tm_min = 59;
tm->tm_sec = 59;
return tm;
}
inline system_clock::time_point day_beg(const system_clock::time_point &t) {
return cast<days>(t);
}
inline system_clock::time_point day_end(const system_clock::time_point &t) {
return day_beg(t) + days(1) - system_clock::duration(1);
}
inline system_clock::duration day_time(const system_clock::time_point &t) {
return cast_mod<days>(t);
}
// between
template <typename Duration>
inline std::int64_t between(
const system_clock::time_point &t1, const system_clock::time_point &t2) {
return count<Duration>(t2 - t1);
}
inline std::int64_t between_days(
const system_clock::time_point &t1, const system_clock::time_point &t2) {
return between<days>(day_beg(t1), day_beg(t2));
}
template <typename Duration>
inline std::int64_t between_days(
const std::int64_t &t1, const std::int64_t &t2) {
return between_days(to_time_point<Duration>(t1), to_time_point<Duration>(t2));
}
// epoch
inline system_clock::time_point epoch() {
return system_clock::time_point(system_clock::duration{0});
}
template <typename Duration>
inline std::int64_t since_epoch(const system_clock::time_point &t) {
return count<Duration>(t.time_since_epoch());
}
// now
inline system_clock::time_point now() {
return system_clock::now();
}
template <typename Duration>
inline std::int64_t now() {
return since_epoch<Duration>(now());
}
// string
inline std::string to_string(
const system_clock::time_point &t, const std::tm *tm,
const char *fmt = "%F %T", std::int32_t precision = 6) {
std::stringstream ss;
#if defined(MYNTEYE_OS_ANDROID) || defined(MYNTEYE_OS_LINUX)
char foo[20];
strftime(foo, sizeof(foo), fmt, tm);
ss << foo;
#else
ss << std::put_time(tm, fmt);
#endif
if (precision > 0) {
if (precision > 6)
precision = 6;
ss << '.' << std::setfill('0') << std::setw(precision)
<< static_cast<std::int32_t>(
count<microseconds>(cast_mod<seconds>(t)) /
std::pow(10, 6 - precision));
}
return ss.str();
}
inline std::string to_local_string(
const system_clock::time_point &t, const char *fmt = "%F %T",
const std::int32_t &precision = 6) {
return to_string(t, to_local_tm(t), fmt, precision);
}
inline std::string to_utc_string(
const system_clock::time_point &t, const char *fmt = "%F %T",
const std::int32_t &precision = 6) {
return to_string(t, to_utc_tm(t), fmt, precision);
}
} // namespace times
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_UTIL_TIMES_H_