~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to tools/geis-server/geis-server.c

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * geis-server.c Test driver for the GEIS server.
 
3
 *
 
4
 * Copyright 2011 Canonical Ltd.
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or modify it under
 
7
 * the terms of the GNU General Public License as published by the Free Software
 
8
 * Foundation; either version 3 of the License, or (at your option) any later
 
9
 * version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 
14
 * details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/.
 
18
 */
 
19
#include <errno.h>
 
20
#include <geis/geis.h>
 
21
#include <stdio.h>
 
22
#include <string.h>
 
23
#include <sys/select.h>
 
24
 
 
25
 
 
26
int
 
27
main()
 
28
{
 
29
  GeisStatus status;
 
30
 
 
31
  Geis geis = geis_new(GEIS_INIT_SERVICE_PROVIDER,
 
32
                       GEIS_INIT_XCB_BACKEND,
 
33
                       NULL);
 
34
  if (!geis)
 
35
  {
 
36
    fprintf(stderr, "error creating geis instance.\n");
 
37
    goto final_exit;
 
38
  }
 
39
 
 
40
  int geis_fd = -1;
 
41
  status = geis_get_configuration(geis, GEIS_CONFIGURATION_FD, &geis_fd);
 
42
  if (status != GEIS_STATUS_SUCCESS)
 
43
  {
 
44
    fprintf(stderr, "error obtaining geis fd.\n");
 
45
    goto unwind_geis;
 
46
  }
 
47
 
 
48
  while (1)
 
49
  {
 
50
    fd_set read_fds;
 
51
    FD_ZERO(&read_fds);
 
52
    FD_SET(0, &read_fds);
 
53
    FD_SET(geis_fd, &read_fds);
 
54
 
 
55
    int sstat = select(geis_fd + 1, &read_fds, NULL, NULL, NULL);
 
56
    if (sstat < 0)
 
57
    {
 
58
      fprintf(stderr, "error %d in select(): %s\n", errno, strerror(errno));
 
59
      break;
 
60
    }
 
61
 
 
62
    if (FD_ISSET(geis_fd, &read_fds))
 
63
    {
 
64
      status = geis_dispatch_events(geis);
 
65
 
 
66
      GeisEvent  event_out;
 
67
      status = geis_next_event(geis, &event_out);
 
68
      while (status == GEIS_STATUS_CONTINUE || status == GEIS_STATUS_SUCCESS)
 
69
      {
 
70
        geis_event_delete(event_out);
 
71
        status = geis_next_event(geis, &event_out);
 
72
      }
 
73
    }
 
74
 
 
75
    if (FD_ISSET(0, &read_fds))
 
76
    {
 
77
      break;
 
78
    }
 
79
  }
 
80
 
 
81
unwind_geis:
 
82
  geis_delete(geis);
 
83
final_exit:
 
84
  return 0;
 
85
}