-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of start() #109
Comments
@Tectu This is a weirdness with how friend functions work. Basically: friend functions ignore namespacing when pariticpating in overload resolution for arguments of the type they are friended to (ADL, other contraints still apply afaik) and access specifiers have no effect, additionally it is both implicitly in the namespace enclosing its frend and inaccessible without ADL unless a forward declaration for it is in said namespace. tl;dr for |
Well - that is something I didn't know :D
So how would I convert this to the new API? namespace myapp
{
class controller
{
public:
controller()
{
m_malloy_ctrl = std::make_shared<malloy::server::controller>();
if (!m_malloy_controller->init(cfg.malloy))
throw std::runtime_error("could not initialize malloy controller.");
}
void start()
{
m_malloy_ctrl->start();
}
void stop()
{
m_malloy_ctrl->stop().wait();
}
private:
std::shared_ptr<malloy::server::controller> m_malloy_ctrl;
};
} There is obviously going more on in that class but that would be the malloy specific parts. |
you'll need something like controller()
{
try {
m_malloy_ctrl = std::make_shared<malloy::server::controller>(cfg.malloy); // this will throw a runtime_error if the config is wrong
catch (const std::runtime_error&){
throw std::runtime_error("could not initialize malloy controller.");
}
}
void start() {
m_session = start(std::move(*m_malloy_ctrl));
}
void stop() {
m_session = std::nullopt;
}
private:
std::optional<malloy::server::routing_context::session> m_session; If you need it to be copyable you could make that optional a |
Yeah that's what I tried but I didn't get it to work (didn't get it to compile):
The call to malloy::server::routing_context::start(std::move(*m_malloy_controller)); compiling:
As I said: I feel like I'm missing something ridiculously obvious here. |
ah, yeah thats a problem. There's no way to access it if you've also got a member function with that name. A fix is to add this to your file: namespace malloy::server {
auto start(malloy::server::routing_context&&) -> malloy::server::routing_context::session;
} you can then call it directly with |
I really think so too :D Anyway - after workarounding that I'm back to the other problem which lead me to create this issue to check whether I'm doing things wrong: Anyway, I don't mean to make this issue become a "noob support ticket" or something like that. I honestly didn't know about the weirdness going on with the |
Are you using the latest commit? (or at least one since #108 was merged), it absolutely should be moveable since then (theres even a test case for it:
|
Yeah, this is on latest controller
{
public:
void init(const config& cfg)
{
try {
m_malloy_controller = std::make_shared<malloy::server::routing_context>(cfg.malloy);
}
catch (const std::exception& e) {
throw std::runtime_error("could not initialize malloy controller.");
}
}
void start()
{
m_malloy_session = std::move(malloy::server::start(std::move(*m_malloy_controller)));
}
void stop()
{
m_malloy_session = std::nullopt;
}
private:
std::shared_ptr<malloy::server::routing_context> m_malloy_controller;
std::optional<malloy::server::routing_context::session> m_malloy_session;
}; Using gcc
Alright |
That... is incredibly weird. When I try it with a basic example it works fine, but it does indeed fail for |
@0x00002a I have a question regarding the current way of starting a "session". I feel like I lack some C++ knowledge here but I'd rather just ask:
start()
is a private friend function. In the various examples, we just callstart()
like a free standing function frommain()
. How does this work?In an application which would consume
malloy-server
, how would one call thisstart()
private friend function from an application specific controller class which internally usesmalloy-server
?Unless I am missing something very obvious we'd have to call
malloy::server::routing_context::start()
from a class such asmyapp::controller
but it won't have access to this private friend function.The text was updated successfully, but these errors were encountered: