Exemplo n.º 1
0
static Status
sm_new_client (SmsConn        sms_conn,
               SmPointer      manager_data,
               unsigned long *mask,
               SmsCallbacks  *callbacks,
               char         **failure_reason)
{
  XfsmManager *manager = XFSM_MANAGER (manager_data);
  XfsmClient  *client;
  gchar       *error = NULL;

  xfsm_verbose ("ICE connection fd = %d, received NEW CLIENT\n\n",
                IceConnectionNumber (SmsGetIceConnection (sms_conn)));

  client = xfsm_manager_new_client (manager, sms_conn, &error);
  if (client == NULL)
    {
      xfsm_verbose ("NEW CLIENT failed: %s\n", error);

#ifdef HAVE_STRDUP
      *failure_reason = strdup (error);
#else
      *failure_reason = (char *) malloc (strlen (error) + 1);
      if (*failure_reason != NULL)
        strcpy (*failure_reason, error);
#endif

      return False;
    }

  SET_CALLBACK (callbacks, register_client, client);
  SET_CALLBACK (callbacks, interact_request, client);
  SET_CALLBACK (callbacks, interact_done, client);
  SET_CALLBACK (callbacks, save_yourself_request, client);
  SET_CALLBACK (callbacks, save_yourself_phase2_request, client);
  SET_CALLBACK (callbacks, save_yourself_done, client);
  SET_CALLBACK (callbacks, close_connection, client);
  SET_CALLBACK (callbacks, set_properties, client);
  SET_CALLBACK (callbacks, delete_properties, client);
  SET_CALLBACK (callbacks, get_properties, client);

  *mask = SmsRegisterClientProcMask | SmsInteractRequestProcMask
    | SmsInteractDoneProcMask | SmsSaveYourselfRequestProcMask
    | SmsSaveYourselfP2RequestProcMask | SmsSaveYourselfDoneProcMask
    | SmsCloseConnectionProcMask | SmsSetPropertiesProcMask
    | SmsDeletePropertiesProcMask | SmsGetPropertiesProcMask;

  g_object_set_data (G_OBJECT (client), "--xfsm-manager", manager);

  return True;
}
Exemplo n.º 2
0
static void
ice_connection_watch (IceConn     ice_conn,
                      IcePointer  client_data,
                      Bool        opening,
                      IcePointer *watch_data)
{
  XfsmManager *manager = XFSM_MANAGER (client_data);
  GIOChannel  *channel;
  guint        watchid;
  gint         fd;

  if (opening)
    {
      XfsmIceConnData *icdata = g_new(XfsmIceConnData, 1);
      icdata->manager = manager;
      icdata->ice_conn = ice_conn;

      fd = IceConnectionNumber (ice_conn);

      /* Make sure we don't pass on these file descriptors to an
       * exec'd child process.
       */
      fcntl (fd, F_SETFD, fcntl (fd, F_GETFD, 0) | FD_CLOEXEC);

      channel = g_io_channel_unix_new (fd);
      watchid = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT,
                                     G_IO_ERR | G_IO_HUP | G_IO_IN,
                                     ice_process_messages,
                                     icdata, (GDestroyNotify) g_free);
      g_io_channel_unref (channel);

      *watch_data = (IcePointer) GUINT_TO_POINTER (watchid);
    }
  else
    {
      watchid = GPOINTER_TO_UINT (*watch_data);
      g_source_remove (watchid);
    }
}