Exemple #1
0
static PyObject *
c_set_instance(PyObject *self, PyObject *args, PyObject *kwargs)
{
	struct pack *p;
	int ret;
	PyObject *key, *value;
	char *str;
	size_t strlen;
	int pos = 0;

	proc_check_shutdown();

	p = pack_new(512);
	if (!p) return NULL;

	while(PyDict_Next(kwargs, &pos, &key, &value)) {
		PyString_AsStringAndSize(key, &str, &strlen);
		pack_put(p, str, strlen);
		PyString_AsStringAndSize(value, &str, &strlen);
		pack_put(p, str, strlen);
	}

	ret = db_put_profile(bk_node, bk_app, p);
	if (ret != 0) return NULL;

	Py_INCREF(Py_None);
	return Py_None;
}
Exemple #2
0
static void
job_proc(void)
{
	struct ipc_struct ipc;
	struct pack *p;
	struct ProcChild *sender;
	char *t, *s;
	int cmd;
	size_t size;

	p = pack_new(256);
	while (1) {
		if (1 == proc_listen(&sender, &cmd, &size, 1)) break;
	}
	proc_get(sender, &ipc, p, size);

	bk_channel = ipc.source;

	switch (cmd) {
		case CMD_REGISTER:
			pack_get(p, &t, NULL);
			pack_get(p, &s, NULL);
			do_register(ipc.node, t, s);
			break;
		case CMD_REMOVE:
			pack_get(p, &t, NULL);
			do_remove(t);
			break;
		case CMD_CALL:
			do_call(ipc.node, p);
			break;
		case CMD_CALL_PACKAGE:
			pack_get(p, &t, NULL);
			do_call_package(ipc.node, t, p);
			break;
		case CMD_GETLIST:
			do_getlist(ipc.node);
			break;
		case CMD_DUMP_PROFILE:
			do_dump_profile();
			break;
		case CMD_EVENT:
			pack_get(p, &t, NULL);
			pack_get(p, &s, NULL);
			do_event(t, ipc.node, s, p);
			break;
	}
}
Exemple #3
0
static PyObject *
c_call(PyObject *self, PyObject *args)
{
	struct ipc_struct ipc;
	struct pack *p;
	char *node;
	char *pak;
	int nd;

	if (!PyArg_ParseTuple(args, "ss", &node, &pak))
		return NULL;

	nd = model_lookup_method(node);
	if (nd == -1) return NULL;

	memset(&ipc, 0, sizeof(struct ipc_struct));
	ipc.node = nd;
	p = pack_new(128);
	pack_put(p, pak, strlen(pak));

	job_start(CMD_CALL_PACKAGE, &ipc, p);

	while (1) {
		struct ProcChild *sender;
		int cmd;
		int size;

		if (1 == proc_listen(&sender, &cmd, &size, 1)) {
			switch (cmd) {
				case CMD_RESULT:
				case CMD_FAIL:
				case CMD_ERROR:
				case CMD_NONE:
					proc_get(sender, &ipc, p, size);
					break;
				case CMD_NOTIFY:
					proc_get(sender, &ipc, p, size);
					proc_put(TO_PARENT, cmd, &ipc, p);
					break;
			}
			if (cmd == CMD_FINISH) break;
		}
	}
	Py_INCREF(Py_None);
	return Py_None;
}
Exemple #4
0
static int
send_result(int cmd, const char *data, size_t size)
{
	struct ipc_struct ipc;
	struct pack *p;

	memset(&ipc, 0, sizeof(struct ipc_struct));
	ipc.source = bk_channel;
	p = pack_new(128);

	if (CMD_RESULT == cmd) {
		if (bk_app)
			pack_put(p, bk_app, strlen(bk_app));
		else
			pack_put(p, "comar", 5);
	}
	if (data) {
		if (size == 0) size = strlen(data);
		pack_put(p, data, size);
	}
	proc_put(TO_PARENT, cmd, &ipc, p);
	return 0;
}
Exemple #5
0
static int
do_call(int node, struct pack *pak)
{
	struct pack *p = NULL;
	char *apps;
	int ok = 0;

	log_debug(LOG_JOB, "Call(%s)\n", model_get_path(node));

	if (model_flags(node) & P_GLOBAL) {
		p = pack_dup(pak);
	}

	if (db_get_apps(model_parent(node), &apps) != 0) {
		send_result(CMD_NONE, "noapp", 5);
		// FIXME: ok diyecek betik yoksa profile kayıt etmeli mi acaba
		exit(1);
	}

	if (strchr(apps, '/') == NULL) {
		// there is only one script
		if (0 == do_execute(node, apps, pak))
			ok = 1;
	} else {
		// multiple scripts, run concurrently
		char *t, *s;
		struct ProcChild *p;
		int cmd;
		int cnt = 0;
		size_t size;

		// FIXME: package count
		send_result(CMD_RESULT_START, NULL, 0);
		for (t = apps; t; t = s) {
			s = strchr(t, '/');
			if (s) {
				*s = '\0';
				++s;
			}
			bk_node = node;
			bk_app = t;
			bk_pak = pak;
			p = proc_fork(exec_proc, "ComarSubJob");
			if (p) {
				++cnt;
			} else {
				send_result(CMD_ERROR, "fork failed", 11);
			}
		}
		while(1) {
			struct ipc_struct ipc;
			struct pack *pak;
			pak = pack_new(128);
			proc_listen(&p, &cmd, &size, -1);
			if (cmd == CMD_FINISH) {
				--cnt;
				if (!cnt) break;
			} else {
				if (cmd == CMD_RESULT) ok++;
				proc_get(p, &ipc, pak, size);
				proc_put(TO_PARENT, cmd, &ipc, pak);
			}
		}
		send_result(CMD_RESULT_END, NULL, 0);
	}

    if ((model_flags(node) & P_GLOBAL) && ok) {
		db_put_profile(node, NULL, p);
		pack_delete(p);
	}

	return 0;
}
Exemple #6
0
void CCmdProcess::GetIPByTS(unsigned int flow, Commpack *pPack)
{
    unsigned int nCmd = pPack->GetCmd();
    unsigned short nSeq = pPack->GetSeq();
    Commpack pack;
    pack.SetCmd(nCmd);
    pack.SetSeq(nSeq);

    unsigned uTSOld;
    if (!pPack->GetUInt(uTSOld))
    {
        pack.AddUInt(1000);
        SendToClient(flow, &pack);
        Warn("[GetIPByTS] error protocal, return 1000.");
        return;
    }

    time_t t1 = time(0);

    //1. get incremental change from memory by timestamp
    vector<SIPAttr> vecMod;
    vector < string > vecDel;
    unsigned uTSNew = uTSOld;

    pthread_rwlock_rdlock(&this->m_lock);

    map<string, SIPAttr>::iterator it;
    for(it = this->m_mapIPAttr.begin(); it != this->m_mapIPAttr.end(); it++)
    {
        SIPAttr &ia = it->second;

        if (ia.uModTS >= uTSOld)
        {
            if (0 == ia.uOptFlag)
            {
                vecMod.push_back(ia);
            }
            else
            {
                vecDel.push_back(ia.szIP);
            }
        }

        uTSNew = max(uTSNew, ia.uModTS);
    }

    pthread_rwlock_unlock(&this->m_lock);

    time_t t2 = time(0);

    Debug("select:%lus", t2-t1);

    //2. new a package, for enought size. compress data.
    Commpack pack_new(vecMod.size() * 8 + vecDel.size() * 4 + 512);
    pack_new.SetCmd(nCmd);
    pack_new.SetSeq(nSeq);

    pack_new.AddUInt(0);
    pack_new.AddUInt(uTSNew);

    pack_new.AddUInt(vecMod.size());
    for(size_t i = 0; i < vecMod.size(); i++)
    {
        SIPAttr &ia = vecMod[i];
        pack_new.AddUInt(inet_addr(ia.szIP));
        pack_new.AddUShort(ia.uCountry);
        pack_new.AddByte(ia.uIsp);
        pack_new.AddByte(ia.uProvince);
    }

    pack_new.AddUInt(vecDel.size());
    for(size_t j = 0; j < vecDel.size(); j++)
    {
        pack_new.AddUInt(inet_addr(vecDel[j].c_str()));
    }

    time_t t3 = time(0);
    Debug("add :%lus", t3-t2);

    SendToClient(flow, &pack_new);

    time_t t4 = time(0);
    Debug("send:%lus", t4-t3);
}
Exemple #7
0
bool gtkgui_init(int argc,char *argv[], Stream_mixer *mix)
{

	GtkWidget *bbox=NULL;
	bool isx=false;
	int i;
	
	/* initialization */
	state=true;
	mixer=mix;
	for(i=0; i<7; i++) {
/*		channum[i]=0;*/
		blockid[i]=0;
	}
	
	/*maxpos=0;*/
	list_init(&listachan);
	list_init(&lamelist);
	list_init(&ogglist);
	pathfile=NULL;
	
	/* signal to glib we're going to use threads */
	g_thread_init(NULL);

	isx=gtk_init_check(&argc,&argv);
	if(!isx) return false;	

	isx=mixer->set_lineout(true);

	window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window),"MuSE - Multiple Streaming Engine");
	gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE);
	gtk_container_set_border_width(GTK_CONTAINER(window),7);
	gtk_signal_connect(GTK_OBJECT(window),"delete_event",
					(GtkSignalFunc)gcb_exit,NULL);

	gtk_widget_realize(window);
