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
External messaging. #1807
External messaging. #1807
Conversation
include/toit/cmessaging.h
Outdated
// directory of this repository. | ||
|
||
/* | ||
* C interface for Toit's messaging API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider just having a single toit.h
include file that has all our APIs in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I called it ctoit.h
.
I think it makes sense to split it out again if we ever have more functions (and have a ctoit.h
that combines all others). At the moment that's not worth it.
done.
include/toit/cmessaging.h
Outdated
|
||
#pragma once | ||
|
||
#include <stdint.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
include/toit/cmessaging.h
Outdated
|
||
void toit_register_external_message_handler(void* user_context, | ||
int requested_pid, | ||
void (*create_handler)(void* user_context, HandlerContext* handler_context)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd introduce a type for the create handler function. It feels cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
include/toit/cmessaging.h
Outdated
typedef struct HandlerContext HandlerContext; | ||
|
||
void toit_register_external_message_handler(void* user_context, | ||
int requested_pid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I think it would be better with a symbolic name here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do that in a follow-up PR.
include/toit/cmessaging.h
Outdated
void (*release)(void* user_context)); | ||
|
||
bool toit_send_message(HandlerContext* handler_context, int target_pid, int type, void* data, int length, bool free_on_failure); | ||
void toit_release_handler(HandlerContext* handler_context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void toit_release_handler(HandlerContext* handler_context); | |
void toit_release_handler(HandlerContext* handler_context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
include/toit/cmessaging.h
Outdated
struct HandlerContext; | ||
typedef struct HandlerContext HandlerContext; | ||
|
||
void toit_register_external_message_handler(void* user_context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add/remove instead of register/release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
src/messaging.cc
Outdated
|
||
void on_message(int pid, int type, void* data, int length) override { | ||
if (on_message_ == null) return; | ||
printf("Calling on-message %p\n", user_context_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the debug printing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
} | ||
list->handler.create_handler(list->handler.user_context, reinterpret_cast<HandlerContext*>(handler)); | ||
} | ||
// Free the list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you keep symbolic names in the list, you should probably not free it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I allocated a mapping object.
src/run.cc
Outdated
@@ -65,6 +66,7 @@ int run_program(SnapshotBundle boot_bundle, SnapshotBundle application_bundle, c | |||
vm.load_platform_event_sources(); | |||
ProgramImage boot_image = read_image_from_bundle(boot_bundle); | |||
int group_id = vm.scheduler()->next_group_id(); | |||
create_and_start_external_message_handlers(&vm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it important that you do this after you've gotten the group_id? If not, I'd try to do this before, maybe just after load_platform_event_sources()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -113,6 +114,7 @@ static void start() { | |||
{ VM vm; | |||
vm.load_platform_event_sources(); | |||
int group_id = vm.scheduler()->next_group_id(); | |||
create_and_start_external_message_handlers(&vm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again. Do you need the group id here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no Toit code in this PR?
There is no Toit code here. The example in the envelopes repository has some: toitlang/envelopes#22 |
No description provided.