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_;
61 typename App::ConfigType cfg;
62 google::protobuf::TextFormat::Parser parser;
63 goby::util::FlexOStreamErrorCollector error_collector(config);
64 parser.RecordErrorsTo(&error_collector);
65 parser.AllowPartialMessage(
false);
66 parser.ParseFromString(config, &cfg);
68 App::app_cfg_.reset(
new typename App::ConfigType(cfg));
73 app_ptr_.reset(
new App);
76 void run() { app_ptr_->__run(); }
81 const std::vector<std::uint8_t>& bytes)
87 std::string func, std::string module)
96 std::vector<std::uint8_t> v(app_ptr_->app_cfg().ByteSizeLong());
97 app_ptr_->app_cfg().SerializeToArray(&v[0], v.size());
102 std::unique_ptr<App> app_ptr_;
105template <
typename App>
108 types.add_bits<PubSubLayer>(
"PubSubLayer", jlcxx::julia_type(
"CppEnum"));
109 types.set_const(
"INTERTHREAD", PubSubLayer::INTERTHREAD);
110 types.set_const(
"INTERPROCESS", PubSubLayer::INTERPROCESS);
111 types.set_const(
"INTERMODULE", PubSubLayer::INTERMODULE);
114 jlcxx::julia_type(
"CppEnum"));
119 types.template add_type<ApplicationWrapper<App>>(app_name)
120 .
template constructor<std::string>()
136#define GOBY_JULIA_IF_PUBLICATION(SCHEME, LAYER_ENUM, LAYER_FUNCTION, GROUP, GROUP_KEY, TYPE) \
137 if (id == goby::middleware::julia::Identifier{ \
138 goby::middleware::julia::PubSubLayer::LAYER_ENUM, TYPE::descriptor()->name(), \
139 goby::middleware::MarshallingScheme::SCHEME, GROUP_KEY}) \
141 decltype(bytes.end()) actual_end; \
142 auto msg = goby::middleware::SerializerParserHelper< \
143 TYPE, goby::middleware::MarshallingScheme::SCHEME>::parse(bytes.begin(), bytes.end(), \
145 LAYER_FUNCTION().publish<GROUP>(msg); \
149#define GOBY_JULIA_IF_SUBSCRIPTION(SCHEME, LAYER_ENUM, LAYER_FUNCTION, GROUP, GROUP_KEY, TYPE) \
150 if (id == goby::middleware::julia::Identifier{ \
151 goby::middleware::julia::PubSubLayer::LAYER_ENUM, TYPE::descriptor()->name(), \
152 goby::middleware::MarshallingScheme::SCHEME, GROUP_KEY}) \
154 LAYER_FUNCTION().subscribe<GROUP>( \
155 [=](const TYPE& pb) \
157 std::vector<std::uint8_t> bytes = goby::middleware::julia::serialize_uint8< \
158 TYPE, goby::middleware::MarshallingScheme::SCHEME>(pb); \
159 jlcxx::JuliaFunction cb(func, module); \
160 cb(id.layer, id.type_name, id.scheme, id.group, bytes); \
165#define GOBY_JULIA_FAIL(PUBLISH_OR_SUBSCRIBE) \
166 goby::glog.is_die() && \
167 goby::glog << PUBLISH_OR_SUBSCRIBE " not defined for these parameters: [" << id \
168 << "]. Please include in interfaces.yml and re-generate to include them." \
172#define GOBY_JULIA_QUOTE(name) #name
173#define GOBY_JULIA_DEFINE_MODULE(APPLICATION_NAME) \
174 JLCXX_MODULE define_julia_module(jlcxx::Module& types) \
176 goby::middleware::julia::define_julia_module<APPLICATION_NAME>( \
177 types, GOBY_JULIA_QUOTE(APPLICATION_NAME)); \
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 configure_simulation_time(const protobuf::AppConfig &app_cfg)
Applies the simulation time settings from an application configuration to goby::time::SimulatorSettin...
void define_julia_module(jlcxx::Module &types, const std::string &app_name)
std::vector< std::uint8_t > serialize_uint8(const DataType &msg)
Marshals a message using the given scheme, returning the bytes to hand to the bound language.
PubSubLayer
The publish/subscribe layer used for a given publication or subscription.
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
The global namespace for the Goby project.
MarshallingSchemeEnum
Marshalilng schemes implemented in Goby.
Fully identifies a publication or subscription crossing the language boundary.