Exemplo n.º 1
0
PyObject* make_callback_dict(obj_list plugin_list){
	PyObject* dict = PyDict_New();
	int index = 0;

 
	while(index++ < obj_list_len(plugin_list)){
		PyObject* cur = obj_list_get(plugin_list, index);
		//Might need to add self reference to args, dunno
		PyObject* tuple = PyTuple_New((Py_ssize_t)0);
		if(!tuple){
			printf("Couldn't make tuple ?\n");
			PyErr_Print();
		}
		PyObject* getName = PyObject_GetAttrString(cur, "getName");
		if(!getName){
			printf("Couldn't get the getName method...\n");
			PyErr_Print();
		}
		PyObject* plugin_name = PyObject_Call(getName, tuple, NULL);
		if(!plugin_name){
			printf("Couldn't call the getName method...\n");
			PyErr_Print();
		}
		Py_DECREF(tuple);
		Py_DECREF(getName);
		PyObject* cur_plugin_write = PyObject_GetAttrString(cur, "addMessage");
		if(!cur_plugin_write){
			printf("Couldn't get addMessage method...\n");
			PyErr_Print();
		}
		if(!PyMethod_Check(cur_plugin_write) && !PyFunction_Check(cur_plugin_write)){
			printf("Not function or method...\n");
		}
		printf("Does it have the __call__ attribute %d\n", PyObject_HasAttrString(cur_plugin_write, "__call__"));
		PyDict_SetItem(dict, plugin_name, cur_plugin_write);
		Py_DECREF(plugin_name);
		Py_DECREF(cur_plugin_write);
	}
	return dict;
}
Exemplo n.º 2
0
//Returns an array of all the threads that are running....
thread_container* init_dds_python(Dict* config){
	Py_Initialize();
	if(dict_has_key(config, "plugins")){
		Dict* val = dict_get_val(config, "plugins");

		
		char* cur_plugin;
		char* plugins_list_str = val->value;
		obj_list plugin_list = new_object_list();

		cur_plugin = strtok(plugins_list_str, ",");
		while(cur_plugin){
			//import_plugin(cur_plugin);
			init_plugin(cur_plugin, plugin_list);
			cur_plugin = strtok(NULL, ",");
		}
		int index = 0;
		int len = obj_list_len(plugin_list);
		PyObject* cb_dict = make_callback_dict(plugin_list);
		for(;index < len;index++){
			give_callback_registration_oppertunity(obj_list_get(plugin_list, index), cb_dict);
		}
		thread_container* result = make_thread_container();
		PyObject* mt_tuple = PyTuple_New(0);
		for(index = 0; index < len;index++){
			PyObject* cur = obj_list_get(plugin_list, index);
			PyObject* needsThread = PyObject_GetAttrString(cur, "needsThread");
			if(!needsThread){
				printf("Couldn't get the needsThread method...\n");
				PyErr_Print();
			}
			PyObject* doesNeed = PyObject_Call(needsThread, mt_tuple, NULL);
			if(!doesNeed){
				printf("Couldn't call the needsThread method...\n");
				PyErr_Print();
			}
			if(PyObject_IsTrue(doesNeed)){
				PyObject* getName = PyObject_GetAttrString(cur, "getName");
				if(!getName){
					printf("Couldn't get the getName function...\n");
					PyErr_Print();
				}
				PyObject* nameStr = PyObject_Call(getName, mt_tuple, NULL);
				if(!nameStr){
					printf("Couldn't call the get name function...\n");
					PyErr_Print();
				}
				Py_DECREF(getName);
				plugin_thread* tmp_thread = make_plugin_thread(PyString_AS_STRING(nameStr));
				Py_DECREF(nameStr);
				PyObject* runMethod = PyObject_GetAttrString(cur, "run");
				if(!runMethod){
					printf("Couldn't get the run method...\n");
					PyErr_Print();
				}else{
					pthread_create(&tmp_thread->thread, NULL, run_plugin, (void*)runMethod);
				
				}
				thread_container_add(result, tmp_thread);
			}else{
				//TODO figure out what we want to happen here xD
			}
			Py_DECREF(doesNeed);
			Py_DECREF(needsThread);
		}
		Py_DECREF(mt_tuple);
		Py_DECREF(cb_dict);
		del_object_list(plugin_list);
		return result;
	}
}
Exemplo n.º 3
0
department*
employee_departments(employee* record,
					 int index) {
    return obj_list_get(record->departments, index);
}