Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions score/mw/com/doc/tutorial/chapter_1/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "score/mw/com/doc/tutorial/chapter_1/hello_world_service.h"
#include "score/mw/com/types.h"

#include <algorithm>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstring>
#include <string>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -73,15 +73,11 @@ int main()
}

// Write new event data to slot
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
const std::string message = std::string{kHelloWorld} + std::to_string(send_counter);
auto& sample = *sample_allocatee_ptr.value().Get();
auto* buf = sample.data();
const auto chars_to_copy = std::min(message.size(), sample.size() - 1U);
*std::copy_n(message.begin(), chars_to_copy, sample.begin()) = '\0';

// Send the new event sample (make it visible to potential consumers)
// [hello-world-send-start]
Expand Down
18 changes: 7 additions & 11 deletions score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "score/mw/com/doc/tutorial/chapter_10/hello_world_service.h"
#include "score/mw/com/types.h"

#include <algorithm>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstring>
#include <string>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -63,15 +63,11 @@ int main()
}

// Write new event data to slot
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
const std::string message = std::string{kHelloWorld} + std::to_string(send_counter);
auto& sample = *sample_allocatee_ptr.value().Get();
auto* buf = sample.data();
const auto chars_to_copy = std::min(message.size(), sample.size() - 1U);
*std::copy_n(message.begin(), chars_to_copy, sample.begin()) = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = hello_world_service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
2 changes: 1 addition & 1 deletion score/mw/com/doc/tutorial/chapter_12/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ The `SkeletonComponent` implementation encapsulates offer/allocate/send behavior

.. literalinclude:: provider/skeleton_component.cpp
:language: cpp
:lines: 27-69
:lines: 26-64
:caption: provider/skeleton_component.cpp


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
********************************************************************************/
#include "score/mw/com/doc/tutorial/chapter_12/provider/skeleton_component.h"

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -46,15 +45,11 @@ SkeletonComponent::SendSampleResult SkeletonComponent::SendSample(std::size_t se
return SendSampleResult::kNoSampleAllocated;
}

std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
return SendSampleResult::kFatalError;
}
const std::string message = std::string{kHelloWorld} + std::to_string(send_counter);
auto& sample = *sample_allocatee_ptr.value().Get();
auto* buf = sample.data();
const auto chars_to_copy = std::min(message.size(), sample.size() - 1U);
*std::copy_n(message.begin(), chars_to_copy, sample.begin()) = '\0';

const std::string payload_for_log{buf};
auto send_result = hello_world_skeleton_->message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
18 changes: 7 additions & 11 deletions score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "score/mw/com/doc/tutorial/chapter_2/hello_world_service.h"
#include "score/mw/com/types.h"

#include <algorithm>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstring>
#include <string>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -63,15 +63,11 @@ int main()
}

// Write new event data to slot
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
const std::string message = std::string{kHelloWorld} + std::to_string(send_counter);
auto& sample = *sample_allocatee_ptr.value().Get();
auto* buf = sample.data();
const auto chars_to_copy = std::min(message.size(), sample.size() - 1U);
*std::copy_n(message.begin(), chars_to_copy, sample.begin()) = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = hello_world_service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
18 changes: 7 additions & 11 deletions score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "score/mw/com/doc/tutorial/chapter_6/hello_world_service.h"
#include "score/mw/com/types.h"

#include <algorithm>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstring>
#include <string>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -63,15 +63,11 @@ int main()
}

// Write new event data to slot
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
const std::string message = std::string{kHelloWorld} + std::to_string(send_counter);
auto& sample = *sample_allocatee_ptr.value().Get();
auto* buf = sample.data();
const auto chars_to_copy = std::min(message.size(), sample.size() - 1U);
*std::copy_n(message.begin(), chars_to_copy, sample.begin()) = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = hello_world_service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
Loading