// Copyright status: this file is in the public domain. #include #include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_SetPointerMapping PRIV_SetPointerMapping; struct priv_SetPointerMapping { LX_MAPPINGSTATUS *statp; } ; static void done_SetPointerMapping(LX_CONN *xc, const unsigned char *rep, void *pv) { PRIV_SetPointerMapping *p; LX_MAPPINGSTATUS s; p = pv; do <"ret"> { if (r_card32(rep+4) != 0) { lx__protoerr(xc,"SetPointerMapping response length wrong (%u, expecting 0)",r_card32(rep+4)); break <"ret">; } s = lx__proto_to_mappingstatus(rep[1]); switch (s) { case LX_MAPPINGSTATUS_Success: case LX_MAPPINGSTATUS_Busy: break; default: lx__protoerr(xc,"SetPointerMapping reply has invalid status value %d",rep[1]); break <"ret">; } if (p->statp) *p->statp = s; } while (0); free(p); } LX_OP *lx_SetPointerMapping(LX_CONN *xc, int num, const unsigned char *mapping, LX_MAPPINGSTATUS *statp) { unsigned char req[4+256]; PRIV_SetPointerMapping *p; int i; if ((xc->flags & XCF_FAIL) || (num > 255)) { lx__bad_call(xc,"lx_SetPointerMapping"); return(0); } lx__nochain(xc); p = malloc(sizeof(PRIV_SetPointerMapping)); if (! p) { lx__nomem_fail(xc); return(0); } p->statp = statp; req[0] = XP_REQ_SetPointerMapping; req[1] = num; w_card16(&req[2],1+((num+3)>>2)); for (i=num-1;i>=0;i--) req[4+i] = mapping[i]; if (num & 3) bzero(req+4+num,4-(num&3)); return(lx__expect_reply(xc,&req[0],4+((num+3)&~3),&done_SetPointerMapping,p)); }