//	load_knob_pixs(window);
	
	vbox=gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window),vbox);
	

	fix=gtk_fixed_new();
	//gtk_container_add(GTK_CONTAINER(vbox), fix);
	gtk_box_pack_start(GTK_BOX(vbox), fix, FALSE, FALSE, 0);
	
	bbox=createbbox(bbox);
	gtk_fixed_put(GTK_FIXED(fix), bbox, 0, 0);
	/*gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);*/ 
	if(isx)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(speakout), TRUE);
	
	
	pack_new();		
	
	/*firstchanfree(channum);*/
	createch();
	putstatusbar();
	
	/*let's show window */
	gtk_widget_show_all(window);
	gtk_widget_hide(pack1.hscale);
	gtk_widget_hide(pack2.hscale);
	gtk_widget_hide(pack3.hscale);

	return true;	
}
Exemple #8
0
bool gtkgui_init(int argc, char *argv[], Stream_mixer *mix)
{

	GtkWidget *bbox = NULL;
	bool isx = false;
	/* FIXME: bisogan mettere l'enable_nls*/
	/* i18n */
	setlocale(LC_ALL, "");
	bindtextdomain("muse", LOCALEDIR);
	bind_textdomain_codeset("muse", "UTF-8");
	textdomain("muse");
	
	/* initialization */
	state = true;
	mixer = mix;
	
	list_init(&listachan);
	list_init(&lamelist);
	list_init(&ogglist);
	iceprof = lameprof = vorbisprof = NULL;
	
	if(!profile_init())
		error(_("profile initialization error"));
	profile_ice_load();
	/* profile_lame_load and profile_vorbis_load are into encoder.cpp */

	pathfile = NULL;
	
	/* signal to glib we're going to use threads */
	g_thread_init(NULL);

	isx = gtk_init_check(&argc,&argv);
	if(!isx) 
		return false;	

	isx = mixer->set_lineout(true);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), _("MuSE-cvs Gtk+2"));
	gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
	gtk_container_set_border_width(GTK_CONTAINER(window), 12);
	g_signal_connect(G_OBJECT(window), "delete_event",
					G_CALLBACK(gcb_exit), NULL);

	/* FIXME: gtk2 remove ? */
	gtk_widget_realize(window);
	
	vbox=gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), vbox);
	

	fix = gtk_fixed_new();
	gtk_box_pack_start(GTK_BOX(vbox), fix, FALSE, FALSE, 0);
	
	bbox = createbbox(bbox);
	gtk_fixed_put(GTK_FIXED(fix), bbox, 0, 0);
	if(isx)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(speakout), TRUE);
	
	
	pack_new();		
	
	createch();
	putstatusbar();
	
	/*let's show window */
	gtk_widget_show_all(window);
	gtk_widget_hide(pack1.hscale);
	gtk_widget_hide(pack2.hscale);
	gtk_widget_hide(pack3.hscale);

	return true;	
}