示例#1
0
文件: kim.c 项目: kamasamikon/zuk
/*---------------------------------------------------------------------------------
 * Remove Value from RTI
 */
static kint delrec(KIM *im, KRtiRec *rec)
{
	KRtiWatch *wch;
	K_dlist_entry *wchentry;

	ksyn_lck_get(im->lck);

	remove_dlist_entry(&rec->entry);
	switch (rec->var.type) {
	case RT_STR:
		kmem_free_s(rec->var.use.sv);
		kmem_free_s(rec->var.def.sv);
		break;
	case RT_PTR:
	case RT_INT:
		break;
	default:
		kerror(("BAD RTIREC Type : %d for %s\n", rec->var.type, rec->id));
		break;
	}

	/* del watch list */
	wchentry = rec->awchhdr.next;
	while (wchentry != &rec->awchhdr) {
		wch = FIELD_TO_STRUCTURE(wchentry, KRtiWatch, abwchentry);
		wchentry = wchentry->next;

		remove_dlist_entry(&wch->abwchentry);
		insert_dlist_tail_entry(&im->nywch.ahdr, &wch->abwchentry);
	}
	wchentry = rec->bwchhdr.next;
	while (wchentry != &rec->bwchhdr) {
		wch = FIELD_TO_STRUCTURE(wchentry, KRtiWatch, abwchentry);
		wchentry = wchentry->next;

		remove_dlist_entry(&wch->abwchentry);
		insert_dlist_tail_entry(&im->nywch.bhdr, &wch->abwchentry);
	}

	kmem_free(rec->id);
	kmem_free_s(rec->desc);
	kmem_free(rec);

	ksyn_lck_rel(im->lck);
	return 0;
}
示例#2
0
int knode_final()
{
	if (!__g_knodecc)
		return 0;
	kmem_free_s(__g_knodecc->arr);
	kmem_free_sz(__g_knodecc);
	return 0;
}
示例#3
0
static int rpc_client_wch_clr(rpc_client_s *c)
{
	int i;

	for (i = 0; i < c->opts.cnt; i++) {
		kmem_free_s(c->opts.arr[i].path);
		if (c->opts.arr[i].wch)
			kopt_wch_del(c->opts.arr[i].wch);
		c->opts.arr[i].wch = NULL;
	}
	kmem_free_sz(c->opts.arr);
	c->opts.cnt = 0;

	return 0;
}
示例#4
0
文件: kim.c 项目: kamasamikon/zuk
/*---------------------------------------------------------------------------------
 * Del watch
 */
static kint delwch(KIM *im, kbean watch)
{
	KRtiWatch *wch = (KRtiWatch *) watch;
	kint ret = -1;

	ksyn_lck_get(im->lck);

	if (wch) {
		kmem_free(wch->forid);
		kmem_free_s(wch->desc);
		remove_dlist_entry(&wch->abwchentry);
		kmem_free(wch);
		ret = 0;
	}

	ksyn_lck_rel(im->lck);

	return ret;
}
示例#5
0
文件: kim.c 项目: kamasamikon/zuk
kint kim_del(KIM *im)
{
	KRtiRec *rec;
	KRtiWatch *wch;

	klog(("\n\n\n\nkim_del:%x\n", im));

	if (im) {
		ksyn_lck_get(im->lck);
		while (!is_dlist_empty(&im->nywch.ahdr)) {
			wch = FIELD_TO_STRUCTURE(im->nywch.ahdr.next, KRtiWatch, abwchentry);
			remove_dlist_entry(&wch->abwchentry);

			klog(("kim_del::nywach.ahdr: %s\n", wch->forid));

			kmem_free(wch->forid);
			kmem_free_s(wch->desc);
			kmem_free(wch);
		}
		while (!is_dlist_empty(&im->nywch.bhdr)) {
			wch = FIELD_TO_STRUCTURE(im->nywch.bhdr.next, KRtiWatch, abwchentry);
			remove_dlist_entry(&wch->abwchentry);

			klog(("kim_del::nywach.bhdr: %s\n", wch->forid));

			kmem_free(wch->forid);
			kmem_free_s(wch->desc);
			kmem_free(wch);
		}

		while (!is_dlist_empty(&im->rechdr)) {
			rec = FIELD_TO_STRUCTURE(im->rechdr.next, KRtiRec, entry);
			remove_dlist_entry(&rec->entry);

			klog(("kim_del::rechdr: %s\n", rec->id));

			while (!is_dlist_empty(&rec->bwchhdr)) {
				wch = FIELD_TO_STRUCTURE(rec->bwchhdr.next, KRtiWatch, abwchentry);
				remove_dlist_entry(&wch->abwchentry);

				klog(("kim_del::rechdr.bhdr: %s:%s\n", rec->id, wch->forid));

				kmem_free(wch->forid);
				kmem_free_s(wch->desc);
				kmem_free(wch);
			}
			while (!is_dlist_empty(&rec->awchhdr)) {
				wch = FIELD_TO_STRUCTURE(rec->awchhdr.next, KRtiWatch, abwchentry);
				remove_dlist_entry(&wch->abwchentry);

				klog(("kim_del::rechdr.ahdr: %s:%s\n", rec->id, wch->forid));

				kmem_free(wch->forid);
				kmem_free_s(wch->desc);
				kmem_free(wch);
			}

			kmem_free(rec->id);
			kmem_free_s(rec->desc);

			if (rec->var.type == RT_STR) {
				kmem_free_s(rec->var.use.sv);
				kmem_free_s(rec->var.def.sv);
			}

			kmem_free(rec);
		}
		ksyn_lck_rel(im->lck);

		assert(is_dlist_empty(&im->nywch.bhdr));
		assert(is_dlist_empty(&im->nywch.ahdr));

		ksyn_lck_del(im->lck);

		kmem_free(im);
		return 0;
	}
	return -1;
}
示例#6
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;
}
示例#7
0
/*-----------------------------------------------------------------------
 * Server
 */
