Update package version to 9.0.15
[platform/core/uifw/isf.git] / ism / src / isf_remote_control.cpp
1 #define Uses_SCIM_TRANSACTION
2 #define Uses_ISF_REMOTE_CLIENT
3 #define Uses_STL_STRING
4
5 #include <glib.h>
6 #include <dlog.h>
7 #include <vconf.h>
8 #include <vconf-keys.h>
9
10 #include "scim.h"
11 #include "isf_remote_control.h"
12 #include "isf_debug.h"
13
14 #ifdef LOG_TAG
15 # undef LOG_TAG
16 #endif
17 #define LOG_TAG             "ISF_REMOTE_CONTROL"
18
19 #define MESSAGE_DELIMETER "\t"
20
21 using namespace scim;
22
23 static bool focus_flag;
24
25 struct _remote_control_client {
26     RemoteInputClient *remote_client;
27     GIOChannel *remote_client_iochannel;
28     guint remote_client_iochannel_read;
29     guint remote_client_iochannel_err;
30     guint remote_client_iochannel_hup;
31     int remote_client_id;
32     remote_control_focus_in_cb focus_in_cb;
33     void* focus_in_cb_user_data;
34     remote_control_focus_out_cb focus_out_cb;
35     void* focus_out_cb_user_data;
36     remote_control_entry_metadata_cb metadata_cb;
37     void* metadata_cb_user_data;
38     remote_control_text_updated_cb text_updated_cb;
39     void* text_updated_cb_user_data;
40     remote_control_input_resource_changed_cb input_resource_changed_cb;
41     void* input_resource_changed_cb_user_data;
42     remote_control_key_event_cb key_event_cb;
43     void* key_event_cb_user_data;
44     remote_control_cursor_position_updated_cb cursor_position_updated_cb;
45     void* cursor_position_updated_cb_user_data;
46
47     _remote_control_client() : remote_client(NULL),
48                                remote_client_iochannel(NULL),
49                                remote_client_iochannel_read(0),
50                                remote_client_iochannel_err(0),
51                                remote_client_iochannel_hup(0),
52                                remote_client_id(0),
53                                focus_in_cb(NULL),
54                                focus_in_cb_user_data(NULL),
55                                focus_out_cb(NULL),
56                                focus_out_cb_user_data(NULL),
57                                metadata_cb(NULL),
58                                metadata_cb_user_data(NULL),
59                                text_updated_cb(NULL),
60                                text_updated_cb_user_data(NULL),
61                                input_resource_changed_cb(NULL),
62                                input_resource_changed_cb_user_data(NULL),
63                                key_event_cb(NULL),
64                                key_event_cb_user_data(NULL),
65                                cursor_position_updated_cb(NULL),
66                                cursor_position_updated_cb_user_data(NULL)
67     {
68     }
69 };
70
71 static gboolean
72 remote_handler(GIOChannel *source, GIOCondition condition, gpointer user_data)
73 {
74     if (condition == G_IO_IN) {
75         remote_control_client *client = static_cast<remote_control_client*>(user_data);
76         if (client->remote_client->has_pending_event()) {
77             switch (client->remote_client->recv_callback_message()) {
78                 case REMOTE_CONTROL_CALLBACK_FOCUS_IN:
79                 {
80                     LOGD ("REMOTE_CONTROL_CALLBACK_FOCUS_IN");
81                     focus_flag = true;
82
83                     if (client->focus_in_cb)
84                         client->focus_in_cb (client->focus_in_cb_user_data);
85                     break;
86                 }
87                 case REMOTE_CONTROL_CALLBACK_FOCUS_OUT:
88                 {
89                     LOGD ("REMOTE_CONTROL_CALLBACK_FOCUS_OUT");
90                     focus_flag = false;
91
92                     if (client->focus_out_cb)
93                         client->focus_out_cb (client->focus_out_cb_user_data);
94                     break;
95                 }
96                 case REMOTE_CONTROL_CALLBACK_ENTRY_METADATA:
97                 {
98                     if (focus_flag) {
99                         remote_control_entry_metadata_s *data = new remote_control_entry_metadata_s;
100                         int hint = 0, layout = 0, variation = 0, autocapital_type = 0, return_key_disabled = 0, return_key_type = 0;
101
102                         client->remote_client->get_entry_metadata (&hint, &layout, &variation, &autocapital_type, &return_key_disabled, &return_key_type);
103                         data->hint = static_cast<Ecore_IMF_Input_Hints> (hint);
104                         data->layout = static_cast<Ecore_IMF_Input_Panel_Layout> (layout);
105                         data->variation = variation;
106                         data->autocapital_type = static_cast<Ecore_IMF_Autocapital_Type> (autocapital_type);
107                         data->return_key_disabled = return_key_disabled;
108                         data->return_key_type = static_cast<Ecore_IMF_Input_Panel_Return_Key_Type> (return_key_type);
109
110                         LOGD ("REMOTE_CONTROL_CALLBACK_ENTRY_METADATA: hint=0x%04x, layout=%d, variation=%d, autocap=%d, retKey_disabled=%d, retKey_type=%d",
111                             data->hint, data->layout, data->variation, data->autocapital_type, data->return_key_disabled, data->return_key_type);
112
113                         if (client->metadata_cb)
114                             client->metadata_cb (client->metadata_cb_user_data, data);
115                         delete data;
116                     }
117                     break;
118                 }
119                 case REMOTE_CONTROL_CALLBACK_TEXT_UPDATED:
120                 {
121                     if (focus_flag) {
122                         String surrounding_text;
123                         int cursor = -1;
124
125                         client->remote_client->get_surrounding_text (surrounding_text, &cursor);
126                         SECURE_LOGD ("REMOTE_CONTROL_CALLBACK_TEXT_UPDATED: %d \"%s\"", cursor, surrounding_text.c_str ());
127
128                         if (client->text_updated_cb)
129                             client->text_updated_cb (client->text_updated_cb_user_data, surrounding_text.c_str (), cursor);
130                     }
131                     break;
132                 }
133                 case REMOTE_CONTROL_CALLBACK_INPUT_RESOURCE:
134                 {
135                     if (focus_flag) {
136                         int resource = 0;
137
138                         client->remote_client->get_input_resource (&resource);
139                         LOGD ("REMOTE_CONTROL_CALLBACK_INPUT_RESOURCE: %s", (resource ? "REMOTE" : "LOCAL"));
140
141                         if (client->input_resource_changed_cb)
142                             client->input_resource_changed_cb (client->input_resource_changed_cb_user_data,
143                                 static_cast<remote_control_input_resource> (resource));
144                     }
145                     break;
146                 }
147                 case REMOTE_CONTROL_CALLBACK_KEY_EVENT:
148                 {
149                     if (focus_flag) {
150                         remote_control_key_event_s *data = new remote_control_key_event_s;
151                         String key_symbol;
152                         int press = 0, timestamp = 0;
153
154                         client->remote_client->get_key_symbol (key_symbol, &press, &timestamp);
155
156                         if (strcmp (key_symbol.c_str(), "Return") == 0)
157                             data->type = REMOTE_CONTROL_KEY_SELECT;
158                         else if (strcmp (key_symbol.c_str(), "space") == 0)
159                             data->type = REMOTE_CONTROL_KEY_SPACE;
160                         else if (strcmp (key_symbol.c_str(), "BackSpace") == 0)
161                             data->type = REMOTE_CONTROL_KEY_BACKSPACE;
162                         else if (strcmp (key_symbol.c_str(), "XF86Back") == 0)
163                             data->type = REMOTE_CONTROL_KEY_CANCEL;
164                         else if (strcmp (key_symbol.c_str(), "Up") == 0)
165                             data->type = REMOTE_CONTROL_KEY_UP;
166                         else if (strcmp (key_symbol.c_str(), "Down") == 0)
167                             data->type = REMOTE_CONTROL_KEY_DOWN;
168                         else if (strcmp (key_symbol.c_str(), "Left") == 0)
169                             data->type = REMOTE_CONTROL_KEY_LEFT;
170                         else if (strcmp (key_symbol.c_str(), "Right") == 0)
171                             data->type = REMOTE_CONTROL_KEY_RIGHT;
172
173                         data->pressed = press;
174                         data->timestamp = timestamp;
175                         LOGD ("REMOTE_CONTROL_CALLBACK_KEY_EVENT: type : %d, pressed : %d, timestamp : %d", data->type, data->pressed, data->timestamp);
176
177                         if (client->key_event_cb)
178                             client->key_event_cb (client->key_event_cb_user_data, data);
179                         delete data;
180                     }
181                     break;
182                 }
183                 case REMOTE_CONTROL_CALLBACK_CURSOR_POSITION_UPDATED:
184                 {
185                     if (focus_flag) {
186                         int cursor = -1;
187
188                         client->remote_client->get_cursor_position (&cursor);
189                         SECURE_LOGD ("REMOTE_CONTROL_CALLBACK_CURSOR_POSITION_UPDATED: %d", cursor);
190
191                         if (client->cursor_position_updated_cb)
192                             client->cursor_position_updated_cb (client->cursor_position_updated_cb_user_data, cursor);
193                     }
194                     break;
195                 }
196                 case REMOTE_CONTROL_CALLBACK_ERROR:
197                     LOGE ("REMOTE_CONTROL_CALLBACK_ERROR");
198                     break;
199                 default:
200                     break;
201             }
202         } else {
203             LOGE ("Failed to receive callback message");
204             return (gboolean)FALSE;
205         }
206     } else if (condition == G_IO_ERR || condition == G_IO_HUP) {
207         LOGE ("Failed to receive callback message");
208         return (gboolean)FALSE;
209     }
210
211     return (gboolean)TRUE;
212 }
213
214 EXAPI remote_control_client * remote_control_connect(void)
215 {
216     remote_control_client *client = NULL;
217
218     try {
219         client = new remote_control_client;
220     } catch(const std::bad_alloc& e) {
221         LOGE("Memory allocation failed");
222         return NULL;
223     }
224
225     focus_flag = false;
226
227     try {
228         client->remote_client = new RemoteInputClient;
229     } catch(const std::bad_alloc& e) {
230         LOGE("Memory allocation failed");
231         delete client;
232         return NULL;
233     }
234
235     if (!client->remote_client->open_connection()) {
236         LOGE ("REMOTE_CONTROL_REPLY_TIMEOUT");
237         goto cleanup;
238     }
239
240     {
241         remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
242         if (error_e) {
243             LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
244             goto cleanup;
245         }
246     }
247
248     client->remote_client_id = client->remote_client->get_panel2remote_connection_number();
249
250     if (client->remote_client_id >= 0) {
251         client->remote_client_iochannel = g_io_channel_unix_new(client->remote_client_id);
252
253         if (client->remote_client_iochannel == NULL) {
254             LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
255             goto cleanup;
256         }
257
258         client->remote_client_iochannel_read = g_io_add_watch (client->remote_client_iochannel, G_IO_IN,  remote_handler, client);
259         client->remote_client_iochannel_err = g_io_add_watch (client->remote_client_iochannel, G_IO_ERR,  remote_handler, client);
260         client->remote_client_iochannel_hup = g_io_add_watch (client->remote_client_iochannel, G_IO_HUP,  remote_handler, client);
261     }
262     else {
263         LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
264         goto cleanup;
265     }
266
267     LOGD ("%p", client);
268     return client;
269
270 cleanup:
271     delete client->remote_client;
272     delete client;
273     return NULL;
274 }
275
276 EXAPI int remote_control_disconnect(remote_control_client *client)
277 {
278     LOGD("%p", client);
279
280     if (client == NULL) {
281         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
282         return REMOTE_CONTROL_INVALID_PARAMETER;
283     }
284
285     if (client->remote_client) {
286         remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege ();
287         if (error_e) {
288             LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
289             return error_e;
290         }
291
292         if (client->remote_client_iochannel)
293             g_io_channel_unref (client->remote_client_iochannel);
294
295         if (client->remote_client_iochannel_read)
296             g_source_remove (client->remote_client_iochannel_read);
297
298         if (client->remote_client_iochannel_err)
299             g_source_remove (client->remote_client_iochannel_err);
300
301         if (client->remote_client_iochannel_hup)
302             g_source_remove (client->remote_client_iochannel_hup);
303
304         client->remote_client_iochannel = NULL;
305         client->remote_client_iochannel_read = 0;
306         client->remote_client_iochannel_err = 0;
307         client->remote_client_iochannel_hup = 0;
308
309         client->remote_client->close_connection();
310
311         delete client->remote_client;
312     }
313
314     delete client;
315     client = NULL;
316
317     return REMOTE_CONTROL_ERROR_NONE;
318 }
319
320 EXAPI int remote_control_focus_in_callback_set(remote_control_client *client, remote_control_focus_in_cb func, void *user_data)
321 {
322     if (client == NULL || func == NULL) {
323         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
324         return REMOTE_CONTROL_INVALID_PARAMETER;
325     }
326
327     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
328     if (error_e) {
329         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
330         return error_e;
331     }
332
333     client->focus_in_cb = func;
334     client->focus_in_cb_user_data = user_data;
335
336     LOGD ("%p", client);
337     return REMOTE_CONTROL_ERROR_NONE;
338 }
339
340 EXAPI int remote_control_focus_in_callback_unset(remote_control_client *client)
341 {
342     if (client == NULL) {
343         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
344         return REMOTE_CONTROL_INVALID_PARAMETER;
345     }
346
347     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
348     if (error_e) {
349         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
350         return error_e;
351     }
352
353     client->focus_in_cb = NULL;
354     client->focus_in_cb_user_data = NULL;
355
356     LOGD ("%p", client);
357     return REMOTE_CONTROL_ERROR_NONE;
358 }
359
360 EXAPI int remote_control_focus_out_callback_set(remote_control_client *client, remote_control_focus_out_cb func , void *user_data)
361 {
362     if (client == NULL || func == NULL) {
363         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
364         return REMOTE_CONTROL_INVALID_PARAMETER;
365     }
366
367     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
368     if (error_e) {
369         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
370         return error_e;
371     }
372
373     client->focus_out_cb = func;
374     client->focus_out_cb_user_data = user_data;
375
376     LOGD ("%p", client);
377     return REMOTE_CONTROL_ERROR_NONE;
378 }
379
380 EXAPI int remote_control_focus_out_callback_unset(remote_control_client *client)
381 {
382     if (client == NULL) {
383         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
384         return REMOTE_CONTROL_INVALID_PARAMETER;
385     }
386
387     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
388     if (error_e) {
389         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
390         return error_e;
391     }
392
393     client->focus_out_cb = NULL;
394     client->focus_out_cb_user_data = NULL;
395
396     LOGD ("%p", client);
397     return REMOTE_CONTROL_ERROR_NONE;
398 }
399
400 EXAPI int remote_control_entry_metadata_callback_set(remote_control_client *client, remote_control_entry_metadata_cb func, void *user_data)
401 {
402     if (client == NULL || func == NULL) {
403         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
404         return REMOTE_CONTROL_INVALID_PARAMETER;
405     }
406
407     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
408     if (error_e) {
409         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
410         return error_e;
411     }
412
413     client->metadata_cb = func;
414     client->metadata_cb_user_data = user_data;
415
416     LOGD ("%p", client);
417     return REMOTE_CONTROL_ERROR_NONE;
418 }
419
420 EXAPI int remote_control_entry_metadata_callback_unset(remote_control_client *client)
421 {
422     if (client == NULL) {
423         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
424         return REMOTE_CONTROL_INVALID_PARAMETER;
425     }
426
427     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
428     if (error_e) {
429         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
430         return error_e;
431     }
432
433     client->metadata_cb = NULL;
434     client->metadata_cb_user_data = NULL;
435
436     LOGD ("%p", client);
437     return REMOTE_CONTROL_ERROR_NONE;
438 }
439
440 EXAPI int remote_control_text_updated_callback_set(remote_control_client *client, remote_control_text_updated_cb func, void *user_data)
441 {
442     if (client == NULL || func == NULL) {
443         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
444         return REMOTE_CONTROL_INVALID_PARAMETER;
445     }
446
447     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
448     if (error_e) {
449         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
450         return error_e;
451     }
452
453     client->text_updated_cb = func;
454     client->text_updated_cb_user_data = user_data;
455
456     LOGD ("%p", client);
457     return REMOTE_CONTROL_ERROR_NONE;
458 }
459
460 EXAPI int remote_control_text_updated_callback_unset(remote_control_client *client)
461 {
462     if (client == NULL) {
463         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
464         return REMOTE_CONTROL_INVALID_PARAMETER;
465     }
466
467     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
468     if (error_e) {
469         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
470         return error_e;
471     }
472
473     client->text_updated_cb = NULL;
474     client->text_updated_cb_user_data = NULL;
475
476     LOGD ("%p", client);
477     return REMOTE_CONTROL_ERROR_NONE;
478 }
479
480 EXAPI int remote_control_input_resource_changed_callback_set(remote_control_client *client, remote_control_input_resource_changed_cb func , void *user_data)
481 {
482     if (client == NULL || func == NULL) {
483         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
484         return REMOTE_CONTROL_INVALID_PARAMETER;
485     }
486
487     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
488     if (error_e) {
489         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
490         return error_e;
491     }
492
493     client->input_resource_changed_cb = func;
494     client->input_resource_changed_cb_user_data = user_data;
495
496     LOGD ("%p", client);
497     return REMOTE_CONTROL_ERROR_NONE;
498 }
499
500 EXAPI int remote_control_input_resource_changed_callback_unset(remote_control_client *client)
501 {
502     if (client == NULL) {
503         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
504         return REMOTE_CONTROL_INVALID_PARAMETER;
505     }
506
507     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
508     if (error_e) {
509         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
510         return error_e;
511     }
512
513     client->input_resource_changed_cb = NULL;
514     client->input_resource_changed_cb_user_data = NULL;
515
516     LOGD ("%p", client);
517     return REMOTE_CONTROL_ERROR_NONE;
518 }
519
520 EXAPI int remote_control_send_key_event(remote_control_client *client, remote_control_key_type_e key)
521 {
522     if (client == NULL || key > REMOTE_CONTROL_KEY_CANCEL) {
523         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
524         return REMOTE_CONTROL_INVALID_PARAMETER;
525     }
526
527     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
528     if (error_e) {
529         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
530         return error_e;
531     }
532
533     char key_str[12] = {};
534     snprintf(key_str, sizeof(key_str), "%d", key);
535     String command = String (MESSAGE_DELIMETER) + String ("plain") + String (MESSAGE_DELIMETER) +
536                     String ("send_key_event") + String (MESSAGE_DELIMETER) + String (key_str) + String (MESSAGE_DELIMETER);
537
538     if (focus_flag) {
539         error_e = (remote_control_error_e)client->remote_client->send_remote_input_message(command.c_str ());
540
541         if (!error_e) {
542             SECURE_LOGD ("%p, key=%d", client, key);
543             if (vconf_set_bool (VCONFKEY_ISF_REMOTE_INPUT_DETECTED, 1) != 0)
544                 LOGW ("Failed to set vconf key");
545         }
546
547         return error_e;
548     }
549
550     LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
551     return REMOTE_CONTROL_INVALID_OPERATION;
552 }
553
554 EXAPI int remote_control_send_commit_string(remote_control_client *client, const char *text)
555 {
556     if (client == NULL || !text) {
557         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
558         return REMOTE_CONTROL_INVALID_PARAMETER;
559     }
560
561     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
562     if (error_e) {
563         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
564         return error_e;
565     }
566
567     String command = String (MESSAGE_DELIMETER) + String ("plain") + String (MESSAGE_DELIMETER) +
568                     String ("commit_string") + String (MESSAGE_DELIMETER) + String (text) + String (MESSAGE_DELIMETER);
569
570     if (focus_flag) {
571         error_e = (remote_control_error_e)client->remote_client->send_remote_input_message(command.c_str ());
572
573         if (!error_e) {
574             SECURE_LOGD ("%p, \"%s\"", client, text);
575             if (vconf_set_bool (VCONFKEY_ISF_REMOTE_INPUT_DETECTED, 1) != 0)
576                 LOGW ("Failed to set vconf key");
577         }
578
579         return error_e;
580     }
581
582     LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
583     return REMOTE_CONTROL_INVALID_OPERATION;
584 }
585
586 EXAPI int remote_control_update_preedit_string(remote_control_client *client, const char *text, Eina_List *attrs, int cursor_pos)
587 {
588     if (client == NULL) {
589         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
590         return REMOTE_CONTROL_INVALID_PARAMETER;
591     }
592
593     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
594     if (error_e) {
595         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
596         return error_e;
597     }
598
599     char cursor_position[10] = {};
600     snprintf(cursor_position, sizeof(cursor_position), "%d", cursor_pos);
601     String command = String (MESSAGE_DELIMETER) + String ("plain") + String (MESSAGE_DELIMETER) +String ("update_preedit_string") +
602                     String (MESSAGE_DELIMETER) + String (text) + String (MESSAGE_DELIMETER) + String (cursor_position) + String (MESSAGE_DELIMETER);
603
604     if (focus_flag) {
605         error_e = (remote_control_error_e)client->remote_client->send_remote_input_message(command.c_str ());
606
607         if (!error_e) {
608             SECURE_LOGD ("%p, %d, \"%s\"", client, cursor_pos, text);
609             if (vconf_set_bool (VCONFKEY_ISF_REMOTE_INPUT_DETECTED, 1) != 0)
610                 LOGW ("Failed to set vconf key");
611         }
612
613         return error_e;
614     }
615
616     LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
617     return REMOTE_CONTROL_INVALID_OPERATION;
618 }
619
620 EXAPI int remote_control_delete_surrounding_text(remote_control_client *client, int offset, int len)
621 {
622     if (client == NULL || len < 0) {
623         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
624         return REMOTE_CONTROL_INVALID_PARAMETER;
625     }
626
627     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
628     if (error_e) {
629         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
630         return error_e;
631     }
632
633     if (focus_flag) {
634         error_e = (remote_control_error_e)client->remote_client->delete_surrounding_text(offset, len);
635
636         if (!error_e) {
637             LOGD ("%p, (%d, %d)", client, offset, len);
638             if (vconf_set_bool (VCONFKEY_ISF_REMOTE_INPUT_DETECTED, 1) != 0)
639                 LOGW ("Failed to set vconf key");
640         }
641
642         return error_e;
643     }
644
645     LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
646     return REMOTE_CONTROL_INVALID_OPERATION;
647 }
648
649 EXAPI int remote_control_key_event_callback_set(remote_control_client *client, remote_control_key_event_cb func , void *user_data)
650 {
651     if (client == NULL || func == NULL) {
652         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
653         return REMOTE_CONTROL_INVALID_PARAMETER;
654     }
655
656     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
657     if (error_e) {
658         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
659         return error_e;
660     }
661
662     client->key_event_cb = func;
663     client->key_event_cb_user_data = user_data;
664
665     LOGD ("%p", client);
666     return REMOTE_CONTROL_ERROR_NONE;
667 }
668
669 EXAPI int remote_control_key_event_callback_unset(remote_control_client *client)
670 {
671     if (client == NULL) {
672         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
673         return REMOTE_CONTROL_INVALID_PARAMETER;
674     }
675
676     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
677     if (error_e) {
678         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
679         return error_e;
680     }
681
682     client->key_event_cb = NULL;
683     client->key_event_cb_user_data = NULL;
684
685     LOGD ("%p", client);
686     return REMOTE_CONTROL_ERROR_NONE;
687 }
688
689 EXAPI int remote_control_set_cursor_position(remote_control_client *client, int cursor_pos)
690 {
691     if (client == NULL || cursor_pos < 0) {
692         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
693         return REMOTE_CONTROL_INVALID_PARAMETER;
694     }
695
696     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
697     if (error_e) {
698         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
699         return error_e;
700     }
701
702     if (focus_flag) {
703         error_e = (remote_control_error_e)client->remote_client->set_cursor_position(cursor_pos);
704
705         if (!error_e) {
706             LOGD ("%p, (%d)", client, cursor_pos);
707             if (vconf_set_bool (VCONFKEY_ISF_REMOTE_INPUT_DETECTED, 1) != 0)
708                 LOGW ("Failed to set vconf key");
709         }
710
711         return error_e;
712     }
713
714     LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
715     return REMOTE_CONTROL_INVALID_OPERATION;
716 }
717
718 EXAPI int remote_control_cursor_position_updated_callback_set(remote_control_client *client, remote_control_cursor_position_updated_cb func , void *user_data)
719 {
720     if (client == NULL || func == NULL) {
721         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
722         return REMOTE_CONTROL_INVALID_PARAMETER;
723     }
724
725     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
726     if (error_e) {
727         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
728         return error_e;
729     }
730
731     client->cursor_position_updated_cb = func;
732     client->cursor_position_updated_cb_user_data = user_data;
733
734     LOGD ("%p", client);
735     return REMOTE_CONTROL_ERROR_NONE;
736 }
737
738 EXAPI int remote_control_cursor_position_updated_callback_unset(remote_control_client *client)
739 {
740     if (client == NULL) {
741         LOGE ("REMOTE_CONTROL_INVALID_PARAMETER");
742         return REMOTE_CONTROL_INVALID_PARAMETER;
743     }
744
745     remote_control_error_e error_e = (remote_control_error_e)client->remote_client->check_privilege();
746     if (error_e) {
747         LOGE ("REMOTE_CONTROL_PERMISSION_DENIED");
748         return error_e;
749     }
750
751     client->cursor_position_updated_cb = NULL;
752     client->cursor_position_updated_cb_user_data = NULL;
753
754     LOGD ("%p", client);
755     return REMOTE_CONTROL_ERROR_NONE;
756 }