wlmaker
Loading...
Searching...
No Matches
Classes | Functions
subprocess_monitor.c File Reference
#include "subprocess_monitor.h"
#include <inttypes.h>
#include <libbase/libbase.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server-core.h>
#include <wayland-util.h>
#include "toolkit/toolkit.h"
Include dependency graph for subprocess_monitor.c:

Classes

struct  _wlmaker_subprocess_monitor_t
 
struct  _wlmaker_subprocess_handle_t
 
struct  wlmaker_subprocess_window_t
 

Functions

static wlmaker_subprocess_handle_twlmaker_subprocess_handle_create (bs_subprocess_t *subprocess_ptr, struct wl_event_loop *wl_event_loop_ptr)
 
static void wlmaker_subprocess_handle_destroy (wlmaker_subprocess_handle_t *sp_handle_ptr)
 
static int _wlmaker_subprocess_monitor_handle_read_stdout (int fd, uint32_t mask, void *data_ptr)
 
static int _wlmaker_subprocess_monitor_handle_read_stderr (int fd, uint32_t mask, void *data_ptr)
 
static int _wlmaker_subprocess_monitor_process_fd (wlmaker_subprocess_handle_t *subprocess_handle_ptr, struct wl_event_source **wl_event_source_ptr_ptr, int fd, uint32_t mask, const char *fd_name_ptr, bs_dynbuf_t *dynbuf_ptr)
 
static int _wlmaker_subprocess_monitor_handle_sigchld (int signum, void *data_ptr)
 
static void _wlmaker_subprocess_monitor_handle_window_created (struct wl_listener *listener_ptr, void *data_ptr)
 
static void _wlmaker_subprocess_monitor_handle_window_mapped (struct wl_listener *listener_ptr, void *data_ptr)
 
static void _wlmaker_subprocess_monitor_handle_window_unmapped (struct wl_listener *listener_ptr, void *data_ptr)
 
static void _wlmaker_subprocess_monitor_handle_window_destroyed (struct wl_listener *listener_ptr, void *data_ptr)
 
static wlmaker_subprocess_handle_tsubprocess_handle_from_window (wlmaker_subprocess_monitor_t *monitor_ptr, wlmtk_window_t *window_ptr)
 
static wlmaker_subprocess_window_twlmaker_subprocess_window_create (wlmtk_window_t *window_ptr, wlmaker_subprocess_handle_t *subprocess_handle_ptr)
 
static void wlmaker_subprocess_window_destroy (wlmaker_subprocess_window_t *ws_window_ptr)
 
static int wlmaker_subprocess_window_node_cmp (const bs_avltree_node_t *node_ptr, const void *key_ptr)
 
static void wlmaker_subprocess_window_node_destroy (bs_avltree_node_t *node_ptr)
 
wlmaker_subprocess_monitor_twlmaker_subprocess_monitor_create (wlmaker_server_t *server_ptr)
 
void wlmaker_subprocess_monitor_destroy (wlmaker_subprocess_monitor_t *monitor_ptr)
 
bool wlmaker_subprocess_monitor_run (wlmaker_subprocess_monitor_t *monitor_ptr, bs_subprocess_t *subprocess_ptr)
 
wlmaker_subprocess_handle_twlmaker_subprocess_monitor_entrust (wlmaker_subprocess_monitor_t *monitor_ptr, bs_subprocess_t *subprocess_ptr, wlmaker_subprocess_terminated_callback_t terminated_callback, void *userdata_ptr, wlmaker_subprocess_window_callback_t window_created_callback, wlmaker_subprocess_window_callback_t window_mapped_callback, wlmaker_subprocess_window_callback_t window_unmapped_callback, wlmaker_subprocess_window_callback_t window_destroyed_callback, bs_dynbuf_t *stdout_dynbuf_ptr)
 
void wlmaker_subprocess_monitor_cede (wlmaker_subprocess_monitor_t *monitor_ptr, wlmaker_subprocess_handle_t *subprocess_handle_ptr)
 
bs_subprocess_t * wlmaker_subprocess_from_subprocess_handle (wlmaker_subprocess_handle_t *subprocess_handle_ptr)
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlmaker_subprocess_monitor_handle_read_stderr()

int _wlmaker_subprocess_monitor_handle_read_stderr ( int  fd,
uint32_t  mask,
void *  data_ptr 
)
static

Handler for activity on stderr file descriptor, as prescribed by wl_event_loop_fd_func_t.