static int do_opt_command(int s, char *buf, int cmdlen)
{
	rpc_client_s *c;
	char *para, ebuf[256], *errmsg;
	int ret, errnum;

	/* XXX: some client won't append NUL to end of input */
	buf[cmdlen] = '\0';
	kstr_trim(buf);
	wlogf(">> opt-rpc >>%s\n", buf);

	c = rpc_client_by_socket(s);
	if (!c) {
		kerror("no client found for socket %d\n", s);
		return 1;
	}

	if (!strncmp("wa ", buf, 3)) {
		para = buf + 3;
		if (-1 != rpc_client_wch_find(c, para))
			sprintf(buf, "%s%s", mk_errline(EC_EXIST, ebuf), c->prompt);
		else {
			void *wch = NULL;
			if ((c->wch_socket != -1))
				wch = kopt_awch_u(para, rpc_watch, (void *) c, NULL);
			else
				kerror("wchadd while on wfunc set in c side\n");
			if (!wch)
				sprintf(buf, "%s%s", mk_errline(EC_NG, ebuf), c->prompt);
			else {
				ret = rpc_client_wch_add(c, para, wch);
				sprintf(buf, "%s%s", mk_errline(ret, ebuf), c->prompt);
			}
		}
	} else if (!strncmp("wd ", buf, 3)) {
		para = buf + 3;
		ret = rpc_client_wch_del(c, para);
		sprintf(buf, "%s%s", mk_errline(ret, ebuf), c->prompt);
	} else if (!strncmp("os ", buf, 3)) {
		para = buf + 3;
		ret = kopt_setbat(para, 1);
		if (ret && !kopt_get_err(&errnum, &errmsg))
			sprintf(buf, "%x %s%s%s", errnum, errmsg, CRLF, c->prompt);
		else
			sprintf(buf, "%s%s", mk_errline(ret, ebuf), c->prompt);
		klog("optset: ret:%d, buf:%s\n", ret, buf);
	} else if (!strncmp("og ", buf, 3)) {
		para = buf + 3;
		char *iniret = NULL;
		ret = kopt_getini(para, &iniret);
		if (ret && !kopt_get_err(&errnum, &errmsg))
			sprintf(buf, "%x %s%s%s", errnum, errmsg, CRLF, c->prompt);
		else
			sprintf(buf, "%s%s%s", mk_errline(ret, ebuf), iniret ? iniret : "", c->prompt);
		kmem_free_s(iniret);
		klog("optget: ret:%d, buf:%s\n", ret, buf);
	} else if (!strncmp("bye", buf, 3)) {
		return 1;
	} else if (!strncmp("help", buf, 4)) {
		sprintf(buf, "help(), hey(mode<o|w>, client, connhash, user, pass), bye(), wa(opt), wd(opt), os(ini), og(opt)%s",
				c->prompt);
	} else {
		sprintf(buf, "%s%s", mk_errline(EC_NOTHING, ebuf), c->prompt);
	}

	ret = send(c->opt_socket, buf, strlen(buf) + 1, 0);
	if (ret < 0) {
		klog("send resp: s: %d, err %s\n", s, strerror(errno));
		return 1;
	} else if (ret == 0) {
		klog("send resp: Remote close socket: %d\n", s);
		return 1;
	}

	return 0;
}