Skip to content

Commit

Permalink
More fixes following code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
aangerma committed Feb 4, 2020
1 parent 1d659a5 commit a05bb6e
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 38 deletions.
28 changes: 14 additions & 14 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4965,9 +4965,9 @@ namespace rs2
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_grey);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5));
ImGui::PushFont(window.get_font());
auto serializable = dev.as<serializable_device>();
auto serializable_device = dev.as<serializable>();

const auto load_json = [&, serializable](const std::string f) {
const auto load_json = [&, serializable_device](const std::string f) {
std::ifstream file(f);
if (!file.good())
{
Expand All @@ -4978,9 +4978,9 @@ namespace rs2
}
std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());

if (serializable)
if (serializable_device)
{
serializable.load_json(str);
serializable_device.load_json(str);
for (auto&& sub : subdevices)
{
//If json was loaded correctly, we want the presets combo box to show the name of the configuration file
Expand All @@ -5003,14 +5003,14 @@ namespace rs2
viewer.not_model.add_log(to_string() << "Loaded settings from \"" << f << "\"...");
};

const auto save_to_json = [&, serializable](std::string full_filename)
const auto save_to_json = [&, serializable_device](std::string full_filename)
{
if (!ends_with(to_lower(full_filename), ".json")) full_filename += ".json";
std::ofstream outfile(full_filename);
json saved_configuraion;
if (serializable)
if (serializable_device)
{
saved_configuraion = json::parse(serializable.serialize_json());
saved_configuraion = json::parse(serializable_device.serialize_json());
}
save_viewer_configurations(outfile, saved_configuraion);
outfile << saved_configuraion.dump(4);
Expand Down Expand Up @@ -5144,7 +5144,7 @@ namespace rs2
const ImVec2 icons_size{ 20, 20 };
//TODO: Change this once we have support for loading jsons with more data than only advanced controls
bool is_streaming = std::any_of(subdevices.begin(), subdevices.end(), [](const std::shared_ptr<subdevice_model>& sm) { return sm->streaming; });
const int buttons_flags = serializable ? 0 : ImGuiButtonFlags_Disabled;
const int buttons_flags = serializable_device ? 0 : ImGuiButtonFlags_Disabled;
static bool require_advanced_mode_enable_prompt = false;
auto advanced_dev = dev.as<advanced_mode>();
auto is_advanced_device = false;
Expand All @@ -5166,7 +5166,7 @@ namespace rs2

if (ImGui::ButtonEx(upload_button_name.c_str(), icons_size, (is_streaming && !load_json_if_streaming) ? ImGuiButtonFlags_Disabled : buttons_flags))
{
if (serializable && (!is_advanced_device || is_advanced_mode_enabled))
if (serializable_device && (!is_advanced_device || is_advanced_mode_enabled))
{
json_loading([&]()
{
Expand Down Expand Up @@ -5198,7 +5198,7 @@ namespace rs2
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 1); //Align the two icons to buttom
if (ImGui::ButtonEx(save_button_name.c_str(), icons_size, buttons_flags))
{
if (serializable && (!is_advanced_device || is_advanced_mode_enabled))
if (serializable_device && (!is_advanced_device || is_advanced_mode_enabled))
{
auto ret = file_dialog_open(save_file, "JavaScript Object Notation (JSON)\0*.json\0", NULL, NULL);
if (ret)
Expand Down Expand Up @@ -5421,8 +5421,8 @@ namespace rs2
////////////////////////////////////////
// draw advanced mode panel
////////////////////////////////////////
auto serializable = dev.is<serializable_device>();
if (serializable)
auto serialize = dev.is<serializable>();
if (serialize)
{
pos = ImGui::GetCursorPos();
const float vertical_space_before_advanced_mode_control = 10.0f;
Expand Down Expand Up @@ -5684,7 +5684,7 @@ namespace rs2
if (show_stream_selection)
sub->draw_stream_selection();

static const std::vector<rs2_option> drawing_order = serializable ?
static const std::vector<rs2_option> drawing_order = serialize ?
std::vector<rs2_option>{ RS2_OPTION_EMITTER_ENABLED, RS2_OPTION_ENABLE_AUTO_EXPOSURE }
: std::vector<rs2_option>{ RS2_OPTION_VISUAL_PRESET, RS2_OPTION_EMITTER_ENABLED, RS2_OPTION_ENABLE_AUTO_EXPOSURE };

Expand All @@ -5708,7 +5708,7 @@ namespace rs2
if (skip_option(opt)) continue;
if (std::find(drawing_order.begin(), drawing_order.end(), opt) == drawing_order.end())
{
if (serializable && opt == RS2_OPTION_VISUAL_PRESET)
if (serialize && opt == RS2_OPTION_VISUAL_PRESET)
continue;
if (sub->draw_option(opt, dev.is<playback>() || update_read_only_options, error_message, viewer.not_model))
{
Expand Down
2 changes: 1 addition & 1 deletion include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ extern "C" {
RS2_L500_VISUAL_PRESET_MAX_RANGE,
RS2_L500_VISUAL_PRESET_SHORT_RANGE,
RS2_L500_VISUAL_PRESET_COUNT
}rs2_l500_visual_preset;
} rs2_l500_visual_preset;
const char* rs2_l500_visual_preset_to_string(rs2_l500_visual_preset preset);

/** \brief For setting the camera_mode option */
Expand Down
2 changes: 1 addition & 1 deletion include/librealsense2/h/rs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ typedef enum rs2_extension
RS2_EXTENSION_MOTION_SENSOR,
RS2_EXTENSION_FISHEYE_SENSOR,
RS2_EXTENSION_DEPTH_HUFFMAN_DECODER,
RS2_EXTENSION_SERIALIZABLE_DEVICE,
RS2_EXTENSION_SERIALIZABLE,
RS2_EXTENSION_COUNT
} rs2_extension;
const char* rs2_extension_type_to_string(rs2_extension type);
Expand Down
6 changes: 3 additions & 3 deletions include/librealsense2/hpp/rs_serializable_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace rs2
{
class serializable_device : public rs2::device
class serializable : public rs2::device
{
public:
serializable_device(rs2::device d)
serializable(rs2::device d)
: rs2::device(d.get())
{
rs2_error* e = nullptr;
if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_SERIALIZABLE_DEVICE, &e) == 0 && !e)
if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_SERIALIZABLE, &e) == 0 && !e)
{
_dev = nullptr;
}
Expand Down
6 changes: 2 additions & 4 deletions include/librealsense2/rs_advanced_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@

namespace rs400
{
using namespace rs2;

class advanced_mode : public serializable_device
class advanced_mode : public rs2::serializable
{
public:
advanced_mode(rs2::device d)
: serializable_device(d)
: rs2::serializable(d)
{
rs2_error* e = nullptr;
if(_dev && rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_ADVANCED_MODE, &e) == 0 && !e)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/command_transfer.h"
"${CMAKE_CURRENT_LIST_DIR}/frame-validator.h"
"${CMAKE_CURRENT_LIST_DIR}/auto-calibrated-device.h"
"${CMAKE_CURRENT_LIST_DIR}/serializable.h"
"${CMAKE_CURRENT_LIST_DIR}/serializable-interface.h"
)
2 changes: 1 addition & 1 deletion src/core/advanced_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define RS400_ADVANCED_MODE_HPP
#include "ds5/advanced_mode/presets.h"
#include "../../include/librealsense2/h/rs_advanced_mode_command.h"
#include "serializable.h"
#include "serializable-interface.h"

#undef RS400_ADVANCED_MODE_HPP

Expand Down
2 changes: 1 addition & 1 deletion src/l500/l500-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace librealsense
{
auto& depth_sensor = get_depth_sensor();

auto signaled_opt = std::make_shared <cascade_option<T>>(opt, std::forward<Args>(args)...);
auto signaled_opt = std::make_shared <cascade_option<T>>(std::forward<Args>(args)...);
signaled_opt->add_observer([opt, this](float val) {on_set_option(opt, val);});
depth_sensor.register_option(opt, std::dynamic_pointer_cast<option>(signaled_opt));

Expand Down
2 changes: 1 addition & 1 deletion src/l500/l500-serializable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//// License: Apache 2.0. See LICENSE file in root directory.
//// Copyright(c) 2018 Intel Corporation. All Rights Reserved.
//// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#include "l500-serializable.h"
#include "../../../third-party/json.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/l500/l500-serializable.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2018 Intel Corporation. All Rights Reserved.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#pragma once

#include "serializable.h"
#include "serializable-interface.h"
#include "hw-monitor.h"
#include "sensor.h"

Expand Down
7 changes: 2 additions & 5 deletions src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ namespace librealsense
{
public:
template <class... Args>
cascade_option(rs2_option opt, Args&&... args) :
T(std::forward<Args>(args)...), _opt(opt) {}
cascade_option(Args&&... args) :
T(std::forward<Args>(args)...){}

void set(float value) override
{
Expand All @@ -139,9 +139,6 @@ namespace librealsense
{
T::set(value);
}
private:
std::function<void(rs2_option, float)> _callback;
rs2_option _opt;
};

template<class T>
Expand Down
2 changes: 1 addition & 1 deletion src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ int rs2_is_device_extendable_to(const rs2_device* dev, rs2_extension extension,
case RS2_EXTENSION_UPDATE_DEVICE : return VALIDATE_INTERFACE_NO_THROW(dev->device, librealsense::update_device_interface) != nullptr;
case RS2_EXTENSION_GLOBAL_TIMER : return VALIDATE_INTERFACE_NO_THROW(dev->device, librealsense::global_time_interface) != nullptr;
case RS2_EXTENSION_AUTO_CALIBRATED_DEVICE: return VALIDATE_INTERFACE_NO_THROW(dev->device, librealsense::auto_calibrated_interface) != nullptr;
case RS2_EXTENSION_SERIALIZABLE_DEVICE : return VALIDATE_INTERFACE_NO_THROW(dev->device, librealsense::serializable_interface) != nullptr;
case RS2_EXTENSION_SERIALIZABLE : return VALIDATE_INTERFACE_NO_THROW(dev->device, librealsense::serializable_interface) != nullptr;

default:
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/serializable.h → src/serializable-interface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#pragma once
#include "types.h"
Expand All @@ -13,5 +13,5 @@ namespace librealsense
virtual std::vector<uint8_t> serialize_json() const = 0;
virtual void load_json(const std::string& json_content) = 0;
};
MAP_EXTENSION(RS2_EXTENSION_SERIALIZABLE_DEVICE, serializable_interface);
MAP_EXTENSION(RS2_EXTENSION_SERIALIZABLE, serializable_interface);
}
2 changes: 1 addition & 1 deletion src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ namespace librealsense
CASE(MOTION_SENSOR)
CASE(FISHEYE_SENSOR)
CASE(DEPTH_HUFFMAN_DECODER)
CASE(SERIALIZABLE_DEVICE)
CASE(SERIALIZABLE)
default: assert(!is_valid(value)); return UNKNOWN_VALUE;
}
#undef CASE
Expand Down

0 comments on commit a05bb6e

Please sign in to comment.