void XBMCHelper::Start() { int pid = GetProcessPid(XBMC_HELPER_PROGRAM); // try multiple times in case startup failed for some reason int retries = 5; while(pid == -1 && retries-- > 0) { //printf("Asking helper to start.\n"); // use -x to have XBMCHelper read its configure file std::string cmd = "\"" + m_helperFile + "\" -x &"; system(cmd.c_str()); usleep(500); pid = GetProcessPid(XBMC_HELPER_PROGRAM); } }
void XBMCHelper::Start() { int pid = GetProcessPid(XBMC_HELPER_PROGRAM); if (pid == -1) { printf("Asking helper to start.\n"); // use -x to have XBMCHelper read its configure file std::string cmd = "\"" + m_helperFile + "\" -x &"; system(cmd.c_str()); } }
void XBMCHelper::Stop() { // Kill the process. int pid = GetProcessPid(XBMC_HELPER_PROGRAM); if (pid != -1) { printf("Asked to stop\n"); kill(pid, SIGKILL); } }
void XBMCHelper::Stop() { // Kill the process. int pid = GetProcessPid(XBMC_HELPER_PROGRAM); if (pid != -1) { CLog::Log(LOGDEBUG,"XBMCHelper: Sending SIGKILL to %s\n", XBMC_HELPER_PROGRAM); kill(pid, SIGKILL); } }
void XBMCHelper::Install() { // Make sure directory exists. std::string strDir = getenv("HOME"); strDir += "/Library/LaunchAgents"; CURL url = CURL(strDir); XFILE::CDirectory::Create(url); // Load template. std::string plistData = ReadFile(m_launchAgentLocalFile.c_str()); if (plistData != "") { std::string launchd_args; // Replace PATH with path to app. int start = plistData.find("${PATH}"); plistData.replace(start, 7, m_helperFile.c_str(), m_helperFile.length()); // Replace ARG1 with a single argument, additional args // will need ARG2, ARG3 added to plist. launchd_args = "-x"; start = plistData.find("${ARG1}"); plistData.replace(start, 7, launchd_args.c_str(), launchd_args.length()); // Install it. WriteFile(m_launchAgentInstallFile.c_str(), plistData); // Load it if not running already. int pid = GetProcessPid(XBMC_HELPER_PROGRAM); if (pid == -1) { std::string cmd = "/bin/launchctl load "; cmd += m_launchAgentInstallFile; system(cmd.c_str()); } } }
bool XBMCHelper::IsSofaControlRunning() { return false; // Check for a "Sofa Control" process running. return GetProcessPid(SOFA_CONTROL_PROGRAM) != -1; }
bool XBMCHelper::IsRunning() { return (GetProcessPid(XBMC_HELPER_PROGRAM)!=-1); }
void XBMCHelper::Configure() { int oldMode = m_mode; int oldDelay = m_sequenceDelay; int oldAlwaysOn = m_alwaysOn; int oldPort = m_port; // Read the new configuration. m_errorStarting = false; m_mode = g_guiSettings.GetInt("input.appleremotemode"); m_sequenceDelay = g_guiSettings.GetInt("input.appleremotesequencetime"); m_alwaysOn = g_guiSettings.GetBool("input.appleremotealwayson"); CStdString port_string = g_guiSettings.GetString("services.esport"); m_port = atoi(port_string.c_str()); // Don't let it enable if sofa control or remote buddy is around. if (IsRemoteBuddyInstalled() || IsSofaControlRunning()) { // If we were starting then remember error. if (oldMode == APPLE_REMOTE_DISABLED && m_mode != APPLE_REMOTE_DISABLED) m_errorStarting = true; m_mode = APPLE_REMOTE_DISABLED; g_guiSettings.SetInt("input.appleremotemode", APPLE_REMOTE_DISABLED); } // New configuration. if (oldMode != m_mode || oldDelay != m_sequenceDelay || oldPort != m_port) { // Build a new config string. std::string strConfig; switch (m_mode) { case APPLE_REMOTE_UNIVERSAL: strConfig = "--universal "; break; case APPLE_REMOTE_MULTIREMOTE: strConfig = "--multiremote "; break; default: break; } std::stringstream strPort; strPort << "--port " << m_port; strConfig += strPort.str(); #ifdef _DEBUG strConfig += "--verbose "; #endif char strDelay[64]; sprintf(strDelay, "--timeout %d ", m_sequenceDelay); strConfig += strDelay; // Find out where we're running from. char real_path[2*MAXPATHLEN]; char given_path[2*MAXPATHLEN]; uint32_t path_size = 2*MAXPATHLEN; if (_NSGetExecutablePath(given_path, &path_size) == 0) { if (realpath(given_path, real_path) != NULL) { strConfig += "--appPath \""; strConfig += real_path; strConfig += "\" "; strConfig += "--appHome \""; strConfig += m_homepath; strConfig += "\" "; } } // Write the new configuration. strConfig + "\n"; WriteFile(m_configFile.c_str(), strConfig); // If process is running, kill -HUP to have it reload settings. int pid = GetProcessPid(XBMC_HELPER_PROGRAM); if (pid != -1) kill(pid, SIGHUP); } // Turning off? if (oldMode != APPLE_REMOTE_DISABLED && m_mode == APPLE_REMOTE_DISABLED) { Stop(); Uninstall(); } // Turning on. if (oldMode == APPLE_REMOTE_DISABLED && m_mode != APPLE_REMOTE_DISABLED) Start(); // Installation/uninstallation. if (oldAlwaysOn == false && m_alwaysOn == true) Install(); if (oldAlwaysOn == true && m_alwaysOn == false) Uninstall(); }
void XBMCHelper::Configure() { int oldMode = m_mode; int oldDelay = m_sequenceDelay; int oldPort = m_port; // Read the new configuration. m_errorStarting = false; m_mode = CSettings::GetInstance().GetInt(CSettings::SETTING_INPUT_APPLEREMOTEMODE); m_sequenceDelay = CSettings::GetInstance().GetInt(CSettings::SETTING_INPUT_APPLEREMOTESEQUENCETIME); m_port = CSettings::GetInstance().GetInt(CSettings::SETTING_SERVICES_ESPORT); // Don't let it enable if sofa control or remote buddy is around. if (IsRemoteBuddyInstalled() || IsSofaControlRunning()) { // If we were starting then remember error. if (oldMode == APPLE_REMOTE_DISABLED && m_mode != APPLE_REMOTE_DISABLED) m_errorStarting = true; m_mode = APPLE_REMOTE_DISABLED; CSettings::GetInstance().SetInt(CSettings::SETTING_INPUT_APPLEREMOTEMODE, APPLE_REMOTE_DISABLED); } // New configuration. if (oldMode != m_mode || oldDelay != m_sequenceDelay || oldPort != m_port) { // Build a new config string. std::string strConfig; switch (m_mode) { case APPLE_REMOTE_UNIVERSAL: strConfig = "--universal "; break; case APPLE_REMOTE_MULTIREMOTE: strConfig = "--multiremote "; break; default: break; } std::stringstream strPort; strPort << "--port " << m_port; strConfig += strPort.str(); #ifdef _DEBUG strConfig += "--verbose "; #endif char strDelay[64]; sprintf(strDelay, "--timeout %d ", m_sequenceDelay); strConfig += strDelay; // Find out where we're running from. char real_path[2*MAXPATHLEN]; char given_path[2*MAXPATHLEN]; uint32_t path_size = 2*MAXPATHLEN; if (_NSGetExecutablePath(given_path, &path_size) == 0) { if (realpath(given_path, real_path) != NULL) { strConfig += "--appPath \""; strConfig += real_path; strConfig += "\" "; strConfig += "--appHome \""; strConfig += m_homepath; strConfig += "\" "; } } // Write the new configuration. strConfig + "\n"; WriteFile(m_configFile.c_str(), strConfig); // If process is running, kill -HUP to have it reload settings. int pid = GetProcessPid(XBMC_HELPER_PROGRAM); if (pid != -1) kill(pid, SIGHUP); } // Turning off? if (oldMode != APPLE_REMOTE_DISABLED && m_mode == APPLE_REMOTE_DISABLED) { Stop(); Uninstall(); } // Turning on. if (oldMode == APPLE_REMOTE_DISABLED && m_mode != APPLE_REMOTE_DISABLED) Start(); HandleLaunchAgent(); }
bool PlexRemoteHelper::IsSofaControlRunning() { // Check for a "Sofa Control" process running. return GetProcessPid(SOFA_CONTROL_PROGRAM) != -1; }