~ubuntu-branches/ubuntu/trusty/fcitx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/module/remote/remote.c

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-02-10 17:03:56 UTC
  • mfrom: (1.3.18) (33.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130210170356-2yuv6xy3ed378kn0
Tags: 1:4.2.7-1
* New upstream release.
* New binary packages:
  - fcitx-libs-gclient: D-Bus client library for Glib
  - fcitx-libs-qt: D-Bus client library for Qt
  - fcitx-module-quickphrase-editor: Quick Phrase editor module

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "fcitx/instance.h"
38
38
#include "fcitx-utils/utils.h"
39
39
 
 
40
#define MAX_IMNAME_LEN 30
 
41
 
40
42
static void* RemoteCreate(FcitxInstance* instance);
41
43
static void RemoteProcessEvent(void* arg);
42
44
static void RemoteSetFD(void* arg);
 
45
static void RemoteDestroy(void* arg);
43
46
static int CreateSocket(const char *name);
44
47
 
45
 
FCITX_EXPORT_API
46
 
FcitxModule module = {
 
48
FCITX_DEFINE_PLUGIN(fcitx_remote, module, FcitxModule) = {
47
49
    RemoteCreate,
48
50
    RemoteSetFD,
49
51
    RemoteProcessEvent,
50
 
    NULL,
 
52
    RemoteDestroy,
51
53
    NULL
52
54
};
53
55
 
54
 
FCITX_EXPORT_API
55
 
int ABI_VERSION = FCITX_ABI_VERSION;
56
 
 
57
56
typedef struct _FcitxRemote {
58
57
    FcitxInstance* owner;
59
58
    int socket_fd;
95
94
        return fd;
96
95
    }
97
96
 
 
97
    int opt = 1;
 
98
    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*) &opt, sizeof(opt));
 
99
 
98
100
    /* setup address struct */
99
101
    memset(&uds_addr, 0, sizeof(uds_addr));
100
102
    uds_addr.sun_family = AF_UNIX;
145
147
{
146
148
    FcitxRemote* remote = (FcitxRemote*) p;
147
149
    unsigned int O;
148
 
    // lower 16bit 0->get 1->set, 2->reload, 3->toggle
 
150
    // lower 16bit 0->get 1->set, 2->reload, 3->toggle, 4->setIM
149
151
    int client_fd = UdAccept(remote->socket_fd);
150
152
    if (client_fd < 0)
151
153
        return;
152
154
    read(client_fd, &O, sizeof(int));
153
155
    unsigned int cmd = O & 0xFFFF;
154
156
    unsigned int arg = (O >> 16) & 0xFFFF;
155
 
    FcitxInstanceLock(remote->owner);
156
157
    switch (cmd) {
157
158
        /// {{{
158
159
    case 0:
172
173
    case 3:
173
174
        FcitxInstanceChangeIMState(remote->owner, FcitxInstanceGetCurrentIC(remote->owner));
174
175
        break;
 
176
    case 4: {
 
177
        char imname[MAX_IMNAME_LEN];
 
178
        int n = read(client_fd, imname, MAX_IMNAME_LEN-1);
 
179
        imname[n] = '\0';
 
180
        FcitxInstanceSwitchIMByName(remote->owner, imname);
 
181
        break;
 
182
    }
175
183
    default:
176
184
        break;
177
185
        /// }}}
178
186
    }
179
 
    FcitxInstanceUnlock(remote->owner);
180
187
    close(client_fd);
181
188
}
182
189
 
188
195
        FcitxInstanceSetMaxFD(remote->owner, remote->socket_fd);
189
196
}
190
197
 
 
198
void RemoteDestroy(void* arg)
 
199
{
 
200
    FcitxRemote* remote = (FcitxRemote*) arg;
 
201
    close(remote->socket_fd);
 
202
    free(remote);
 
203
}
 
204
 
191
205
 
192
206
// kate: indent-mode cstyle; space-indent on; indent-width 0;