46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
#include <debugconsole.h>
|
|
#include <process.h>
|
|
#include <status.h>
|
|
#include <strconv.h>
|
|
#include <string.h>
|
|
#include <system.h>
|
|
|
|
void app_main(void) {
|
|
char commandbuf[32];
|
|
memset(commandbuf, 0, sizeof(commandbuf));
|
|
char payloadbuf[32];
|
|
memset(payloadbuf, 0, sizeof(payloadbuf));
|
|
char procgroupbuf[32];
|
|
memset(procgroupbuf, 0, sizeof(procgroupbuf));
|
|
|
|
if (env_get(process_get_pgid(), "C", (void*)commandbuf, sizeof(commandbuf)) != ST_OK) {
|
|
return;
|
|
}
|
|
|
|
if (strcmp(commandbuf, "recv") == 0) {
|
|
char recv_buffer[1024];
|
|
|
|
for (;;) {
|
|
debug_printf("Waiting...\n");
|
|
memset(recv_buffer, 0, sizeof(recv_buffer));
|
|
mail_receive(recv_buffer, sizeof(recv_buffer));
|
|
|
|
debug_printf("Recv: %s\n", recv_buffer);
|
|
}
|
|
} else if (strcmp(commandbuf, "send") == 0) {
|
|
if (env_get(process_get_pgid(), "payload", (void*)payloadbuf, sizeof(payloadbuf)) != ST_OK) {
|
|
return;
|
|
}
|
|
|
|
if (env_get(process_get_pgid(), "pg", (void*)procgroupbuf, sizeof(procgroupbuf)) != ST_OK) {
|
|
return;
|
|
}
|
|
|
|
int pgid = str_to_uint32(procgroupbuf);
|
|
|
|
debug_printf("sending %s to PG %s (%d)\n", payloadbuf, procgroupbuf, pgid);
|
|
|
|
mail_send(pgid, payloadbuf, sizeof(payloadbuf));
|
|
}
|
|
}
|