Skip to content

Commit

Permalink
Merge branch 'develop' into pr-timesync
Browse files Browse the repository at this point in the history
  • Loading branch information
julianoes committed Nov 13, 2019
2 parents 6995b2d + 480a93c commit aa31e7c
Show file tree
Hide file tree
Showing 7 changed files with 335 additions and 343 deletions.
4 changes: 0 additions & 4 deletions src/plugins/action/action_impl.cpp
Expand Up @@ -44,10 +44,6 @@ void ActionImpl::enable()
1.0,
nullptr,
MAVLinkCommands::DEFAULT_COMPONENT_ID_AUTOPILOT);

_parent->get_param_float_async(TAKEOFF_ALT_PARAM, nullptr, this);
_parent->get_param_float_async(MAX_SPEED_PARAM, nullptr, this);
_parent->get_param_float_async(TAKEOFF_ALT_PARAM, nullptr, this);
}

void ActionImpl::disable() {}
Expand Down
86 changes: 63 additions & 23 deletions src/plugins/camera/camera_impl.cpp
Expand Up @@ -391,11 +391,9 @@ void CameraImpl::start_photo_interval_async(
float interval_s, const Camera::result_callback_t& callback)
{
if (!interval_valid(interval_s)) {
if (callback) {
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::WRONG_ARGUMENT); });
}
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::WRONG_ARGUMENT); });
return;
}

Expand Down Expand Up @@ -1096,7 +1094,9 @@ void CameraImpl::receive_set_mode_command_result(
Camera::Result camera_result = camera_result_from_command_result(command_result);

if (callback) {
callback(camera_result, mode);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback, camera_result, mode]() { temp_callback(camera_result, mode); });
}

