24#include <jlcxx/functions.hpp>
25#include <jlcxx/jlcxx.hpp>
49 Application() { loop_ = std::make_unique<jlcxx::JuliaFunction>(
"cxx_loop",
"Goby"); }
50 void loop()
override { (*loop_)(); }
53 std::unique_ptr<jlcxx::JuliaFunction> loop_;
75 typename App::ConfigType cfg;
76 google::protobuf::TextFormat::Parser parser;
78 parser.RecordErrorsTo(&error_collector);
79 parser.AllowPartialMessage(
false);
80 parser.ParseFromString(config, &cfg);
82 App::app_cfg_.reset(
new typename App::ConfigType(cfg));
86 if (App::app3_base_configuration_->simulation().
time().use_sim_time())
90 App::app3_base_configuration_->simulation().time().warp_factor();
91 if (App::app3_base_configuration_->simulation().
time().has_reference_microtime())
93 std::chrono::system_clock::time_point(std::chrono::microseconds(
94 App::app3_base_configuration_->simulation().
time().reference_microtime()));
97 app_ptr_.reset(
new App);
100 void run() { app_ptr_->__run(); }
105 const std::vector<std::uint8_t>& bytes)
111 std::string func, std::string module)
120 std::vector<std::uint8_t> v(app_ptr_->app_cfg().ByteSizeLong());
121 app_ptr_->app_cfg().SerializeToArray(&v[0], v.size());
126 std::unique_ptr<App> app_ptr_;
127 std::map<std::string, goby::middleware::DynamicGroup> subscription_groups_;
130template <
typename App>
133 types.add_bits<
PubSubLayer>(
"PubSubLayer", jlcxx::julia_type(
"CppEnum"));
139 jlcxx::julia_type(
"CppEnum"));
144 types.template add_type<ApplicationWrapper<App>>(app_name)
145 .
template constructor<std::string>()
153template <
typename DataType,
int scheme>
156 std::vector<char> out =
158 return std::vector<std::uint8_t>(out.begin(), out.end());
176 return (os <<
"layer: " << layer <<
", type_name: \"" << i.
type_name
178 <<
", group: \"" << i.
group <<
"\"");
182#define GOBY_JULIA_IF_PUBLICATION(SCHEME, LAYER_ENUM, LAYER_FUNCTION, GROUP, TYPE) \
183 if (id == goby::middleware::julia::Identifier{ \
184 goby::middleware::julia::PubSubLayer::LAYER_ENUM, TYPE::descriptor()->name(), \
185 goby::middleware::MarshallingScheme::SCHEME, GROUP}) \
187 decltype(bytes.end()) actual_end; \
188 auto msg = goby::middleware::SerializerParserHelper< \
189 TYPE, goby::middleware::MarshallingScheme::SCHEME>::parse(bytes.begin(), bytes.end(), \
191 LAYER_FUNCTION().publish<GROUP>(msg); \
195#define GOBY_JULIA_IF_SUBSCRIPTION(SCHEME, LAYER_ENUM, LAYER_FUNCTION, GROUP, TYPE) \
196 if (id == goby::middleware::julia::Identifier( \
197 goby::middleware::julia::PubSubLayer::LAYER_ENUM, TYPE::descriptor()->name(), \
198 goby::middleware::MarshallingScheme::SCHEME, GROUP)) \
200 LAYER_FUNCTION().subscribe<GROUP>( \
201 [=](const TYPE& pb) \
203 std::vector<std::uint8_t> bytes = goby::middleware::julia::serialize_uint8< \
204 TYPE, goby::middleware::MarshallingScheme::SCHEME>(pb); \
205 jlcxx::JuliaFunction cb(func, module); \
206 cb(id.layer, id.type_name, id.scheme, id.group, bytes); \
211#define GOBY_JULIA_FAIL(PUBLISH_OR_SUBSCRIBE) \
212 goby::glog.is_die() && \
213 goby::glog << PUBLISH_OR_SUBSCRIBE " not defined for these parameters: [" << id \
214 << "]. Please include in interfaces.yml and re-generate to include them." \
218#define GOBY_JULIA_QUOTE(name) #name
219#define GOBY_JULIA_DEFINE_MODULE(APPLICATION_NAME) \
220 JLCXX_MODULE define_julia_module(jlcxx::Module& types) \
222 goby::middleware::julia::define_julia_module<APPLICATION_NAME>( \
223 types, GOBY_JULIA_QUOTE(APPLICATION_NAME)); \
std::ostream & operator<<(std::ostream &os, const goby::middleware::julia::Identifier &i)
void subscribe(PubSubLayer layer, std::string type_name, int scheme, std::string group, std::string func, std::string module)
ApplicationWrapper & interprocess()
ApplicationWrapper(std::string config)
void publish(PubSubLayer layer, std::string type_name, int scheme, std::string group, const std::vector< std::uint8_t > &bytes)
std::vector< std::uint8_t > cfg_serialized()
void set_loop_frequency_hertz(double freq)
goby::util::logger::GroupSetter group(std::string n)
void define_julia_module(jlcxx::Module &types, const std::string &app_name)
bool operator==(const Identifier &i1, const Identifier &i2)
std::vector< std::uint8_t > serialize_uint8(const DataType &msg)
Objects implementing the Goby nested middleware.
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
Functions and objects related to timekeeping.
The global namespace for the Goby project.
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::MessageOptions, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
MarshallingSchemeEnum
Marshalilng schemes implemented in Goby.
static std::string to_string(int e)
Convert a known marshalling scheme to a human-readable string or an unknown scheme to the string repr...
static std::vector< char > serialize(const DataType &)
Given data, produce a vector of bytes.
goby::middleware::julia::PubSubLayer layer
static bool using_sim_time
Enables simulation time if true (if false, none of the remaining parameters are used).
static std::chrono::system_clock::time_point reference_time
Reference time when calculating SystemClock::now(). If this is unset, the default is 1 January of the...
static int warp_factor
Warp factor to speed up (or slow time) the time values returned by SteadyClock::now() and SystemClock...