24#include <jlcxx/functions.hpp>
25#include <jlcxx/jlcxx.hpp>
57 if (!loop_function.empty())
58 loop_ = std::make_unique<jlcxx::JuliaFunction>(loop_function);
62 std::unique_ptr<jlcxx::JuliaFunction> loop_;
85 typename App::ConfigType cfg;
86 google::protobuf::TextFormat::Parser parser;
87 goby::util::FlexOStreamErrorCollector error_collector(config);
88 parser.RecordErrorsTo(&error_collector);
89 parser.AllowPartialMessage(
false);
90 parser.ParseFromString(config, &cfg);
92 App::app_cfg_.reset(
new typename App::ConfigType(cfg));
96 if (App::app3_base_configuration_->simulation().time().use_sim_time())
100 App::app3_base_configuration_->simulation().time().warp_factor();
101 if (App::app3_base_configuration_->simulation().time().has_reference_microtime())
103 std::chrono::system_clock::time_point(std::chrono::microseconds(
104 App::app3_base_configuration_->simulation().time().reference_microtime()));
107 app_ptr_.reset(
new App);
108 app_ptr_->set_loop_function_name(loop_function_name);
111 void run() { app_ptr_->__run(); }
116 const std::vector<std::uint8_t>& bytes)
122 std::string func, std::string module)
128 std::unique_ptr<App> app_ptr_;
129 std::map<std::string, goby::middleware::DynamicGroup> subscription_groups_;
132template <
typename App>
135 types.add_bits<
PubSubLayer>(
"PubSubLayer", jlcxx::julia_type(
"CppEnum"));
141 jlcxx::julia_type(
"CppEnum"));
146 types.template add_type<ApplicationWrapper<App>>(app_name)
147 .
template constructor<std::string>()
148 .template constructor<std::string, std::string>()
154template <
typename DataType,
int scheme>
157 std::vector<char> out =
159 return std::vector<std::uint8_t>(out.begin(), out.end());
177 return (os <<
"layer: " << layer <<
", type_name: \"" << i.
type_name
179 <<
", group: \"" << i.
group <<
"\"");
183#define GOBY_JULIA_IF_PUBLICATION(SCHEME, LAYER_ENUM, LAYER_FUNCTION, GROUP, TYPE) \
184 if (id == goby::middleware::julia::Identifier{ \
185 goby::middleware::julia::PubSubLayer::LAYER_ENUM, TYPE::descriptor()->name(), \
186 goby::middleware::MarshallingScheme::SCHEME, GROUP}) \
188 decltype(bytes.end()) actual_end; \
189 auto msg = goby::middleware::SerializerParserHelper< \
190 TYPE, goby::middleware::MarshallingScheme::SCHEME>::parse(bytes.begin(), bytes.end(), \
192 LAYER_FUNCTION().publish<GROUP>(msg); \
196#define GOBY_JULIA_IF_SUBSCRIPTION(SCHEME, LAYER_ENUM, LAYER_FUNCTION, GROUP, TYPE) \
197 if (id == goby::middleware::julia::Identifier( \
198 goby::middleware::julia::PubSubLayer::LAYER_ENUM, TYPE::descriptor()->name(), \
199 goby::middleware::MarshallingScheme::SCHEME, GROUP)) \
201 LAYER_FUNCTION().subscribe<GROUP>( \
202 [=](const TYPE& pb) \
204 std::vector<std::uint8_t> bytes = goby::middleware::julia::serialize_uint8< \
205 TYPE, goby::middleware::MarshallingScheme::SCHEME>(pb); \
206 jlcxx::JuliaFunction cb(func, module); \
207 cb(id.layer, id.type_name, id.scheme, id.group, bytes); \
212#define GOBY_JULIA_FAIL(PUBLISH_OR_SUBSCRIBE) \
213 goby::glog.is_die() && \
214 goby::glog << PUBLISH_OR_SUBSCRIBE " not defined for these parameters: [" << id \
215 << "]. Please include in interfaces.yml and re-generate to include them." \
219#define GOBY_JULIA_QUOTE(name) #name
220#define GOBY_JULIA_DEFINE_MODULE(APPLICATION_NAME) \
221 JLCXX_MODULE define_julia_module(jlcxx::Module& types) \
223 goby::middleware::julia::define_julia_module<APPLICATION_NAME>( \
224 types, GOBY_JULIA_QUOTE(APPLICATION_NAME)); \
ApplicationWrapper(std::string config, std::string loop_function_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)
void set_loop_function_name(std::string loop_function)
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)
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
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...