void ansisop_asignarValorCompartida(int socket_local,int pid_local){ int* tamanioNombreGV = recibirCpu(socket_local,sizeof(int),pid_local); int* valorAGrabar = recibirCpu(socket_local, sizeof(int),pid_local); char* nombreVariable = recibirCpu(socket_local,*tamanioNombreGV,pid_local); pthread_mutex_lock(&varsGlobals); free(dictionary_remove(reg_config.dic_variables,nombreVariable));//libero xq es un int* malloc lo q hay dictionary_put(reg_config.dic_variables,nombreVariable, valorAGrabar); pthread_mutex_unlock(&varsGlobals); free(tamanioNombreGV); free(nombreVariable); }
//******************************************************************************************************* void *administrar_cola_Reject (){ log_debug(log_procesador_Reject , "administrar_cola_Reject esta corriendo"); pcb_t* pcb_elegido; int pid_local = 0; t_sock_mje* datos_a_consola; while (1){ sem_wait(&sem_REJECT_dispo); // espero que haya un proceso en REJECT disponible log_debug(log_procesador_Reject, "Se empezo a procesar un PCB de REJECT"); // quito el proceso de la cola REJECT pthread_mutex_lock(&sem_l_Reject); pcb_elegido = list_remove(proc_Reject, 0);//Agarro el pcb pid_local = *(pcb_elegido->PID); pthread_mutex_unlock(&sem_l_Reject); if(*(pcb_elegido->SP) != -1){ notificarAUMCfpc(pid_local);//Si el pid es -1 significa q no se pudo cargar en memoria asi q no le notifico a la umc //ya q no lo tiene } log_debug(log_procesador_Reject, "Se removio el PCB de REJECT: %d", pid_local); // quito el proceso del Diccionario, obtengo Consola_Id y mensaje de respuesta pthread_mutex_lock(&sem_pid_consola); datos_a_consola = dictionary_get(dict_pid_consola,&pid_local); dictionary_remove(dict_pid_consola,&pid_local); pthread_mutex_unlock(&sem_pid_consola); log_debug(log_procesador_Reject, "Se removio el PID ( %d ) del dicc y se envio el mje a consola: %d", pid_local, datos_a_consola->socket_dest); log_debug(logger, "PCB con PID %d sacado de REJECT y se respondio a la consola %d",pid_local, datos_a_consola->socket_dest); //log_debug(logger, "Se envio a consola: %d el mensaje: %s", datos_a_consola->socket_dest, mje_Rej); if(datos_a_consola->proc_status == 0){ if(!strcmp(datos_a_consola->mensaje,"123456")){ int fin = -998; send(datos_a_consola->socket_dest,&fin,sizeof(int),0); }else{ int fin = -999; send(datos_a_consola->socket_dest,&fin,sizeof(int),0); } /*if (send(datos_a_consola->socket_dest, datos_a_consola->mensaje, MJE_RTA, 0) == -1){ log_debug(logger, "se intento enviar mensaje a consola: %d, pero el Send dio Error", datos_a_consola->socket_dest); log_debug(log_procesador_Reject, "se intento enviar mensaje a consola: %d, pero el Send dio Error", datos_a_consola->socket_dest); }*/ log_debug(log_procesador_Reject, "Envio correcto a consola: %d", datos_a_consola->socket_dest); liberarPcb(pcb_elegido); free(datos_a_consola); } } }
/******************************************************************************* * @author : Rohan Jyoti * @name : addToDir * @param : Dictionary to remove from, corresp. key, mChunk to remove * @return : void * @purpose : Remove mChunk to Dictionary ******************************************************************************/ void removeFromDir(dictionary_t *incomingD, char *key, mChunk_t *incomingChunk, queue_t *tKeys) { //if last element, remember to remove the queue and destroy the key from dict queue_t *tQ = (queue_t *)dictionary_get(incomingD, key); if(tQ == NULL) { //doesn't exist return; } else { unsigned int i; for(i=0; i<queue_size(tQ); i++) { mChunk_t *tempC = (mChunk_t *)queue_at(tQ, i); if(tempC->chunkID == incomingChunk->chunkID) if(tempC->chunkSize == incomingChunk->chunkSize) if(tempC->chunkType == incomingChunk->chunkType) if(tempC->data == incomingChunk->data) if(tempC->ip_addr == incomingChunk->ip_addr) if(tempC->port == incomingChunk->port) { queue_remove_at(tQ, i); dictionary_remove(incomingD, key); unsigned int j; for(j=0; j<queue_size(tKeys); j++) if(strcmp(key, (char *)queue_at(tKeys, j)) == 0) queue_remove_at(tKeys, j); break; } } } //next we free incomingChunk if(incomingChunk->data) free(incomingChunk->data); if(incomingChunk->ip_addr) free(incomingChunk->ip_addr); free(incomingChunk); }
//************************************************************************************** void *administrar_cola_Exit(){ log_debug(log_procesador_Exit, "administrar_cola_Exit esta corriendo"); t_sock_mje* datos_a_consola; pcb_t* pcb_elegido; int pid_local = 0; while (1){ sem_wait(&sem_EXIT_dispo); // espero que haya un proceso en EXIT disponible log_debug(log_procesador_Exit, "Se empezo a procesar un PCB de EXIT"); // quito el proceso de la cola EXIT pthread_mutex_lock(&sem_l_Exit); pcb_elegido = list_remove(proc_Exit, 0);//Agarro el pcb pid_local = *(pcb_elegido->PID); pthread_mutex_unlock(&sem_l_Exit); //Notifico umc notificarAUMCfpc(pid_local); log_debug(log_procesador_Exit, "Se removio el PCB de EXIT: %d", pid_local); // quito el proceso del Diccionario, obtengo Consola_Id y mensaje de respuesta pthread_mutex_lock(&sem_pid_consola); // datos_a_consola = dictionary_get(dict_pid_consola,&pid_local); datos_a_consola = dictionary_remove(dict_pid_consola,&pid_local); pthread_mutex_unlock(&sem_pid_consola); log_debug(log_procesador_Exit, "Se removio el PID ( %d ) del dicc y se envio el mje ( %s ) a consola: %d", pid_local, datos_a_consola->mensaje, datos_a_consola->socket_dest); log_debug(logger, "PCB con PID %d sacado de EXIT y se respondio a la consola %d",pid_local, datos_a_consola->socket_dest); log_debug(logger, "Se envio a consola: %d el mensaje: %s", datos_a_consola->socket_dest,datos_a_consola->mensaje); int fin = 999; send(datos_a_consola->socket_dest,&fin,sizeof(int),0); /*if (send(datos_a_consola->socket_dest, datos_a_consola->mensaje, MJE_RTA, 0) == -1){ log_debug(logger, "se intento enviar mensaje a consola: %d, pero el Send dio Error", datos_a_consola->socket_dest); log_debug(log_procesador_Exit, "se intento enviar mensaje a consola: %d, pero el Send dio Error", datos_a_consola->socket_dest); }*/ liberarPcb(pcb_elegido); free(datos_a_consola->mensaje); free(datos_a_consola); log_debug(log_procesador_Exit, "Envio correcto a consola: %d", datos_a_consola->socket_dest); } }
int main() { /* * Initialize the dictionary data structure. */ dictionary_t dictionary; dictionary_init(&dictionary); /* * Preform some basic actions */ int result; const char *s; /* _add() */ result = dictionary_add(&dictionary, "key", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key2", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key3", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } //dictionary_print(&dictionary); result = dictionary_add(&dictionary, "key", "value2"); if (result == 0) { printf("_add() was successful, and it should've failed.\n"); } else { printf("_add(): OKAY!\n"); } //dictionary_print(&dictionary); /* _remove() */ dictionary_remove(&dictionary, "key3"); /* _get() */ s = dictionary_get(&dictionary, "non-existant"); if (s != NULL) { printf("_get() was successful, and it should've failed.\n"); } else { printf("_get(): OKAY!\n"); } s = dictionary_get(&dictionary, "key"); if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); } else { printf("_get(): OKAY!\n"); } /* _parse() */ char *s1 = malloc(100); strcpy(s1, "key3: value"); result = dictionary_parse(&dictionary, s1); if (result != 0) { printf("_parse() failed, and it should have been successful.\n"); } else { printf("_parse(): OKAY!\n"); } //if(dictionary_remove(&dictionary, "key3")!=0) printf("unsuccesfull\n");//added char *s2 = malloc(100); strcpy(s2, "bad key-value"); result = dictionary_parse(&dictionary, s2); if (result == 0) { printf("_parse() was successful, and it should've failed.\n"); } else { printf("_parse(): OKAY!\n"); } /* _get() */ s = dictionary_get(&dictionary, "key3"); if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); } else { printf("_get(): OKAY!\n"); } /* * Free up the memory used by the dictionary and close the file. */ dictionary_destroy(&dictionary); free(s1); free(s2); return 0; }
//Setea el valor de una variable compartida void set_var_value(char* var_name, int value){ if(dictionary_has_key(vars_control_dictionary, var_name)){ dictionary_remove(vars_control_dictionary, var_name); dictionary_put(vars_control_dictionary, var_name, value); } }
int main(int argc, char *argv[]) { char *prgm = *argv; argv++; argc--; dictionary_t dictionary; if(argc < 1) { printf("Usage: %s [options]\n",prgm); printf("Use any combination of the following:\n"); printf(" -i: Initialize the dictionary\n"); printf(" -a [key] [value]: Add a key/value to the dictionary\n"); printf(" -p [string]: Parse a string into the dictionary\n"); printf(" -g [key]: Get a value by its key from the dictionary\n"); printf(" -r [key]: Remove a key from the dictionary\n"); printf(" -d: Destroy the dictionary\n"); } char *key, *value, *string; while(argc > 0) { if(strcmp(*argv,"-i") == 0) { //Initialize printf("Running init()\n"); dictionary_init(&dictionary); printf(" completed\n"); } else if(strcmp(*argv,"-a") == 0) { if(argc < 3) { printf("Not enough parameters to -a\n"); return 2; } key = mstrcpy(argv[1]); value = mstrcpy(argv[2]); printf("Running add(\"%s\",\"%s\")\n",argv[1],argv[2]); d_retint(dictionary_add(&dictionary, key, value)); d_compare("key",argv[1],key); d_compare("value",argv[2],value); argv += 2; argc -= 2; } else if(strcmp(*argv,"-p") == 0) { if(argc < 2) { printf("Not enough parameters to -p\n"); return 2; } string = mstrcpy(argv[1]); printf("Running parse(\"%s\")\n",argv[1]); d_retint(dictionary_parse(&dictionary, string)); d_compare("string",argv[1],string); argv += 1; argc -= 1; } else if(strcmp(*argv,"-g") == 0) { if(argc < 2) { printf("Not enough parameters to -g\n"); return 2; } key = mstrcpy(argv[1]); printf("Running get(\"%s\")\n",argv[1]); d_retstr(dictionary_get(&dictionary, key)); d_compare("key",argv[1],key); argv += 1; argc -= 1; } else if(strcmp(*argv,"-r") == 0) { if(argc < 2) { printf("Not enough parameters to -r\n"); return 2; } key = mstrcpy(argv[1]); printf("Running remove(\"%s\")\n",argv[1]); d_retint(dictionary_remove(&dictionary, key)); d_compare("remove",argv[1],key); argv += 1; argc -= 1; } else if(strcmp(*argv,"-d") == 0) { printf("Running destroy()\n"); dictionary_destroy(&dictionary); printf(" completed\n"); } else { printf("Did not understand parameter: %s\n",*argv); return 3; } argv++; argc--; } }
int main() { /* * Initialize the dictionary data structure. */ dictionary_t dictionary; dictionary_init(&dictionary); /* * Preform some basic actions */ int result; const char *s; /* _add() */ result = dictionary_add(&dictionary, "key", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key2", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key3", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key", "value2"); if (result == 0) { printf("_add() was successful, and it should've failed.\n"); } else { printf("_add(): OKAY!\n"); } /* _remove() */ dictionary_remove(&dictionary, "key3"); /* _get() */ s = dictionary_get(&dictionary, "non-existant"); if (s != NULL) { printf("_get() was successful, and it should've failed.\n"); } else { printf("_get(): OKAY!\n"); } s = dictionary_get(&dictionary, "key"); if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); } else { printf("_get(): OKAY!\n"); } /* _parse() */ char *s1 = malloc(100); strcpy(s1, "key3: value"); result = dictionary_parse(&dictionary, s1); if (result != 0) { printf("_parse() failed, and it should have been successful.\n"); } else { printf("_parse(): OKAY!\n"); } char *s2 = malloc(100); strcpy(s2, "bad key-value"); result = dictionary_parse(&dictionary, s2); if (result == 0) { printf("_parse() was successful, and it should've failed.\n"); } else { printf("_parse(): OKAY!\n"); } /* _get() */ s = dictionary_get(&dictionary, "key3"); if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); } else { printf("_get(): OKAY!\n"); } result = dictionary_parse(&dictionary, "hola, :senor"); if(result == 0) printf("Bad!\r\n"); else printf("Success\r\n"); strcpy(s1, "w00t: d00ddd"); result = dictionary_parse(&dictionary, s1); //char * z = "w00t: d00ddd"; s = dictionary_get(&dictionary, "w00t"); if(s == 0 || strcmp(s, "d00ddd") != 0) printf("Bad: %s\r\n", s); else printf("Success\r\n"); char * s3 = (char*)malloc(100); strcpy(s3, " : sdasda"); result = dictionary_parse(&dictionary, s3); s = dictionary_get(&dictionary, ""); if(s != 0) printf("Bad: %s\r\n", s); else printf("Success\r\n"); char* s4 = (char*)malloc(100); strcpy(s1, "ad: (&DAS^\\x"); if(dictionary_parse(&dictionary, s1) != 0) printf("Error\r\n"); s = dictionary_get(&dictionary, "ad"); strcpy(s1, "w00t1: test"); dictionary_parse(&dictionary, s1); strcpy(s4, "w00t1"); s = dictionary_get(&dictionary, s4); if(s == 0 || strcmp(s, "test") != 0) printf("Error3\r\n"); else printf("Success\r\n"); strcpy(s1, "w00t1: test2324334"); if((result = dictionary_parse(&dictionary, s1)) != KEY_EXISTS) printf("Error: %d\r\n", result); else printf("Success\r\n"); /**** BEGIN "Robust" Test Cases ****/ // Test 1 printf("\r\n\r\n=== BEGIN ROBUST ===\r\n\r\n"); char x[] = "Test Me: 57 ad9 X"; result = dictionary_parse(&dictionary, x); if(result != 0) printf("Error: Test 1, %d\r\n", result); else printf("Test 1 Passed!\r\n"); // Test 2 s = dictionary_get(&dictionary, "Test Me"); if(s != 0 && strcmp(s, "57 ad9 X") == 0) printf("Test 2 Passed!\r\n"); else printf("Error: Test2\r\n"); // Test 3 result = dictionary_add(&dictionary, "Test me", "test_value"); s = dictionary_get(&dictionary, "tESt mE"); if(result != KEY_EXISTS || strcmp(s, "57 ad9 X") != 0) printf("Error: Test 3, %d, %s\r\n", result, s); else printf("Test 3 Passed!\r\n"); // Test 4 char y[] = "TeSt Me: d00d another one <3"; result = dictionary_parse(&dictionary, y); if(result != KEY_EXISTS) printf("Error: Test 4\r\n"); else printf("Test 4 Passed!\r\n"); // Test 5 dictionary_remove(&dictionary, "TeSt ME"); s = dictionary_get(&dictionary, "test me"); if(s != 0) printf("Error: Test 5\r\n"); else printf("Test 5 Passed!\r\n"); /* * Free up the memory used by the dictionary and close the file. */ dictionary_destroy(&dictionary); free(s1); free(s2); free(s3); free(s4); return 0; }
int main() { /** * Set the start time */ clock_t start, end; double time_spent; start = clock(); /* * Initialize the dictionary data structure. */ dictionary_t dictionary; dictionary_init(&dictionary); int i=0; char** key_values = (char**)malloc(MAX_ENTRIES*sizeof(char*)); for(i=0; i<MAX_ENTRIES; i++){ key_values[i] = (char*)malloc(50*sizeof(char)); sprintf(key_values[i], "%d: %d", i, i); if(dictionary_parse(&dictionary, key_values[i])!=0) { printf("NOT_OK...THE ITEM SHOULD NOT ALREADY EXIST IN DICTIONARY\n"); return 1; } } for(i=0; i<MAX_ENTRIES; i++){ char tmp[30]; sprintf(tmp, "%d", i); if(strcmp(tmp, dictionary_get(&dictionary, tmp))!=0) { printf("NOT_OK...CANNOT GET EXISTING ITEM IN DICTIONARY\n"); return 1; } } for(i=0; i<MAX_ENTRIES; i++){ if(dictionary_parse(&dictionary, key_values[i])==0) { printf("NOT_OK...THE ITEM SHOULD ALREADY EXIST IN DICTIONARY\n"); return 1; } } for(i=0; i<MAX_ENTRIES; i++){ char tmp[30]; sprintf(tmp, "%d", i); if(dictionary_remove(&dictionary, tmp)!=0){ printf("NOT_OK...THE ITEM TO REMOVE SHOULD IN DICTIONARY\n"); return 1; } } /* * Free up the memory used by the dictionary and close the file. */ dictionary_destroy(&dictionary); for(i=0; i<MAX_ENTRIES; i++) free(key_values[i]); free(key_values); /** * Set the end time */ end = clock(); time_spent = (double)(end - start) / CLOCKS_PER_SEC; printf("The running time for your dictionary is: %f seconds\n", time_spent); return 0; }
int main() { /* * Initialize the dictionary data structure. */ dictionary_t dictionary; dictionary_init(&dictionary); /* * Preform some basic actions */ int result; const char *s; /* _add() */ result = dictionary_add(&dictionary, "key", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key2", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key3", "value"); if (result != 0) { printf("_add() failed, and it should have been successful.\n"); } else { printf("_add(): OKAY!\n"); } result = dictionary_add(&dictionary, "key", "value2"); if (result == 0) { printf("_add() was successful, and it should've failed.\n"); } else { printf("_add(): OKAY!\n"); } /* _remove() */ dictionary_remove(&dictionary, "key3"); /* _get() */ s = dictionary_get(&dictionary, "non-existant"); if (s != NULL) { printf("_get() was successful, and it should've failed.\n"); } else { printf("_get(): OKAY!\n"); } s = dictionary_get(&dictionary, "key"); if (s == NULL){printf("NULL");} if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); } else { printf("_get(): OKAY!\n"); } /* _parse() */ char *s1 = malloc(100); strcpy(s1, "key3: value"); result = dictionary_parse(&dictionary, s1); if (result != 0) { printf("_parse() failed, and it should have been successful.\n"); } else { printf("_parse(): OKAY!\n"); } char *s2 = malloc(100); strcpy(s2, "a:: b"); result = dictionary_parse(&dictionary, s2); if (result == 0) { printf("_parse() was successful, and it should've failed.\n"); } else { printf("_parse(): OKAY!\n"); } /*OWN TEST * - ": www.cs.uiuc.edu", since the KEY is zero-length * - "MyKey, MyValue", since no colon, space exists * - "a:b", since no colon, space exists. * - "a:: b", since the first colon isn't followed by a space. * - ": key: value" * - " : " * - " : " */ char *s3 = malloc(100); strcpy(s3, " : "); result = dictionary_parse(&dictionary, s3); printf("The result is %d\n",result); /* _get() */ s = dictionary_get(&dictionary, "key3"); /* if (s != NULL){printf("ITS NOT NULL");} if (s = NULL){printf("ITS NULL");} if (strcmp(s,"value") == 0){printf("Its 0");} if (strcmp(s,"value") != 0){printf("Its NOT 0");} */ if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); } else { printf("_get(): OKAY!\n"); } //printf("Im Here\n"); /* * Free up the memory used by the dictionary and close the file. */ dictionary_destroy(&dictionary); free(s1); free(s2); return 0; }