A mir client demonstrating prompt sessions.
The handles needs to be accessible both to callbacks and to the control function.
void* context)
{
(void)prompt_session;
demo_state->state = state;
printf("helper: Prompt Session state updated to %d\n", state);
{
kill(demo_state->child_pid, SIGINT);
}
}
static void client_fd_callback(
MirPromptSession* prompt_session,
size_t count,
int const* fds,
void* context)
{
(void)prompt_session;
((
MirDemoState*)context)->client_fds = malloc(
sizeof(
int)*count);
unsigned int i = 0;
for (; i < count; i++)
{
}
}
This program creates two processes, both opening a mir connection, one starting a prompt session with the other process.
#define _POSIX_SOURCE
#undef NDEBUG
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <signal.h>
{
pid_t child_pid;
int* client_fds;
unsigned int client_fd_count;
void* context)
{
(void)prompt_session;
demo_state->state = state;
printf("helper: Prompt Session state updated to %d\n", state);
{
kill(demo_state->child_pid, SIGINT);
}
}
static void client_fd_callback(
MirPromptSession* prompt_session,
size_t count,
int const* fds,
void* context)
{
(void)prompt_session;
((
MirDemoState*)context)->client_fds = malloc(
sizeof(
int)*count);
unsigned int i = 0;
for (; i < count; i++)
{
}
}
{
assert(mcd->connection != NULL);
printf("%s: Connected\n", name);
{
}
}
{
if (mcd->surface)
{
mcd->surface = 0;
printf("%s: Surface released\n", name);
}
printf("%s: Connection released\n", name);
}
void helper(
const char* server)
{
mcd.connection = 0;
mcd.surface = 0;
mcd.prompt_session = 0;
mcd.client_fd_count = 0;
assert(mcd.prompt_session != NULL);
puts("helper: Started prompt session");
assert(mcd.client_fd_count == 1);
puts("helper: Added waiting FD");
printf("helper: Starting child application 'mir_demo_client_basic' with fd://%d\n", mcd.client_fds[0]);
mcd.child_pid = fork();
if (mcd.child_pid == 0)
{
char buffer[128] = {0};
sprintf(buffer, "fd://%d", mcd.client_fds[0]);
char* args[4];
args[0] = "mir_demo_client_basic";
args[1] = "-m";
args[2] = &buffer[0];
args[3] = NULL;
errno = 0;
execvp("mir_demo_client_basic", args);
return;
}
int status;
printf("helper: Waiting on child application: %d\n", mcd.child_pid);
waitpid(mcd.child_pid, &status, 0);
{
mcd.prompt_session = NULL;
puts("helper: Stopped prompt session");
}
else
{
puts("helper: Prompt session stopped by server");
}
puts("helper: Done");
}
int main(
int argc,
char* argv[])
{
char const *server = NULL;
{
int arg;
opterr = 0;
while ((arg = getopt (argc, argv, "c:hm:")) != -1)
{
switch (arg)
{
case 'm':
server = optarg;
break;
case '?':
case 'h':
default:
puts(argv[0]);
puts("Usage:");
puts(" -m <Mir server socket>");
puts(" -h: this help text");
return -1;
}
}
}
return 0;
}