Exemple #1
0
/*==========================================================================*
 *  Function: Run
 *
 *  Purpose:
 *
 *  handles the original RXAPI functions.
 *    Perform the message loop
 *
 *
 *==========================================================================*/
void Run (bool asService)
{
    try
    {
        apiServer.initServer();               // start up the server
        apiServer.listenForConnections();     // go into the message loop
    }
    catch (ServiceException *)
    {
    }
    apiServer.terminateServer();     // shut everything down
}
Exemple #2
0
/**
 * Handle a server stop request
 *
 * @param signo The signal number (not used)
 */
void Stop(int signo)
{
    apiServer.terminateServer();     // shut everything down

    exit(1);
}
Exemple #3
0
/**
 * The rxapi main entry point.
 *
 * @param argc   The command line arguments
 * @param argv   The arguments
 *
 * @return The completion return code.
 */
int main(int argc, char *argv[])
{
    if (argc > 1)
    {
        printf("rxapi: no args allowed\n");
    }

    // a buffer for generating the name
    char lockFileName[PATH_MAX + 100];

    // the location of the lock file
    char pipePath[PATH_MAX];
    // determine the best place to put this
    SysServerLocalSocketConnectionManager::getServiceLocation(pipePath, sizeof(pipePath));
    snprintf(lockFileName, sizeof(lockFileName), "%s.lock", pipePath);
    printf("rxapi: lockfile path is %s\n", lockFileName);

    // see if we can get the lock file before proceeding. This is one
    // file per user.
    int fd;
    if ((fd = acquireLock(lockFileName)) == -1)
    {
        printf("rxapi: lockfile is locked by another rxapi instance; exiting\n");
        return EACCES;
    }
    printf("rxapi: lockfile lock acquired\n");

    struct sigaction sa;

    // handle kill -15
    (void) sigemptyset(&sa.sa_mask);
    (void) sigaddset(&sa.sa_mask, SIGTERM);
    sa.sa_flags = SA_RESTART;
    sa.sa_handler = Stop;
    if (sigaction(SIGTERM, &sa, NULL) == -1)
    {
        printf("rxapi: sigaction(SIGTERM) failed; exiting\n");
        exit(1);
    }

    // turn off SIGPIPE signals in case the other end of the
    // pipe terminates on us.
    signal(SIGPIPE, SIG_IGN);

    try
    {
        // create a connection object that will be the server target
        SysServerLocalSocketConnectionManager *c = new SysServerLocalSocketConnectionManager();
        // try to create the named pipe used for this server. If this fails, we
        // likely have an instance of the daemon already running, so just fail quietly.
        const char *service = SysServerLocalSocketConnectionManager::generateServiceName();
        printf("rxapi: service path is %s\n", service);
        if (!c->bind(service))
        {
            printf("rxapi: service is locked by another rxapi instance; exiting\n");
            delete c;
            return EACCES;
        }
        apiServer.initServer(c);              // start up the server
        printf("rxapi: service successfully started; listening\n");
        apiServer.listenForConnections();     // go into the message loop
    }
    catch (ServiceException *e)
    {
        delete e;  // just ignore errors
    }
    apiServer.terminateServer();     // shut everything down
    releaseLock(lockFileName, fd);   // release the exclusive lock
    printf("rxapi: service stopped and lockfile released; exiting\n");

    return 0;
}
Exemple #4
0
void MainLoop(void)
{
	int            commandSock = 0;
	int            controlSock = 0;
	int            bridgeSock = 0;
	int            prevFPPstatus = FPPstatus;
	int            sleepms = 50000;
	fd_set         active_fd_set;
	fd_set         read_fd_set;
	struct timeval timeout;
	int            selectResult;

	LogDebug(VB_GENERAL, "MainLoop()\n");

	FD_ZERO (&active_fd_set);

	CheckExistanceOfDirectoriesAndFiles();

	piFaceSetup(200); // PiFace inputs 1-8 == wiringPi 200-207

	if (getFPPmode() == BRIDGE_MODE)
	{
		bridgeSock = Bridge_Initialize();
		if (bridgeSock)
			FD_SET (bridgeSock, &active_fd_set);
	}
	else
	{
		InitMediaOutput();
	}

	pluginCallbackManager.init();

	InitializeChannelOutputs();
	sequence->SendBlankingData();

	InitEffects();
	InitializeChannelDataMemoryMap();

	commandSock = Command_Initialize();
	if (commandSock)
		FD_SET (commandSock, &active_fd_set);

#ifdef USEHTTPAPI
	APIServer apiServer;
	apiServer.Init();
#endif

	controlSock = InitControlSocket();
	FD_SET (controlSock, &active_fd_set);

	SetupGPIOInput();

	if (getFPPmode() & PLAYER_MODE)
	{
		if (getFPPmode() == MASTER_MODE)
			InitSyncMaster();

		scheduler->CheckIfShouldBePlayingNow();

		if (getAlwaysTransmit())
			StartChannelOutputThread();
	}

	LogInfo(VB_GENERAL, "Starting main processing loop\n");

	while (runMainFPPDLoop)
	{
		timeout.tv_sec  = 0;
		timeout.tv_usec = sleepms;

		read_fd_set = active_fd_set;


		selectResult = select(FD_SETSIZE, &read_fd_set, NULL, NULL, &timeout);
		if (selectResult < 0)
		{
			if (errno == EINTR)
			{
				// We get interrupted when media players finish
				continue;
			}
			else
			{
				LogErr(VB_GENERAL, "Main select() failed: %s\n",
					strerror(errno));
				runMainFPPDLoop = 0;
				continue;
			}
		}

		if (commandSock && FD_ISSET(commandSock, &read_fd_set))
			CommandProc();

		if (bridgeSock && FD_ISSET(bridgeSock, &read_fd_set))
			Bridge_ReceiveData();

		if (controlSock && FD_ISSET(controlSock, &read_fd_set))
			ProcessControlPacket();

		// Check to see if we need to start up the output thread.
		// FIXME, possibly trigger this via a fpp command to fppd
		if ((!ChannelOutputThreadIsRunning()) &&
			(getFPPmode() != BRIDGE_MODE) &&
			((UsingMemoryMapInput()) ||
			 (channelTester->Testing()) ||
			 (getAlwaysTransmit()))) {
			int E131BridgingInterval = getSettingInt("E131BridgingInterval");
			if (!E131BridgingInterval)
				E131BridgingInterval = 50;
			SetChannelOutputRefreshRate(1000 / E131BridgingInterval);
			StartChannelOutputThread();
		}

		if (getFPPmode() & PLAYER_MODE)
		{
			if ((FPPstatus == FPP_STATUS_PLAYLIST_PLAYING) ||
				(FPPstatus == FPP_STATUS_STOPPING_GRACEFULLY))
			{
				if (prevFPPstatus == FPP_STATUS_IDLE)
				{
					playlist->PlayListPlayingInit();
					sleepms = 10000;
				}

				// Check again here in case PlayListPlayingInit
				// didn't find anything and put us back to IDLE
				if ((FPPstatus == FPP_STATUS_PLAYLIST_PLAYING) ||
					(FPPstatus == FPP_STATUS_STOPPING_GRACEFULLY))
				{
					playlist->PlayListPlayingProcess();
				}
			}

			int reactivated = 0;
			if (FPPstatus == FPP_STATUS_IDLE)
			{
				if ((prevFPPstatus == FPP_STATUS_PLAYLIST_PLAYING) ||
					(prevFPPstatus == FPP_STATUS_STOPPING_GRACEFULLY))
				{
					playlist->PlayListPlayingCleanup();

					if (FPPstatus != FPP_STATUS_IDLE)
						reactivated = 1;
					else
						sleepms = 50000;
				}
			}

			if (reactivated)
				prevFPPstatus = FPP_STATUS_IDLE;
			else
				prevFPPstatus = FPPstatus;

			scheduler->ScheduleProc();
		}
		else if (getFPPmode() == REMOTE_MODE)
		{
			if(mediaOutputStatus.status == MEDIAOUTPUTSTATUS_PLAYING)
			{
				playlist->PlaylistProcessMediaData();
			}
		}

		CheckGPIOInputs();
	}

	StopChannelOutputThread();
	ShutdownControlSocket();

	if (getFPPmode() == BRIDGE_MODE)
		Bridge_Shutdown();

	LogInfo(VB_GENERAL, "Main Loop complete, shutting down.\n");
}