~ubuntu-branches/ubuntu/wily/scim/wily-proposed

« back to all changes in this revision

Viewing changes to extras/immodules/agent/scim-bridge-agent-interruption-listener.cpp

  • Committer: Package Import Robot
  • Author(s): Rolf Leggewie, Rolf Leggewie, Tz-Huan Huang
  • Date: 2012-06-30 11:21:42 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120630112142-a4cwzsr16dty8dk7
Tags: 1.4.14-1
[ Rolf Leggewie ]
* new upstream release 1.4.14
  - drop 32_scim-1.4.8-fix-dlopen.patch which has landed upstream
* bump compat level to 9
* debian/control: add Toni Mueller as co-maintainer
  Welcome aboard!

[ Tz-Huan Huang ]
* start shipping a couple of newly introduced im-module packages
* debian/rules:
  - simplify dh_auto_install override where upstream changes allow this
  - drop -fpermissive from CXXFLAGS, fixed upstream
* debian/README.*: update the documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * SCIM Bridge
 
3
 *
 
4
 * Copyright (c) 2006 Ryo Dairiki <ryo-dairiki@users.sourceforge.net>
 
5
 *
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation and 
 
10
 * appearing in the file LICENSE.LGPL included in the package of this file.
 
11
 * You can also redistribute it and/or modify it under the terms of 
 
12
 * the GNU General Public License as published by the Free Software Foundation and 
 
13
 * appearing in the file LICENSE.GPL included in the package of this file.
 
14
 *
 
15
 * This library is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
18
 */
 
19
 
 
20
#include <errno.h>
 
21
#include <fcntl.h>
 
22
#include <stdio.h>
 
23
#include <string.h>
 
24
#include <unistd.h>
 
25
 
 
26
#include <sys/socket.h>
 
27
#include <sys/types.h>
 
28
 
 
29
#include "scim-bridge-output.h"
 
30
 
 
31
#include "scim-bridge-agent-interruption-listener.h"
 
32
 
 
33
/* Class definition */
 
34
class ScimBridgeAgentInterruptionListenerImpl: public ScimBridgeAgentInterruptionListener
 
35
{
 
36
 
 
37
    public:
 
38
 
 
39
        ScimBridgeAgentInterruptionListenerImpl ();
 
40
        ~ScimBridgeAgentInterruptionListenerImpl ();
 
41
 
 
42
        retval_t initialize ();
 
43
 
 
44
        int get_socket_fd () const;
 
45
 
 
46
        scim_bridge_agent_event_type_t get_trigger_events () const;
 
47
 
 
48
        bool handle_event (scim_bridge_agent_event_type_t event_type);
 
49
 
 
50
        bool is_interrupted () const;
 
51
 
 
52
        void interrupt ();
 
53
 
 
54
        void clear_interruption ();
 
55
 
 
56
    private:
 
57
 
 
58
        bool interrupted;
 
59
 
 
60
        int pipe_in;
 
61
        int pipe_out;
 
62
 
 
63
};
 
64
 
 
65
/* Implementations */
 
66
ScimBridgeAgentInterruptionListener *ScimBridgeAgentInterruptionListener::alloc ()
 
67
{
 
68
 
 
69
    ScimBridgeAgentInterruptionListenerImpl *interruption_listener = new ScimBridgeAgentInterruptionListenerImpl ();
 
70
    if (interruption_listener->initialize ()) {
 
71
        delete interruption_listener;
 
72
        interruption_listener = NULL;
 
73
    }
 
74
 
 
75
    return interruption_listener;
 
76
}
 
77
 
 
78
 
 
79
ScimBridgeAgentInterruptionListenerImpl::ScimBridgeAgentInterruptionListenerImpl (): interrupted (false), pipe_in (-1), pipe_out (-1)
 
80
{
 
81
}
 
82
 
 
83
 
 
84
ScimBridgeAgentInterruptionListenerImpl::~ScimBridgeAgentInterruptionListenerImpl ()
 
85
{
 
86
    if (pipe_in >= 0) close (pipe_in);
 
87
    if (pipe_out >= 0) close (pipe_out);
 
88
}
 
89
 
 
90
 
 
91
retval_t ScimBridgeAgentInterruptionListenerImpl::initialize ()
 
92
{
 
93
    int pipe_pair[2];
 
94
 
 
95
    if (socketpair (PF_UNIX, SOCK_STREAM, 0, pipe_pair)) {
 
96
        scim_bridge_perrorln ("Cannot make a pipe for a interruption listener: %s", strerror (errno));
 
97
        return RETVAL_FAILED;
 
98
    }
 
99
 
 
100
    pipe_out = pipe_pair[0];
 
101
    pipe_in = pipe_pair[1];
 
102
    scim_bridge_pdebugln (2, "The interruption pipe: (%d, %d)", pipe_in, pipe_out);
 
103
 
 
104
    return RETVAL_SUCCEEDED;
 
105
}
 
106
 
 
107
 
 
108
int ScimBridgeAgentInterruptionListenerImpl::get_socket_fd () const
 
109
{
 
110
    return pipe_out;
 
111
}
 
112
 
 
113
 
 
114
scim_bridge_agent_event_type_t ScimBridgeAgentInterruptionListenerImpl::get_trigger_events () const
 
115
{
 
116
    return SCIM_BRIDGE_AGENT_EVENT_READ;
 
117
}
 
118
 
 
119
 
 
120
bool ScimBridgeAgentInterruptionListenerImpl::handle_event (scim_bridge_agent_event_type_t event_type)
 
121
{
 
122
    return true;
 
123
}
 
124
 
 
125
 
 
126
void ScimBridgeAgentInterruptionListenerImpl::interrupt ()
 
127
{
 
128
    scim_bridge_pdebugln (1, "An interruption occurred");
 
129
    if (interrupted) return;
 
130
 
 
131
    interrupted = true;
 
132
    if (send (pipe_in, " ", sizeof (char), MSG_NOSIGNAL | MSG_DONTWAIT) < 0 && errno != EAGAIN) {
 
133
        scim_bridge_perrorln ("Failed to make an interruption: %s", strerror (errno));
 
134
    }
 
135
}
 
136
 
 
137
 
 
138
bool ScimBridgeAgentInterruptionListenerImpl::is_interrupted () const
 
139
{
 
140
    return interrupted;
 
141
}
 
142
 
 
143
 
 
144
void ScimBridgeAgentInterruptionListenerImpl::clear_interruption ()
 
145
{
 
146
    scim_bridge_pdebugln (1, "The interruption is cleared");
 
147
    char c;
 
148
    recv (pipe_out, &c, sizeof (char), MSG_DONTWAIT);
 
149
    interrupted = false;
 
150
}