int twmtp_MtpServer::mtppipe_thread(void)
{
	if (mtp_read_pipe == -1) {
		MTPD("mtppipe_thread exiting because mtp_read_pipe not set\n");
		return 0;
	}
	MTPD("Starting twmtp_MtpServer::mtppipe_thread\n");
	int read_count;
	struct mtpmsg mtp_message;
	while (1) {
		read_count = ::read(mtp_read_pipe, &mtp_message, sizeof(mtp_message));
		MTPD("read %i from mtppipe\n", read_count);
		if (read_count == sizeof(mtp_message)) {
			if (mtp_message.message_type == MTP_MESSAGE_ADD_STORAGE) {
				MTPI("mtppipe add storage %i '%s'\n", mtp_message.storage_id, mtp_message.path);
				if (mtp_message.storage_id) {
					long reserveSpace = 1;
					bool removable = false;
					MtpStorage* storage = new MtpStorage(mtp_message.storage_id, mtp_message.path, mtp_message.display, reserveSpace, removable, mtp_message.maxFileSize, refserver);
					server->addStorage(storage);
					MTPD("mtppipe done adding storage\n");
				} else {
					MTPE("Invalid storage ID %i specified\n", mtp_message.storage_id);
				}
			} else if (mtp_message.message_type == MTP_MESSAGE_REMOVE_STORAGE) {
				MTPI("mtppipe remove storage %i\n", mtp_message.storage_id);
				remove_storage(mtp_message.storage_id);
				MTPD("mtppipe done removing storage\n");
			} else {
				MTPE("Unknown mtppipe message value: %i\n", mtp_message.message_type);
			}
		} else {
			MTPE("twmtp_MtpServer::mtppipe_thread unexpected read_count %i\n", read_count);
			close(mtp_read_pipe);
			break;
		}
	}
	MTPD("twmtp_MtpServer::mtppipe_thread closing\n");
	return 0;
}
示例#2
0
void menu_warehouse(warehouse *warehouses)
{
	boolean loop = TRUE;
	int option;

	while(loop)
	{
		show_menu(5);
		int_input(&option, 3);

		switch(option)
		{
			case 1:
				{
					insert_hallway(warehouses);
					insert_storage(&warehouses->hallways[warehouses->hallways_size - 1]);
					printf("Corredor adicionado.\n\n");
					break;
				}
			case 2:
				{
					if(warehouses->hallways_size > 0)
					{
						int hallway_number = choose_hallway(warehouses);
						if (hallway_number >= 0)
						{
							insert_storage(&warehouses->hallways[hallway_number]);
							printf("Armario adicionado.\n\n");
						}
					}
					else
					{
						printf("Nao existem corredores.\n\n");
					}
					break;
				}
				case 3:
				{
					int hallway_number = choose_hallway(warehouses);

					if (hallway_number >= 0)
					{
						if(warehouses->hallways_size > 1)
						{
							remove_hallway(warehouses, hallway_number, TRUE);
							printf("Corredor removido.\n\n");
						}
						else
						{
							printf("Nao e possivel remover o ultimo corredor.\n\n");
						}
					}
					break;
				}
				case 4:
				{
					int hallway_number = choose_hallway(warehouses);
					int storage_number = choose_storage(warehouses, &hallway_number);

					if ((hallway_number >= 0) && (storage_number >= 0))
					{
						if(warehouses->hallways[hallway_number].storages_size > 1)
						{
							remove_storage(warehouses, hallway_number, storage_number, TRUE);
							printf("Armario removido.\n\n");
						}
						else
						{
							printf("Nao e possivel remover o ultimo corredor.\n\n");
						}
					}
					break;
				}
			case 9:
				{
					loop = FALSE;
					break;
				}
			default:
				{
					printf("Essa opcao nao existe.\n\n");
					break;
				}
		}
	}
}
void default_garbage_collector::commit_object(object &constructed)
{
    object_handle handle(remove_storage(
                             reinterpret_cast<char *>(&constructed)));
    m_objects.push_back(std::move(handle));
}