static int Reply(adbus_CbData* d) { struct ReplyData* r = (struct ReplyData*) d->user1; if (d->msg->type == ADBUS_MSG_ERROR) { adbus_MsgFactory* msg = adbus_msg_new(); adbus_msg_settype(msg, ADBUS_MSG_ERROR); adbus_msg_setdestination(msg, r->sender, -1); adbus_msg_setreply(msg, r->serial); adbus_msg_seterror(msg, d->msg->error, -1); if (*d->msg->signature == 's') { const char* sig = adbus_check_string(d, NULL); adbus_msg_setsig(msg, "s", -1); adbus_msg_string(msg, sig, -1); } adbus_msg_send(msg, r->connection); adbus_msg_free(msg); FreeReply(r); } else if (--r->replies == 0) { adbus_MsgFactory* msg = adbus_msg_new(); adbus_msg_settype(msg, ADBUS_MSG_RETURN); adbus_msg_setdestination(msg, r->sender, -1); adbus_msg_setreply(msg, r->serial); adbus_msg_send(msg, r->connection); adbus_msg_free(msg); FreeReply(r); } return 0; }
Boolean WSMProcessProtoTarget(Widget w, Atom target, XtPointer input, unsigned long input_len, int input_fmt, Atom *return_type, XtPointer *output, unsigned long *output_len, int *output_fmt) { Display *dpy; int scr_num; WSMScreenInfo *screen_info; WSMRequest request; WSMReply reply; /* * Check the Target to make sure it is valid. * Check the format to make sure it is WSM_PROTO_FMT. */ if (!WSMIsKnownTarget(w, target)) return(False); if (input_fmt != WSM_PROTO_FMT) { fprintf(stderr, "Format of the request must be %d\n", WSM_PROTO_FMT); return(False); } dpy = XtDisplay(w); scr_num = XScreenNumberOfScreen(XtScreen(w)); /* * Unpack up the request from the wire. */ _WSMUnpackRequest(dpy, scr_num, (MessageData) input, input_len, _WSMTargetToReqType(dpy, target), &request); /* * Call the app's callback function to process the request. */ screen_info = _WSMGetScreenInfo(dpy, scr_num); reply.any.type = request.any.type; reply.any.allocated = False; (*screen_info->request_callback)(w, screen_info->request_data, &request, &reply); /* * Pack up the reply and send it back. */ *output = (XtPointer) _WSMPackReply(dpy, scr_num, &reply, output_len); *output_fmt = WSM_PROTO_FMT; *return_type = target; /* Is this the right return type? */ FreeRequest(&request); FreeReply(&reply); return(TRUE); }
static void ReleaseReply(void* u) { struct ReplyData* r = (struct ReplyData*) u; if (--r->ref == 0) FreeReply(r); }