Parameters
fd
maskA bitmask of WL_EVENT_READABLE, WL_EVENT_HANGUP or WL_EVENT_ERROR.
data_ptrPoints to a wlmaker_subprocess_handle_t.
Returns
0.

◆ _wlmaker_subprocess_monitor_handle_read_stdout()

int _wlmaker_subprocess_monitor_handle_read_stdout ( int  fd,
uint32_t  mask,
void *  data_ptr 
)
static

Handler for activity on stdout file descriptor, as prescribed by wl_event_loop_fd_func_t.

Parameters
fd
maskA bitmask of WL_EVENT_READABLE, WL_EVENT_HANGUP or WL_EVENT_ERROR.
data_ptrPoints ot a wlmaker_subprocess_handle_t.
Returns
0.

◆ _wlmaker_subprocess_monitor_handle_sigchld()

int _wlmaker_subprocess_monitor_handle_sigchld ( int  signum,
void *  data_ptr 
)
static

Handles SIGCHLD. Callback for Wayland event loop.

Parameters
signum
data_ptrPoints to wlmaker_subprocess_monitor_t.

◆ _wlmaker_subprocess_monitor_handle_window_created()

void _wlmaker_subprocess_monitor_handle_window_created ( struct wl_listener *  listener_ptr,
void *  data_ptr 
)
static

Handles window creation: Will see if there's a subprocess mapping to the corresponding client's PID, and call the "created" callback, if registered.

Note: A client may have an arbitrary number of windows created.

Parameters
listener_ptr
data_ptrPoints to a wlmaker_subprocess_monitor_t.

◆ _wlmaker_subprocess_monitor_handle_window_destroyed()

void _wlmaker_subprocess_monitor_handle_window_destroyed ( struct wl_listener *  listener_ptr,
void *  data_ptr 
)
static

Handles window destruction: Will retrieve the wlmaker_subprocess_window_t structure for tracking windows for subprocesses, call the respective callbacks and destroy the associated window tracking structure.

Parameters
listener_ptr
data_ptrPoints to a wlmaker_subprocess_monitor_t.

◆ _wlmaker_subprocess_monitor_handle_window_mapped()

void _wlmaker_subprocess_monitor_handle_window_mapped ( struct wl_listener *  listener_ptr,
void *  data_ptr 
)
static

Handles window mapping: Will see if there's a window and corresponding subprocess, and calls the "mapped" callback, if registered.

Parameters
listener_ptr
data_ptrPoints to a wlmaker_subprocess_monitor_t.

◆ _wlmaker_subprocess_monitor_handle_window_unmapped()

void _wlmaker_subprocess_monitor_handle_window_unmapped ( struct wl_listener *  listener_ptr,
void *  data_ptr 
)
static

Handles window unmapping: Will see if there's a window and corresponding subprocess, and calls the "unmapped" callback, if registered.

Parameters
listener_ptr
data_ptrPoints to a wlmaker_subprocess_monitor_t.

◆ _wlmaker_subprocess_monitor_process_fd()

int _wlmaker_subprocess_monitor_process_fd ( wlmaker_subprocess_handle_t subprocess_handle_ptr,
struct wl_event_source **  wl_event_source_ptr_ptr,
int  fd,
uint32_t  mask,
const char *  fd_name_ptr,
bs_dynbuf_t *  dynbuf_ptr 
)
static

Processes activity on a file descriptor, matches wl_event_loop_fd_func_t.

Parameters
subprocess_handle_ptr
wl_event_source_ptr_ptr
fd
mask
fd_name_ptr
dynbuf_ptr
Returns
0.

◆ subprocess_handle_from_window()

wlmaker_subprocess_handle_t * subprocess_handle_from_window ( wlmaker_subprocess_monitor_t monitor_ptr,
wlmtk_window_t window_ptr 
)
static

Returns the subprocess matching the window's client, if any.

Practically, there should only ever be one subprocess matching, since the PID of a subprocess is supposed to be unique.

Parameters
monitor_ptr
window_ptr
Returns
A pointer to the subprocess handle corresponding to the window's client, or NULL if not found.

◆ wlmaker_subprocess_from_subprocess_handle()

bs_subprocess_t * wlmaker_subprocess_from_subprocess_handle ( wlmaker_subprocess_handle_t subprocess_handle_ptr)

Returns the bs_subprocess_t from the wlmaker_subprocess_handle_t.

◆ wlmaker_subprocess_handle_create()

