Skip to content

Commit

Permalink
Replace deprecated File.exists with File.exist and tweak tutorial (#529)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero authored Sep 2, 2024
1 parent ae8a2fa commit 2ddd4c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 93 deletions.
4 changes: 4 additions & 0 deletions example/playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/// Launch the gz-transport subscriber example if the log was created
/// by recording the publisher example.

//! [complete]
#include <cstdint>
#include <iostream>
#include <regex>
Expand Down Expand Up @@ -62,4 +63,7 @@ int main(int argc, char *argv[])
// Wait until the player stops on its own
std::cout << "Playing all messages in the log file\n";
handle->WaitUntilFinished();

return 0;
}
//! [complete]
4 changes: 4 additions & 0 deletions example/record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/// Launch the gz-transport publisher example so this example has
/// something to record.

//! [complete]
#include <cstdint>
#include <iostream>
#include <regex>
Expand Down Expand Up @@ -65,4 +66,7 @@ int main(int argc, char *argv[])
recorder.Stop();

std::cout << "\nRecording finished!" << std::endl;

return 0;
}
//! [complete]
2 changes: 1 addition & 1 deletion log/src/cmd/cmdlog.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Cmd

case options['subcommand']
when 'record'
if options['force'] and File.exists?(options['file'])
if options['force'] and File.exist?(options['file'])
begin
File.delete(options['file'])
rescue Exception => e
Expand Down
94 changes: 2 additions & 92 deletions tutorials/10_logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,7 @@ cd ~/gz_transport_tutorial
Download the [record.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport14/example/record.cc)
file within the `gz_transport_tutorial` folder and open it with your favorite editor:

```{.cpp}
#include <cstdint>
#include <iostream>
#include <regex>
#include <gz/transport/Node.hh>
#include <gz/transport/log/Recorder.hh>
//////////////////////////////////////////////////
int main(int argc, char *argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " OUTPUT.tlog\n";
return -1;
}
gz::transport::log::Recorder recorder;
// Record all topics
const int64_t addTopicResult = recorder.AddTopic(std::regex(".*"));
if (addTopicResult < 0)
{
std::cerr << "An error occurred when trying to add topics: "
<< addTopicResult << "\n";
return -1;
}
// Begin recording, saving received messages to the given file
const auto result = recorder.Start(argv[1]);
if (gz::transport::log::RecorderError::SUCCESS != result)
{
std::cerr << "Failed to start recording: " << static_cast<int64_t>(result)
<< "\n";
return -2;
}
std::cout << "Press Ctrl+C to finish recording.\n Recording... "
<< std::endl;
// Wait until the interrupt signal is sent.
gz::transport::waitForShutdown();
recorder.Stop();
std::cout << "\nRecording finished!" << std::endl;
}
```
\snippet example/record.cc complete

### Walkthrough

Expand Down Expand Up @@ -130,50 +83,7 @@ Download the [playback.cc](https://github.com/gazebosim/gz-transport/raw/gz-tran
file within the `gz_transport_tutorial` folder and open it with your favorite
editor:

```{.cpp}
#include <cstdint>
#include <iostream>
#include <regex>
#include <gz/transport/log/Playback.hh>
//////////////////////////////////////////////////
int main(int argc, char *argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " INPUT.tlog\n";
return -1;
}
gz::transport::log::Playback player(argv[1]);
// Playback all topics
const int64_t addTopicResult = player.AddTopic(std::regex(".*"));
if (addTopicResult == 0)
{
std::cout << "No topics to play back\n";
return 0;
}
else if (addTopicResult < 0)
{
std::cerr << "Failed to advertise topics: " << addTopicResult
<< "\n";
return -1;
}
// Begin playback
const auto handle = player.Start();
if (!handle)
{
std::cerr << "Failed to start playback\n";
return -2;
}
// Wait until the player stops on its own
std::cout << "Playing all messages in the log file\n";
handle->WaitUntilFinished();
}
```
\snippet example/playback.cc complete

### Walkthrough

Expand Down

0 comments on commit 2ddd4c8

Please sign in to comment.