PfAttachLocalDll()

Load a local font DLL

Synopsis:

#include <font_api.h>

fontdll_t PfAttachLocalDll( char const * options,
                            char const * schema );

Arguments:

options
Command-line options for the local font DLL. These commands should be comma-separated. For example: -A,-d=/usr/photon/font_repository. This argument may be NULL if there are no options.
schema
The name of a schema, a configuration file used to override the default settings for a local font server.

Use the DLL_FONT_SERVER schema for processes that need to allocate sufficient resources to act as a default font server. This schema loads a local server instance that can be used as an external server by other applications (that is, it appears in /def/phfont). Use NULL to load a local server instance that cannot be used by other applications.

The string referenced by schema may not exceed DLL_MAX_OPTION_NAME bytes, including the terminating NULL.

Library:

font

Description:

This function loads a local font DLL, which eliminates message passing to an external font server. Options are processed and applied before the server instance is activated. The options are the same as those supported by the font server, though some options may not be relevant to a DLL instance of the font server.

Returns:

A fontdll_t context
Success
NULL
An error ocurred (errno is set).

Errors:

ENOENT
Unable to locate font server plugin.
ELIBBAD
Font server plugin is bad.
ENOMEM
Insufficient resources.

Examples:

/* An example of how to run a root level font server device. */

#include <signal.h>
#include <font_api.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/siginfo.h>
#include <atomic.h>
#include <sys/procmgr.h>
#include <unistd.h>

static volatile unsigned restart = 0;

void restart_fontserver(int sig)
{  atomic_add(&restart, 1);
}

static volatile unsigned stop = 0;

void stop_fontserver(int sig)
{  atomic_add(&stop, 1);
}

/*
 * Install useful signal handlers.
 */
static int TrapSignals(void)
{  int sig;

#if defined(__linux__) || defined(__CYGWIN__)
   signal(SIGTERM, SIG_DFL);
   signal(SIGQUIT, SIG_DFL);
   //signal(SIGINT, SIG_DFL);
   signal(SIGHUP, SIG_DFL);
#else
   for(sig = _SIGMIN; sig <= _SIGMAX; ++sig)
   {  if(sig == SIGTERM)
        signal(sig, stop_fontserver);
      else if(sig == SIGINT || sig == SIGHUP)
        signal(sig, SIG_IGN);
      else if(sig == SIGUSR2)
        signal(sig, restart_fontserver);
      else
        signal(sig, SIG_DFL);
   }
#endif
   return(0);
}

int main(int argc, char * argv[])
{  fontdll_t dll;

   /* Make oneself a daemon. */

   procmgr_daemon(EXIT_SUCCESS, PROCMGR_DAEMON_NOCHDIR | PROCMGR_DAEMON_NODEVNULL
                  | PROCMGR_DAEMON_KEEPUMASK | PROCMGR_DAEMON_NOCLOSE);

   /* Process any command line arguments here, if you so desire. */

   /* Retrieve font dll context. */
   if((dll = PfAttachLocalDll(NULL, DLL_FONT_SERVER)) == NULL)
   {  perror("Unable to open font DLL");
      return(EXIT_FAILURE);
   }
   else
   {  /* Set up signals as per documentation from PfAttachServerDll. */
      TrapSignals();

      /* Initialize root level font server device instance. */
      if(PfAttachServerDll(dll, 12, NULL) == -1)
      {  perror("Unable to start server thread");
         PfDetachLocalDll(dll);
         return(EXIT_FAILURE);
      }
      else
      {  int exit = 0;

         /* Wait for font server device to exit. */
         do
         {  if(PfWaitOnServerDll(dll) == -1)
            {  if((errno = EINTR) && restart)
               {  if(PfRestartServerDll(dll) == -1)
                  {  perror("Unable to restart server thread");
                     exit = 1;
                  }
                  else
                    atomic_sub(&restart, 1);
               }
               else if((errno = EINTR) && stop)
                 exit = 1;
            }
            else
              exit = 1;
         }
         while(!exit);
      }

      /* Clean everything up tidy like. */
      PfDetachLocalDll(dll);
   }

   return(EXIT_SUCCESS);
}

Classification:

Photon

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

PfAttachServerDll()

Fonts chapter of the Photon Programmer's Guide