wlmaker_subprocess_handle_t * wlmaker_subprocess_handle_create ( bs_subprocess_t *  subprocess_ptr,
struct wl_event_loop *  wl_event_loop_ptr 
)
static

Creates a wlmaker_subprocess_handle_t and connects to subprocess_ptr.

Parameters
subprocess_ptr
wl_event_loop_ptr
Returns
The subprocess handle or NULL on error.

◆ wlmaker_subprocess_handle_destroy()

void wlmaker_subprocess_handle_destroy ( wlmaker_subprocess_handle_t sp_handle_ptr)
static

Destroys the subprocess handle and frees up associated resources.

Parameters
sp_handle_ptr

◆ wlmaker_subprocess_monitor_cede()

void wlmaker_subprocess_monitor_cede ( wlmaker_subprocess_monitor_t monitor_ptr,
wlmaker_subprocess_handle_t subprocess_handle_ptr 
)

Releases the reference held on subprocess_handle_ptr. Once the subprocess terminates, all corresponding resources will be freed.

Parameters
monitor_ptr
subprocess_handle_ptr

◆ wlmaker_subprocess_monitor_create()

wlmaker_subprocess_monitor_t * wlmaker_subprocess_monitor_create ( wlmaker_server_t server_ptr)

Creates the subprocess monitor

Parameters
server_ptr
Returns
Pointer to the subprocess monitor or NULL on error.

◆ wlmaker_subprocess_monitor_destroy()

void wlmaker_subprocess_monitor_destroy ( wlmaker_subprocess_monitor_t monitor_ptr)

Destroys the subprocess monitor.

Parameters
monitor_ptr

◆ wlmaker_subprocess_monitor_entrust()

wlmaker_subprocess_handle_t * wlmaker_subprocess_monitor_entrust ( wlmaker_subprocess_monitor_t monitor_ptr,
bs_subprocess_t *  subprocess_ptr,
wlmaker_subprocess_terminated_callback_t  terminated_callback,
void *  userdata_ptr,
wlmaker_subprocess_window_callback_t  window_created_callback,
wlmaker_subprocess_window_callback_t  window_mapped_callback,
wlmaker_subprocess_window_callback_t  window_unmapped_callback,
wlmaker_subprocess_window_callback_t  window_destroyed_callback,
bs_dynbuf_t *  stdout_dynbuf_ptr 
)

Passes ownership of the started subprocess_ptr to monitor_ptr.

Also registers a set of callbacks that will be triggered. Permits to keep a central register of all started sub-processes, to monitor for termination, and to link up connecting clients with the sub-processes.

Parameters
monitor_ptr
subprocess_ptr
terminated_callback
userdata_ptr
window_created_callback
window_mapped_callback
window_unmapped_callback
window_destroyed_callback
stdout_dynbuf_ptr
Returns
A pointer to the created subprocess handle or NULL on error.

◆ wlmaker_subprocess_monitor_run()

bool wlmaker_subprocess_monitor_run ( wlmaker_subprocess_monitor_t monitor_ptr,
bs_subprocess_t *  subprocess_ptr 
)

Starts, entrust and cedes a subprocess to the monitor.

Parameters
monitor_ptr
subprocess_ptrSubprocess. Ignored, if NULL. Takes ownership.
Returns
true on success.

◆ wlmaker_subprocess_window_create()

wlmaker_subprocess_window_t * wlmaker_subprocess_window_create ( wlmtk_window_t window_ptr,
wlmaker_subprocess_handle_t subprocess_handle_ptr 
)
static

Creates a structure to track windows for subprocesses.

Also calls the window_created_callback, if given.

Parameters
window_ptr
subprocess_handle_ptr
Returns
A pointer to wlmaker_subprocess_window_t or NULL on error.

◆ wlmaker_subprocess_window_destroy()

void wlmaker_subprocess_window_destroy ( wlmaker_subprocess_window_t ws_window_ptr)
static

Destroys the structure for tracking windows for subprocesses.

Calls the window_destroyed_callback, if given.

Parameters
ws_window_ptr

◆ wlmaker_subprocess_window_node_cmp()

int wlmaker_subprocess_window_node_cmp ( const bs_avltree_node_t *  node_ptr,
const void *  key_ptr 
)
static

Comparator for window registry tree nodes.

◆ wlmaker_subprocess_window_node_destroy()

void wlmaker_subprocess_window_node_destroy ( bs_avltree_node_t *  node_ptr)
static

Destructor for window registry tree nodes.