if (command_result == MAVLinkCommands::Result::SUCCESS && _camera_definition) {
Expand Down Expand Up @@ -1237,7 +1237,9 @@ void CameraImpl::set_option_async(
if (!_camera_definition) {
LogWarn() << "Error: no camera defnition available yet.";
if (callback) {
callback(Camera::Result::ERROR);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}
Expand All @@ -1251,15 +1253,19 @@ void CameraImpl::set_option_async(
if (!_camera_definition->get_all_options(setting_id, all_values)) {
if (callback) {
LogErr() << "Could not get all options to get type for range param.";
callback(Camera::Result::ERROR);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}

if (all_values.size() == 0) {
if (callback) {
LogErr() << "Could not get any options to get type for range param.";
callback(Camera::Result::ERROR);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}
Expand All @@ -1269,7 +1275,9 @@ void CameraImpl::set_option_async(
if (!value.set_as_same_type(option.option_id)) {
if (callback) {
LogErr() << "Could not set option value to given type.";
callback(Camera::Result::ERROR);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}
Expand All @@ -1278,7 +1286,9 @@ void CameraImpl::set_option_async(
if (!_camera_definition->get_option_value(setting_id, option.option_id, value)) {
if (callback) {
LogErr() << "Could not get option value.";
callback(Camera::Result::ERROR);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}
Expand All @@ -1294,7 +1304,9 @@ void CameraImpl::set_option_async(
if (!allowed) {
LogErr() << "Setting " << setting_id << "(" << option.option_id << ") not allowed";
if (callback) {
callback(Camera::Result::ERROR);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}
Expand All @@ -1305,17 +1317,34 @@ void CameraImpl::set_option_async(
value,
[this, callback, setting_id, value](MAVLinkParameters::Result result) {
if (result == MAVLinkParameters::Result::SUCCESS) {
if (this->_camera_definition) {
_camera_definition->set_setting(setting_id, value);
refresh_params();
if (!this->_camera_definition) {
if (callback) {
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}
if (callback) {
callback(Camera::Result::SUCCESS);

if (!_camera_definition->set_setting(setting_id, value)) {
if (callback) {
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::ERROR); });
}
return;
}
} else {

if (callback) {
callback(Camera::Result::ERROR);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback]() { temp_callback(Camera::Result::SUCCESS); });
}

// FIXME: We are already holding the lock when this lambda is run and need to
// schedule the refresh_params() for later.
// We (ab)use the thread pool for the user callbacks for this.
_parent->call_user_callback([this]() { refresh_params(); });
}
},
this,
Expand Down Expand Up @@ -1351,7 +1380,10 @@ void CameraImpl::get_option_async(
LogWarn() << "Error: no camera defnition available yet.";
if (callback) {
Camera::Option empty_option{};
callback(Camera::Result::ERROR, empty_option);
const auto temp_callback = callback;
_parent->call_user_callback([temp_callback, empty_option]() {
temp_callback(Camera::Result::ERROR, empty_option);
});
}
return;
}
Expand All @@ -1365,14 +1397,19 @@ void CameraImpl::get_option_async(
if (!is_setting_range(setting_id)) {
get_option_str(setting_id, new_option.option_id, new_option.option_description);
}
callback(Camera::Result::SUCCESS, new_option);
const auto temp_callback = callback;
_parent->call_user_callback([temp_callback, new_option]() {
temp_callback(Camera::Result::SUCCESS, new_option);
});
}
} else {
// If this still happens, we request the param, but also complain.
LogWarn() << "Setting '" << setting_id << "' not found.";
if (callback) {
Camera::Option no_option{};
callback(Camera::Result::ERROR, no_option);
const auto temp_callback = callback;
_parent->call_user_callback(
[temp_callback, no_option]() { temp_callback(Camera::Result::ERROR, no_option); });
}
}
}
Expand Down Expand Up @@ -1519,7 +1556,10 @@ void CameraImpl::refresh_params()
if (!this->_camera_definition) {
return;
}
this->_camera_definition->set_setting(param_name, value);

if (!this->_camera_definition->set_setting(param_name, value)) {
return;
}

if (is_last) {
notify_current_settings();
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/gimbal/include/plugins/gimbal/gimbal.h
Expand Up @@ -39,10 +39,10 @@ class Gimbal : public PluginBase {
* @brief Possible results returned for gimbal commands.
*/
enum class Result {
SUCCESS = 0, /**< @brief Success. The gimbal command was accepted. */
UNKNOWN = 0, /**< @brief Unspecified error. */
SUCCESS, /**< @brief Success. The gimbal command was accepted. */
ERROR, /**< @brief Error. An error occured sending the command. */
TIMEOUT, /**< @brief Timeout. A timeout occured sending the command. */
UNKNOWN /**< @brief Unspecified error. */
TIMEOUT /**< @brief Timeout. A timeout occured sending the command. */
};

/**
Expand Down
6 changes: 2 additions & 4 deletions third_party/zlib/CMakeLists.txt
Expand Up @@ -18,9 +18,7 @@ ExternalProject_add(
zlib
GIT_REPOSITORY https://github.com/madler/zlib
GIT_TAG v1.2.11
# Patch taken from: https://github.com/madler/zlib/pull/337/files
# Thanks to @Mizux
PATCH_COMMAND git apply ${PROJECT_SOURCE_DIR}/pr-337-cmake-update.patch
PREFIX zlib
PATCH_COMMAND git apply ${PROJECT_SOURCE_DIR}/build_shared_libs.patch
CMAKE_ARGS "${CMAKE_ARGS}"
)

89 changes: 89 additions & 0 deletions third_party/zlib/build_shared_libs.patch
@@ -0,0 +1,89 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0fe939d..1873459 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -123,7 +123,7 @@ set(ZLIB_SRCS
zutil.c
)

-if(NOT MINGW)
+if(BUILD_SHARED_LIBS AND NOT MINGW)
set(ZLIB_DLL_SRCS
win32/zlib1.rc # If present will override custom build rule below.
)
@@ -167,7 +167,7 @@ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
"\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})

-if(MINGW)
+if(BUILD_SHARED_LIBS AND MINGW)
# This gets us DLL resource information when compiling on MinGW.
if(NOT CMAKE_RC_COMPILER)
set(CMAKE_RC_COMPILER windres.exe)
@@ -181,37 +181,42 @@ if(MINGW)
-o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
-i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
-endif(MINGW)
-
-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
-set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
-set_target_properties(zlib PROPERTIES SOVERSION 1)
-
-if(NOT CYGWIN)
- # This property causes shared libraries on Linux to have the full version
- # encoded into their final filename. We disable this on Cygwin because
- # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
- # seems to be the default.
- #
- # This has no effect with MSVC, on that platform the version info for
- # the DLL comes from the resource file win32/zlib1.rc
- set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
endif()

+add_library(zlib ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
+
if(UNIX)
# On unix-like platforms the library is almost always called libz
- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
- if(NOT APPLE)
- set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
- endif()
-elseif(BUILD_SHARED_LIBS AND WIN32)
- # Creates zlib1.dll when building shared library version
- set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
+ set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
+endif()
+
+if(BUILD_SHARED_LIBS)
+ set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
+ set_target_properties(zlib PROPERTIES SOVERSION 1)
+
+ if(NOT CYGWIN)
+ # This property causes shared libraries on Linux to have the full version
+ # encoded into their final filename. We disable this on Cygwin because
+ # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
+ # seems to be the default.
+ #
+ # This has no effect with MSVC, on that platform the version info for
+ # the DLL comes from the resource file win32/zlib1.rc
+ set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
+ endif()
+
+ if(UNIX AND NOT APPLE)
+ set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
+ endif()
+
+ if(WIN32)
+ # Creates zlib1.dll when building shared library version
+ set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
+ endif()
endif()

if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
- install(TARGETS zlib zlibstatic
+ install(TARGETS zlib
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )

0 comments on commit aa31e7c

Please sign in to comment.