int client_accept(int listenfd) { struct sockaddr_un addr; int cfd; socklen_t len = sizeof(struct sockaddr_un); cfd = accept(listenfd, (struct sockaddr *)&addr, &len); if (cfd < 0) { usbmuxd_log(LL_ERROR, "accept() failed (%s)", strerror(errno)); return cfd; } struct mux_client *client; client = malloc(sizeof(struct mux_client)); memset(client, 0, sizeof(struct mux_client)); client->fd = cfd; client->ob_buf = malloc(REPLY_BUF_SIZE); client->ob_size = 0; client->ob_capacity = REPLY_BUF_SIZE; client->ib_buf = malloc(CMD_BUF_SIZE); client->ib_size = 0; client->ib_capacity = CMD_BUF_SIZE; client->state = CLIENT_COMMAND; client->events = POLLIN; pthread_mutex_lock(&client_list_mutex); collection_add(&client_list, client); pthread_mutex_unlock(&client_list_mutex); usbmuxd_log(LL_INFO, "New client on fd %d", client->fd); return client->fd; }
gboolean collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci, gboolean sorted) { struct stat st; if (!insert_ci) return collection_add(cd, fd, sorted); if (stat_utf8(fd->path, &st) >= 0 && !S_ISDIR(st.st_mode)) { CollectInfo *ci; ci = collection_info_new_if_not_exists(cd, &st, fd); if (!ci) return FALSE; DEBUG_3("insert in collection: %s", fd->path); cd->list = collection_list_insert(cd->list, ci, insert_ci, sorted ? cd->sort_method : SORT_NONE); cd->changed = TRUE; collection_window_insert(collection_window_find(cd), ci); return TRUE; } return FALSE; }
int cprocessor_command_register(struct cprocessor_command *command_ptr) { // collection_add(co_collection, command_ptr); // return 0; }
int cprocessor_open() { // co_collection = collection_new(); // cprocessor_signal_exit = 0; // Přidání příkazu pro exit.. cprocessor_command_exit = cprocessor_command_new(COMMAND_EXIT_NAZEV, COMMAND_EXIT_KATEGORIE, &cprocessor_command_exit_function); cprocessor_command_show_commands = cprocessor_command_new(COMMAND_SHOW_COMMANDS_NAZEV, COMMAND_SHOW_COMMANDS_KATEGORIE, &cprocessor_command_show_commands_function); // collection_add(co_collection, cprocessor_command_exit); collection_add(co_collection, cprocessor_command_show_commands); // return 0; }
/** * Wait for an inbound connection on the usbmuxd socket * and create a new mux_client instance for it, and store * the client in the client list. * * @param listenfd the socket fd to accept() on. * @return The connection fd for the client, or < 0 for error * in which case errno will be set. */ int client_accept(int listenfd) { struct sockaddr_un addr; int cfd; socklen_t len = sizeof(struct sockaddr_un); cfd = accept(listenfd, (struct sockaddr *)&addr, &len); if (cfd < 0) { usbmuxd_log(LL_ERROR, "accept() failed (%s)", strerror(errno)); return cfd; } int flags = fcntl(cfd, F_GETFL, 0); if (flags < 0) { usbmuxd_log(LL_ERROR, "ERROR: Could not get socket flags!"); } else { if (fcntl(cfd, F_SETFL, flags | O_NONBLOCK) < 0) { usbmuxd_log(LL_ERROR, "ERROR: Could not set socket to non-blocking mode"); } } struct mux_client *client; client = malloc(sizeof(struct mux_client)); memset(client, 0, sizeof(struct mux_client)); client->fd = cfd; client->ob_buf = malloc(REPLY_BUF_SIZE); client->ob_size = 0; client->ob_capacity = REPLY_BUF_SIZE; client->ib_buf = malloc(CMD_BUF_SIZE); client->ib_size = 0; client->ib_capacity = CMD_BUF_SIZE; client->state = CLIENT_COMMAND; client->events = POLLIN; pthread_mutex_lock(&client_list_mutex); collection_add(&client_list, client); pthread_mutex_unlock(&client_list_mutex); #ifdef SO_PEERCRED if (log_level >= LL_INFO) { struct ucred cr; len = sizeof(struct ucred); getsockopt(cfd, SOL_SOCKET, SO_PEERCRED, &cr, &len); if (getpid() == cr.pid) { usbmuxd_log(LL_INFO, "New client on fd %d (self)", client->fd); } else { usbmuxd_log(LL_INFO, "New client on fd %d (pid %d)", client->fd, cr.pid); } } #else usbmuxd_log(LL_INFO, "New client on fd %d", client->fd); #endif return client->fd; }
int test_collection_04() { // struct collection *col = NULL; // Pokud to proběhne bez toho aniž by spadlo na neoprávněný přístup do paměti, je to OK (snad).. col = collection_new(); // collection_add(col, NULL); collection_add(col, NULL); collection_add(col, NULL); collection_add(col, NULL); collection_add(col, NULL); collection_add(col, NULL); collection_add(col, NULL); collection_add(col, NULL); // Zde budu testovat hodnoty položky kolekce.. struct collection_item *item = col -> first_item; while(item) { // void *object = NULL; // if(item -> object) { object = item -> object; } // if(object != NULL) { ctest_assert_null(object, "Hodnota položky object v kolekci je neplatná měla by být NULL.."); break; } // item = item -> next; } // collection_delete(col); // char *assert_message = "Testing collection for new/several add(null)/delete.."; ctest_assert_pass(assert_message); // return 0; }
int test_collection_03() { // struct collection *col = NULL; // Pokud to proběhne bez toho aniž by spadlo na neoprávněný přístup do paměti, je to OK (snad).. col = collection_new(); collection_add(col, NULL); collection_delete(col); // char *assert_message = "Testing collection for new/add(null)/delete.."; ctest_assert_pass(assert_message); // return 0; }
void collect_manager_add(const gchar *path, const gchar *collection) { CollectManagerAction *action; CollectWindow *cw; if (!path || !collection) return; cw = collection_window_find_by_path(collection); if (cw) { if (collection_list_find(cw->cd->list, path) == NULL) { collection_add(cw->cd, path, FALSE); } return; } action = collect_manager_action_new(path, collection, COLLECTION_MANAGER_ADD); collect_manager_add_action(action); }
int test_collection_05() { // struct collection *col = NULL; // int my_number = 1234; int *my_object = &my_number; // Pokud to proběhne bez toho aniž by spadlo na neoprávněný přístup do paměti, je to OK (snad).. col = collection_new(); // collection_add(col, my_object); collection_add(col, my_object); collection_add(col, my_object); collection_add(col, my_object); // struct collection_item *item = col -> first_item; // while(item) { // void *object = NULL; // object = item -> object; // if(object == NULL) { ctest_assert_fail("Object has to by valid object to pass this test!"); break; } // if(object != my_object) { ctest_assert_fail("Object address is not the expected one!"); break; } // int value = *(int *) object; if(value != my_number) { ctest_assert_fail("Object value is not the excepted one!"); break; } // item = item -> next; } // collection_delete(col); // char *assert_message = "Testing collection for new/several add(null)/delete.."; ctest_assert_pass(assert_message); // return 0; }
/** * Add a collection to a collection ListBase and synchronize all render layers * The ListBase is NULL when the collection is to be added to the master collection */ Collection *BKE_collection_add(Main *bmain, Collection *collection_parent, const char *name_custom) { Collection *collection = collection_add(bmain, collection_parent, name_custom); BKE_main_collection_sync(bmain); return collection; }