static int plugin_success(void *libhandle, int inst, const char *parent, const char *implstem, void *ud) { int rc = 0; struct success_box *box = ud; #define GET_CB(Stem) \ do { \ char buf[64]; \ snprintf(buf, sizeof buf, "%s_spi_"#Stem, implstem); \ void *ptr = dlsym(libhandle, buf); \ box->spi->impls[inst].Stem = ALIASING_CAST(spi_##Stem,ptr); \ } while (0) \ // GET_CB(clock); if (!box->spi->impls[inst].clock) { const char *err = dlerror(); if (err) fatal(0, "Failed to locate SPI clock cb for '%s' ; %s", implstem, err); else fatal(0, "SPI clock cb for '%s' is NULL ? : %s", implstem); } GET_CB(init); GET_CB(select); GET_CB(fini); if (box->spi->impls[inst].init) { struct plugin_cookie dst; dst.gops = box->pcookie->gops; dst.gops.param_get = wrapped_param_get; dst.gops.param_set = wrapped_param_set; dst.wrapped = box->pcookie; snprintf(dst.prefix, sizeof dst.prefix, "%s.%s", parent, implstem); if (box->spi->impls[inst].init(&box->spi->impl_cookies[inst], &dst)) debug(1, "SPI attached instance %d returned nonzero from init()", inst); } return rc; }
/** ******************************************************************************** ** \brief ** callback for ark functions: set,get,exists,del *******************************************************************************/ void kv_async_cb(int errcode, uint64_t dt, int64_t res) { async_context_t *pCT = pCTs+GET_CTXT(dt); async_CB_t *pCB = NULL; kv_t *p_kv = NULL; if (NULL == pCT) KV_ERR_STOP(pCB, "bad dt: ctxt", 0); pCB = pCT->pCBs+GET_CB(dt); if (NULL == pCB) KV_ERR_STOP(pCB, "bad dt: cb", 0); if (0 != errcode) KV_ERR_STOP(pCB, "bad errcode", errcode); if (dt != pCB->tag) KV_ERR_STOP(pCB, "bad tag", 0); if (res != pCB->db->vlen) KV_ERR_STOP(pCB, "bad res", 0); p_kv = pCB->db->kv + pCB->len_i; ++pCB->len_i; if (pCB->flags & KV_ASYNC_SET) { /* end of db len sequence, move to next step */ if (pCB->len_i == pCB->len) { pCB->len_i = 0; pCB->flags &= ~KV_ASYNC_SET; pCB->flags |= KV_ASYNC_GET; kv_async_GET_KEY(pCB); goto done; } kv_async_SET_KEY(pCB); goto done; } else if (pCB->flags & KV_ASYNC_GET) { if (0 != memcmp(p_kv->value, pCB->gvalue, pCB->db->vlen)) { KV_ERR_STOP(pCB,"get miscompare",0); } /* end of db len sequence, move to next step */ if (pCB->len_i == pCB->len) { pCB->len_i = 0; if (read100 && !(pCB->flags & KV_ASYNC_SHUTDOWN)) { kv_async_GET_KEY(pCB); } else { pCB->flags &= ~KV_ASYNC_GET; pCB->flags |= KV_ASYNC_EXISTS; kv_async_EXISTS_KEY(pCB); } goto done; } kv_async_GET_KEY(pCB); goto done; } else if (pCB->flags & KV_ASYNC_EXISTS) { /* if end of db len sequence, move to next step */ if (pCB->len_i == pCB->len) { pCB->len_i = 0; pCB->flags &= ~KV_ASYNC_EXISTS; pCB->flags |= KV_ASYNC_DEL; kv_async_DEL_KEY(pCB); goto done; } kv_async_EXISTS_KEY(pCB); goto done; } else if (pCB->flags & KV_ASYNC_DEL) { /* end of db len sequence, move to next step */ if (pCB->len_i == pCB->len) { if (pCB->flags & KV_ASYNC_SHUTDOWN) { pCB->flags &= ~KV_ASYNC_RUNNING; goto done; } pCB->flags &= ~KV_ASYNC_DEL; pCB->flags |= KV_ASYNC_SET; pCB->len_i = 0; kv_async_SET_KEY(pCB); goto done; } kv_async_DEL_KEY(pCB); goto done; } else { /* should not be here */ assert(0); } done: return; }