コード例 #1
0
static int rpc_client_wch_add(rpc_client_s *c, char *path, void *wch)
{
	int i;
	const char *tmp;

	for (i = 0; i < c->opts.cnt; i++) {
		tmp = c->opts.arr[i].path;
		if (tmp && (0 == strcmp(tmp, path))) {
			kerror("%s already\n", path);
			return -1;
		}
	}

	for (i = 0; i < c->opts.cnt; i++)
		if (!c->opts.arr[i].path) {
			c->opts.arr[i].path = kstr_dup(path);
			c->opts.arr[i].wch = wch;
			return 0;
		}

	ARR_INC(2, c->opts.arr, c->opts.cnt, rpc_wch_s);
	c->opts.arr[i].path = kstr_dup(path);
	c->opts.arr[i].wch = wch;

	return 0;
}
コード例 #2
0
ファイル: kim.c プロジェクト: kamasamikon/zuk
/*---------------------------------------------------------------------------------
 * Add watch
 */
static kbean addwch(KIM *im, const kchar *id, WCHPROC watch, kuchar type, kvoid *ua, kvoid *ub, const kchar *desc)
{
	KRtiWatch *wch = (KRtiWatch *) kmem_alloz(sizeof(KRtiWatch));

	ksyn_lck_get(im->lck);

	if (wch) {
		KRtiRec *rec = kim_chkrec(im, id);
		init_dlist_head(&wch->abwchentry);
		wch->wch = watch;
		wch->desc = desc ? kstr_dup(desc) : knil;
		wch->forid = kstr_dup(id);
		wch->ua = ua;
		wch->ub = ub;

		if (rec) {
			if (WT_LO == type)
				insert_dlist_tail_entry(&rec->awchhdr, &wch->abwchentry);
			else
				insert_dlist_tail_entry(&rec->bwchhdr, &wch->abwchentry);
		} else {
			/*
			 * some watch may be added before the im item added
			 * so, pending these watch till the im item add
			 */
			if (WT_LO == type)
				insert_dlist_tail_entry(&im->nywch.ahdr, &wch->abwchentry);
			else
				insert_dlist_tail_entry(&im->nywch.bhdr, &wch->abwchentry);
		}
	}

	ksyn_lck_rel(im->lck);

	return (kbean) wch;
}
コード例 #3
0
ファイル: kim.c プロジェクト: kamasamikon/zuk
/*---------------------------------------------------------------------------------
 * Add Value to RTI
 */
static KRtiRec *addrec(KIM *im, const kchar *id, kuchar type, kvoid *def, kint flg, ATPROC at, const kchar *desc)
{
	KRtiRec *rec;
	KRtiWatch *wch;
	K_dlist_entry *wchentry;

	ksyn_lck_get(im->lck);

	rec = kim_chkrec(im, id);
	if (rec)
		delrec(im, rec);

	rec = (KRtiRec *) kmem_alloz(sizeof(KRtiRec));
	if (rec) {
		rec->id = kstr_dup(id);
		rec->desc = desc ? kstr_dup(desc) : knil;
		rec->var.type = type;
		rec->flg = flg;
		rec->at = at;

		init_dlist_head(&rec->awchhdr);
		init_dlist_head(&rec->bwchhdr);
		init_dlist_head(&rec->entry);

		switch (type) {
		case RT_STR:
			if (def)
				rec->var.def.sv = kstr_dup((kchar *) def);
			break;
		case RT_PTR:
			rec->var.def.pv = (kvoid *) def;
			break;
		case RT_INT:
			rec->var.def.iv = (kint) def;
			break;
		default:
			delrec(im, rec);
			ksyn_lck_rel(im->lck);
			return knil;
		}

		/* XXX queue to im */
		insert_dlist_tail_entry(&im->rechdr, &rec->entry);

		/* XXX process the NY watches */
		wchentry = im->nywch.ahdr.next;
		while (wchentry != &im->nywch.ahdr) {
			wch = FIELD_TO_STRUCTURE(wchentry, KRtiWatch, abwchentry);
			wchentry = wchentry->next;
			if (0 == strcmp(wch->forid, id)) {
				remove_dlist_entry(&wch->abwchentry);
				insert_dlist_tail_entry(&rec->awchhdr, &wch->abwchentry);
			}
		}
		wchentry = im->nywch.bhdr.next;
		while (wchentry != &im->nywch.bhdr) {
			wch = FIELD_TO_STRUCTURE(wchentry, KRtiWatch, abwchentry);
			wchentry = wchentry->next;
			if (0 == strcmp(wch->forid, id)) {
				remove_dlist_entry(&wch->abwchentry);
				insert_dlist_tail_entry(&rec->bwchhdr, &wch->abwchentry);
			}
		}

		if (RF_AUTOSET & flg)
			setrec(im, rec, (kvoid *) def, knil, knil);
	}

	ksyn_lck_rel(im->lck);
	return rec;
}
コード例 #4
0
ファイル: kim.c プロジェクト: kamasamikon/zuk
/*---------------------------------------------------------------------------------
 * Set value
 */
static kint setrec(KIM *im, KRtiRec *rec, kvoid *val, kvoid **ua, kvoid **ub)
{
	K_dlist_entry *entry;
	KRtiWatch *watch;

	ksyn_lck_get(im->lck);

	/* for disable recorder skip */
	if (RF_DISABLE & rec->flg) {
		klog(("set disable recorder, ignored\n"));
		ksyn_lck_rel(im->lck);
		return 0;
	}

	rec->val = val;
	rec->ua = ua;
	rec->ub = ub;

	/* upper filter */
	entry = rec->bwchhdr.next;
	while (entry != &rec->bwchhdr) {
		watch = FIELD_TO_STRUCTURE(entry, KRtiWatch, abwchentry);
		if (watch->wch)
			watch->wch(im, rec, watch->ua, watch->ub, WT_UP);
		entry = entry->next;
	}

	if (rec->at) {
		rec->flg |= RF_PROCESS;
		rec->at(im, rec, ATRSN_SET);
		rec->flg &= ~RF_PROCESS;
	}

	switch (rec->var.type) {
	case RT_STR:
		kmem_free_s(rec->var.use.sv);
		if (val)
			rec->var.use.sv = kstr_dup((kchar *) val);
		else
			rec->var.use.sv = knil;
		break;
	case RT_PTR:
		rec->var.use.pv = (kvoid *) val;
		break;
	case RT_INT:
		rec->var.use.iv = (kint) val;
		break;
	default:
		break;
	}

	/* lower filter */
	entry = rec->awchhdr.next;
	while (entry != &rec->awchhdr) {
		watch = FIELD_TO_STRUCTURE(entry, KRtiWatch, abwchentry);
		if (watch->wch)
			watch->wch(im, rec, watch->ua, watch->ub, WT_LO);
		entry = entry->next;
	}

	ksyn_lck_rel(im->lck);
	return 0;
}