void AIFilePicker::multiplex_impl(void)
{
	mPluginManager->update();										// Give the plugin some CPU for it's messages.
	LLPluginClassBasic* plugin = mPluginManager->getPlugin();
	if (!plugin || plugin->isPluginExited())
	{
		// This happens when there was a problem with the plugin (ie, it crashed).
		abort();
		return;
	}
	switch (mRunState)
	{
		case AIFilePicker_initialize_plugin:
		{
			if (!plugin->isPluginRunning())
			{
				break;												// Still initializing.
			}

			// Send initialization message.
			LLPluginMessage initialization_message(LLPLUGIN_MESSAGE_CLASS_BASIC, "initialization");
			static char const* key_str[] = {
				"all_files", "sound_files", "animation_files", "image_files", "save_file_verb",
				"targa_image_files", "bitmap_image_files", "avi_movie_file", "xaf_animation_file",
				"xml_file", "raw_file", "compressed_image_files", "load_file_verb", "load_files",
				"choose_the_directory"
			};
			LLSD dictionary;
			for (int key = 0; key < sizeof(key_str) / sizeof(key_str[0]); ++key)
			{
				dictionary[key_str[key]] = LLTrans::getString(key_str[key]);
			}
			initialization_message.setValueLLSD("dictionary", dictionary);
#if LL_WINDOWS || (LL_GTK && LL_X11)
			std::ostringstream window_id_str;
#if LL_WINDOWS
			unsigned long window_id = (unsigned long)gViewerWindow->getPlatformWindow();
#else
			unsigned long window_id = LLWindowSDL::get_SDL_XWindowID();
#endif
			if (window_id != 0)
			{
				window_id_str << std::hex << "0x" << window_id;
				initialization_message.setValue("window_id", window_id_str.str());
			}
			else
			{
				LL_WARNS("Plugin") << "Couldn't get xwid to use for transient." << LL_ENDL;
			}
#endif // LL_WINDOWS || (LL_GTK && LL_X11)
			plugin->sendMessage(initialization_message);

			// Send open message.
			LLPluginMessage open_message(LLPLUGIN_MESSAGE_CLASS_BASIC, "open");
			open_message.setValue("type", (mOpenType == save) ? "save" : (mOpenType == load) ? "load" : "load_multiple");
			open_message.setValue("filter", mFilter);
			if (mOpenType == save) open_message.setValue("default", mFilename);
			open_message.setValue("folder", mFolder);
			open_message.setValue("gorgon", "block");		// Don't expect HeartBeat messages after an "open".
			plugin->sendMessage(open_message);

			set_state(AIFilePicker_plugin_running);
			break;
		}
		case AIFilePicker_plugin_running:
		{
			// Users are slow, no need to look for new messages from the plugin all too often.
			yield_ms(250);
			break;
		}
		case AIFilePicker_canceled:
		{
			mCanceled = true;
			finish();
			break;
		}
		case AIFilePicker_done:
		{
			// Store folder of first filename as context.
			AIFilePicker::store_folder(mContext, getFolder());
			finish();
		}
	}
}
Exemple #2
0
int proc_loop(void)
{
	int rc = 0;

	log_debug("setting working directory ...\n");
	if ((mkdir(daemon_cfg.notify_dir, 0777) != 0) && (errno != EEXIST)) {
		rc = -errno;
		log_error("failed create folder %s (errno = %d)\n",
			  daemon_cfg.notify_dir, errno);
		goto err;
	}

	log_debug("setting store ...\n");
	rc = open_store();
	if (rc < 0) {
		goto err;
	}

	log_debug("setting flow ...\n");
	rc = open_flow();
	if (rc < 0) {
		goto err;
	}

	log_debug("setting notification ...\n");
	rc = open_notify();
	if (rc < 0) {
		goto err;
	}

	log_debug("setting message processing ...\n");
	rc = open_message();
	if (rc < 0) {
		goto err;
	}

	log_debug("starting loop ...\n");
	while ((0 == daemon_cfg.sig) && (errno != EINTR)) {
		fd_set readfds;
		struct timeval tv;
		int max_fd = -1;

		FD_ZERO(&readfds);
		FD_SET(daemon_cfg.sock_fd, &readfds);
		max_fd = daemon_cfg.sock_fd;
		FD_SET(daemon_cfg.notify_fd, &readfds);
		max_fd = (max_fd < daemon_cfg.notify_fd ? daemon_cfg.notify_fd : max_fd);

		/* Use timeout for select() call */
		tv.tv_sec = 60;
		tv.tv_usec = 0;

		rc = select(max_fd + 1, &readfds, NULL, NULL, &tv);
		if (rc < 0) {
			rc = 0;
			if (errno != EINTR) {
				rc = -errno;
				log_error("Failed select() errno %d (%s)\n", errno,
						strerror(errno));
			}
			goto err;
		} else if (rc == 0) {
			continue;
		}

		/* Check messages from processes */
		if (FD_ISSET(daemon_cfg.sock_fd, &readfds)) {
			log_debug("message processing ...\n");
			rc = proc_message();
		}

		/* Check any events from file system monitor */
		if (FD_ISSET(daemon_cfg.notify_fd, &readfds)) {
			log_debug("notification processing ...\n");
			rc = proc_notify();
		}
	}

err:
	log_debug("finishing loop ...\n");

	close_message();
	close_notify();
	close_flow();
	close_store();

	return rc;
}