TEST(mydict, dict) { dict_t* d = dict_create((void*)123); int k, v; dict_node_t* node = NULL; int i = 0; int sum = 0; for (i = 0; i < 10000; i++) { k = i, v = i; node = dict_add(d, &k, sizeof(k), &v, sizeof(v)); ASSERT_TRUE(node != NULL); sum += i; } for (i = 0; i < 10000; i++) { node = dict_find(d, &k, sizeof(k)); ASSERT_EQ((long)dict_get_val(node), i); } i = 0; for(node = dict_first(d); node; node = dict_next(d, node)) { i += (long)dict_get_val(node); } ASSERT_EQ(i, sum); for (i = 0; i < 10000; i++) { k = i; node = dict_delete(d, &k, sizeof(k)); ASSERT_EQ((long)dict_get_val(node), i); } ASSERT_TRUE(dict_empty(d)); dict_destroy(d); }
//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; } }