Your window manager interacts with the /pps/services/launcher/control object to start and stop applications.
You can create a thread in your window manager to manage your interactions with the PPS object:
window_manager_t window_manager; memset(&window_manager, 0, sizeof(window_manager_t)); window_manager_t *winmgr = &window_manager; ... int pps_tid; /* PPS thread ID */ void *pps_thread(void *arg); if (rc = pthread_create(NULL, NULL, pps_thread, (void*)win_mgr) < 0) { /* error-handling code goes here */ } pthread_setname_np(screen_tid = pthread_self(), "pps");
Simply call open() with O_RDWR from your PPS thread to publish and subscribe to the /pps/services/launcher/control object.
Make sure to open the object in delta mode and wait mode. With delta mode, a subscriber receives only the changes to the object attributes. The wait mode means that any read() calls to the object block until the object changes or a delta appears.
int pps_fd; pps_fd = open("/pps/services/launcher/control?wait,delta", O_RDWR);
In your window manager's PPS thread, parse the PPS message received and then handle each message type accordingly. Refer to "PPS API reference" in the Persistent Publish/Subscribe Developer's Guide for PPS API constants and functions.
Here's an example of how you could implement handling PPS messages:
char buf[1024]; int nread = -1; while(1){ ... while (nread == -1){ ... nread = read(fd, buf, sizeof(buf)-1); if (nread > 1){ buf[nread] = '\0'; /* Declare variables to store PPS API attribute and status*/ pps_attrib_t info; pps_status_t rc; /* Call PPS API function ppsparse() to parse * the message received */ while((rc = ppsparse(&buf, NULL, NULL, &info, 0)) != PPS_END) { /* Handle each PPS message type accordingly */ switch(rc) { case PPS_OBJECT_CREATED: win_mgr->objname = info.obj_name; win_mgr->ptype = PPS_EVENT_OBJECT_CREATED; break; case PPS_OBJECT_TRUNCATED: case PPS_OBJECT_DELETED: nav->objname = info.obj_name; nav->ptype = PPS_EVENT_OBJECT_DELETED; break; case PPS_OBJECT: if(info.obj_name[0] != '@') { exit; } win_mgr->objname = info.obj_name; win_mgr->ptype = PPS_EVENT_OBJECT_CHANGED; break; case PPS_ATTRIBUTE_DELETED: { --info.attr_name; /* Handle when there is an attributed deleted */ int err = pps_parse_attr(nav, &info); if(err != EOK) return; } case PPS_ATTRIBUTE: { /* Handle when there is an attributed updated */ int err = pps_parse_attr(nav, &info); if(err != EOK) return; break; } case PPS_ERROR: default: SLOG_WARNING("We got a parsing error."); return; } } /* Update any necessary information such as appending * or deleting from your application list based on the * PPS message received and parsed. In this case, we * are calling a helper function, launcher_pps() to * perform any updates to the window manager. */ launcher_pps(win_mgr); } } }