Skip to content

Commit

Permalink
Replace pointers to reference wherever possible (#314)
Browse files Browse the repository at this point in the history
Replace `Device *PluginImplBase::parent` => `Device &PluginImplBase::parent`.
And replaces everywhere as required.
  • Loading branch information
Shakthi Prashanth M committed Mar 13, 2018
1 parent ca93a9c commit e7a5bcf
Show file tree
Hide file tree
Showing 56 changed files with 352 additions and 352 deletions.
2 changes: 1 addition & 1 deletion core/plugin_impl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace dronecore {

PluginImplBase::PluginImplBase(Device *device) :
PluginImplBase::PluginImplBase(Device &device) :
_parent(device) {}

} // namespace dronecore
4 changes: 2 additions & 2 deletions core/plugin_impl_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Device;
class PluginImplBase
{
public:
explicit PluginImplBase(Device *device);
explicit PluginImplBase(Device &device);
virtual ~PluginImplBase() = default;

/*
Expand Down Expand Up @@ -56,7 +56,7 @@ class PluginImplBase
const PluginImplBase &operator=(const PluginImplBase &) = delete;

protected:
Device *_parent;
Device &_parent;
};

} // namespace dronecore
6 changes: 3 additions & 3 deletions example/fly_mission/fly_mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ int main(int /*argc*/, char ** /*argv*/)
// If there were multiple, we could specify it with:
// dc.device(uint64_t uuid);
Device &device = dc.device();
std::shared_ptr<Action> action = std::make_shared<Action>(&device);
std::shared_ptr<Mission> mission = std::make_shared<Mission>(&device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(&device);
std::shared_ptr<Action> action = std::make_shared<Action>(device);
std::shared_ptr<Mission> mission = std::make_shared<Mission>(device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(device);

while (!telemetry->health_all_ok()) {
std::cout << "Waiting for device to be ready" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions example/fly_qgc_mission/fly_qgc_mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ int main(int argc, char **argv)
// If there were multiple, we could specify it with:
// dc.device(uint64_t uuid);
Device &device = dc.device();
std::shared_ptr<Action> action = std::make_shared<Action>(&device);
std::shared_ptr<Mission> mission = std::make_shared<Mission>(&device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(&device);
std::shared_ptr<Action> action = std::make_shared<Action>(device);
std::shared_ptr<Mission> mission = std::make_shared<Mission>(device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(device);

while (!telemetry->health_all_ok()) {
std::cout << "Waiting for device to be ready" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions example/follow_me/follow_me.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ int main(int, char **)

// Device got discovered.
Device &device = dc.device();
std::shared_ptr<Action> action = std::make_shared<Action>(&device);
std::shared_ptr<FollowMe> follow_me = std::make_shared<FollowMe>(&device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(&device);
std::shared_ptr<Action> action = std::make_shared<Action>(device);
std::shared_ptr<FollowMe> follow_me = std::make_shared<FollowMe>(device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(device);

while (!telemetry->health_all_ok()) {
std::cout << "Waiting for device to be ready" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions example/offboard_velocity/offboard_velocity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ int main(int, char **)

// Device got discovered.
Device &device = dc.device();
std::shared_ptr<Action> action = std::make_shared<Action>(&device);
std::shared_ptr<Offboard> offboard = std::make_shared<Offboard>(&device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(&device);
std::shared_ptr<Action> action = std::make_shared<Action>(device);
std::shared_ptr<Offboard> offboard = std::make_shared<Offboard>(device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(device);

while (!telemetry->health_all_ok()) {
std::cout << "Waiting for device to be ready" << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions example/takeoff_land/takeoff_and_land.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ int main(int argc, char **argv)
// dc.device(uint64_t uuid);
Device &device = dc.device();

auto telemetry = std::make_shared<Telemetry>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto action = std::make_shared<Action>(device);

// We want to listen to the altitude of the drone at 1 Hz.
const Telemetry::Result set_rate_result = telemetry->set_rate_position(1.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int /*argc*/, char ** /*argv*/)
// If there were multiple, we could specify it with:
// dc.device(uint64_t uuid);
Device &device = dc.device();
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(&device);
std::shared_ptr<Telemetry> telemetry = std::make_shared<Telemetry>(device);

// We want to listen to the altitude of the drone at 1 Hz.
const Telemetry::Result set_rate_result = telemetry->set_rate_position(1.0);
Expand All @@ -74,7 +74,7 @@ int main(int /*argc*/, char ** /*argv*/)
return 1;
}

std::shared_ptr<Action> action = std::make_shared<Action>(&device);
std::shared_ptr<Action> action = std::make_shared<Action>(device);

// Arm vehicle
std::cout << "Arming..." << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/async_hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ TEST_F(SitlTest, ActionAsyncHover)
// TODO: this test is pretty dumb, should be improved with more checks.
Device &device = dc.device();

auto telemetry = std::make_shared<Telemetry>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
telemetry->health_all_ok_async(std::bind(&receive_health_all_ok, _1));
telemetry->in_air_async(std::bind(&receive_in_air, _1));

auto action = std::make_shared<Action>(&device);
auto action = std::make_shared<Action>(device);

while (!_all_ok) {
std::cout << "Waiting to be ready..." << std::endl;
Expand Down
12 changes: 6 additions & 6 deletions integration_tests/follow_me.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ TEST_F(SitlTest, FollowMeOneLocation)
// Wait for device to connect via heartbeat.
sleep_for(seconds(2));
Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto follow_me = std::make_shared<FollowMe>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto follow_me = std::make_shared<FollowMe>(device);
auto action = std::make_shared<Action>(device);

while (!telemetry->health_all_ok()) {
std::cout << "waiting for device to be ready" << std::endl;
Expand Down Expand Up @@ -91,9 +91,9 @@ TEST_F(SitlTest, FollowMeMultiLocationWithConfig)
// Wait for device to connect via heartbeat.
sleep_for(seconds(2));
Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto follow_me = std::make_shared<FollowMe>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto follow_me = std::make_shared<FollowMe>(device);
auto action = std::make_shared<Action>(device);

while (!telemetry->health_all_ok()) {
std::cout << "Waiting for device to be ready" << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions integration_tests/gimbal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ TEST_F(SitlTest, GimbalMove)
std::this_thread::sleep_for(std::chrono::seconds(2));

Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto gimbal = std::make_shared<Gimbal>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto gimbal = std::make_shared<Gimbal>(device);

telemetry->set_rate_camera_attitude(10.0);

Expand All @@ -55,9 +55,9 @@ TEST_F(SitlTest, GimbalTakeoffAndMove)
std::this_thread::sleep_for(std::chrono::seconds(2));

Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto gimbal = std::make_shared<Gimbal>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto gimbal = std::make_shared<Gimbal>(device);
auto action = std::make_shared<Action>(device);

while (!telemetry->health_all_ok()) {
LogInfo() << "waiting for device to be ready";
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST_F(SitlTest, Info)


Device &device = dc.device();
auto info = std::make_shared<Info>(&device);
auto info = std::make_shared<Info>(device);

for (unsigned i = 0; i < 3; ++i) {
Info::Version version = info->get_version();
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TEST_F(SitlTest, Logging)
std::this_thread::sleep_for(std::chrono::seconds(2));

Device &device = dc.device();
auto logging = std::make_shared<Logging>(&device);
auto logging = std::make_shared<Logging>(device);
Logging::Result log_ret = logging->start_logging();

if (log_ret == Logging::Result::COMMAND_DENIED) {
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ TEST_F(SitlTest, MissionAddWaypointsAndFly)


Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto mission = std::make_shared<Mission>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto mission = std::make_shared<Mission>(device);
auto action = std::make_shared<Action>(device);

while (!telemetry->health_all_ok()) {
LogInfo() << "Waiting for device to be ready";
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/mission_change_speed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ TEST_F(SitlTest, MissionChangeSpeed)
std::this_thread::sleep_for(std::chrono::seconds(2));

Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto mission = std::make_shared<Mission>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto mission = std::make_shared<Mission>(device);
auto action = std::make_shared<Action>(device);

while (!telemetry->health_all_ok()) {
std::cout << "waiting for device to be ready" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/mission_survey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ TEST_F(SitlTest, MissionSurvey)
std::this_thread::sleep_for(std::chrono::seconds(2));

Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto mission = std::make_shared<Mission>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto mission = std::make_shared<Mission>(device);
auto action = std::make_shared<Action>(device);

while (!telemetry->health_all_ok()) {
std::cout << "waiting for device to be ready" << std::endl;
Expand Down
14 changes: 7 additions & 7 deletions integration_tests/offboard_velocity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ TEST_F(SitlTest, OffboardVelocityNED)
std::this_thread::sleep_for(std::chrono::seconds(2));

Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto action = std::make_shared<Action>(&device);
auto offboard = std::make_shared<Offboard>(&device);
auto mission = std::make_shared<Mission>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto action = std::make_shared<Action>(device);
auto offboard = std::make_shared<Offboard>(device);
auto mission = std::make_shared<Mission>(device);

while (!telemetry->health_all_ok()) {
std::cout << "waiting for device to be ready" << std::endl;
Expand Down Expand Up @@ -118,9 +118,9 @@ TEST_F(SitlTest, OffboardVelocityBody)
std::this_thread::sleep_for(std::chrono::seconds(2));
Device &device = dc.device();

auto telemetry = std::make_shared<Telemetry>(&device);
auto action = std::make_shared<Action>(&device);
auto offboard = std::make_shared<Offboard>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto action = std::make_shared<Action>(device);
auto offboard = std::make_shared<Offboard>(device);

while (!telemetry->health_all_ok()) {
std::cout << "waiting for device to be ready" << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/simple_hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void takeoff_and_hover_at_altitude(float altitude_m)
ASSERT_TRUE(dc.is_connected());

Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto action = std::make_shared<Action>(device);

int iteration = 0;
while (!telemetry->health_all_ok()) {
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/takeoff_and_kill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ TEST_F(SitlTest, ActionTakeoffAndKill)
ASSERT_TRUE(_discovered_device);

Device &device = dc.device();
auto telemetry = std::make_shared<Telemetry>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto action = std::make_shared<Action>(device);

while (!telemetry->health_all_ok()) {
std::cout << "waiting for device to be ready" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/telemetry_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TEST_F(SitlTest, TelemetryAsync)

Device &device = dc.device(uuid);

auto telemetry = std::make_shared<Telemetry>(&device);
auto telemetry = std::make_shared<Telemetry>(device);

telemetry->set_rate_position_async(10.0, std::bind(&receive_result, _1));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/telemetry_health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_F(SitlTest, TelemetryHealth)

Device &device = dc.device();

auto telemetry = std::make_shared<Telemetry>(&device);
auto telemetry = std::make_shared<Telemetry>(device);

telemetry->health_async(std::bind(&print_health, std::placeholders::_1));
std::this_thread::sleep_for(std::chrono::seconds(3));
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/telemetry_modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ TEST_F(SitlTest, TelemetryFlightModes)

Device &device = dc.device();

auto telemetry = std::make_shared<Telemetry>(&device);
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(device);
auto action = std::make_shared<Action>(device);

telemetry->flight_mode_async(
std::bind(&print_mode, std::placeholders::_1));
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/telemetry_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TEST_F(SitlTest, TelemetrySimple)
std::this_thread::sleep_for(std::chrono::seconds(2));
Device &device = dc.device();

auto telemetry = std::make_shared<Telemetry>(&device);
auto telemetry = std::make_shared<Telemetry>(device);

while (!telemetry->health_all_ok()) {
std::cout << "waiting for device to be ready" << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/transition_multicopter_fixedwing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void takeoff_and_transition_to_fixedwing()
ASSERT_TRUE(dc.is_connected());

Device &device = dc.device();
auto action = std::make_shared<Action>(&device);
auto telemetry = std::make_shared<Telemetry>(&device);
auto action = std::make_shared<Action>(device);
auto telemetry = std::make_shared<Telemetry>(device);

// We need to takeoff first, otherwise we can't actually transition
LogInfo() << "Taking off";
Expand Down
2 changes: 1 addition & 1 deletion plugins/action/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace dronecore {

Action::Action(Device *device) :
Action::Action(Device &device) :
PluginBase()
{
_impl = new ActionImpl(device);
Expand Down
4 changes: 2 additions & 2 deletions plugins/action/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class Action : public PluginBase
* The plugin is typically created as shown below:
*
* ```cpp
* auto action = std::make_shared<Action>(&device);
* auto action = std::make_shared<Action>(device);
* ```
*
* @param device The specific device associated with this plugin.
*/
explicit Action(Device *device);
explicit Action(Device &device);

/**
* @brief Destructor (internal use only).
Expand Down
Loading

0 comments on commit e7a5bcf

Please sign in to comment.