summaryrefslogtreecommitdiff
path: root/src/sclconnection-isf.cpp
blob: 9631f27bdaa2d6ce9f4bc5b547ab49b82836e4a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
/*
 * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include "sclconnection-isf.h"
#include "sclcoreimpl.h"
#include <Elementary.h>
#include <dlog.h>

using namespace scl;

static scim::ConfigPointer _scim_config(0);

/* Slot functions for calling appropriate callback functions */
static void slot_exit(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_ise_hide(ic, ic_uuid.c_str());
            callback->on_exit();
        }
        if (agent) {
            agent->update_ise_exit();
        }
    }
    elm_exit();
}

static void slot_attach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_attach_input_context(ic, ic_uuid.c_str());
        }
    }
}

static void slot_detach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_detach_input_context(ic, ic_uuid.c_str());
        }
    }
}

static void slot_reload_config(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_reload_config(ic, ic_uuid.c_str());
        }
    }
}

static void slot_update_screen(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int screen_number) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            //callback->on_update_screen(ic, ic_uuid.c_str(), screen_number);
        }
    }
}

static void slot_update_spot_location(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int x, int y) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_update_spot_location(ic, ic_uuid.c_str(), x, y);
        }
    }
}

static void slot_update_cursor_position(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int cursor_pos) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_update_cursor_position(ic, ic_uuid.c_str(), cursor_pos);
        }
    }
}

static void slot_update_surrounding_text(const scim::HelperAgent *agent, int ic, const scim::String &text, int cursor) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_update_surrounding_text(ic, text.c_str(), cursor);
        }
    }
}

static void slot_trigger_property(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, const scim::String &property) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            //callback->on_trigger_property(ic, ic_uuid.c_str(), property.c_str());
        }
    }
}

static void slot_focus_out(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_focus_out(ic, ic_uuid.c_str());
        }
    }
}

static void slot_focus_in(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_focus_in(ic, ic_uuid.c_str());
        }
    }
}

static void slot_ise_show(const scim::HelperAgent *agent, int ic, char *buf, size_t &len) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        /* Make sure the appropriate keyboard ise was selected -> is this really necessary? */
        //impl->set_keyboard_ise_by_uuid(impl->get_keyboard_ise_uuid().c_str());

        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            /* Check if effect is enabled */
            Ise_Context ise_context;
            memset(&ise_context, 0x00, sizeof(ise_context));

            if (len >= sizeof(Ise_Context)) {
                memcpy(&ise_context, buf, sizeof(ise_context));

                if (ise_context.imdata_size > 0) {
                    callback->on_set_imdata(buf + sizeof(ise_context), ise_context.imdata_size);
                }
            } else {
                LOGD("\n-=-= WARNING - buf %p len %d size %d \n", buf, len, sizeof(ise_context));
            }
            CSCLCoreUI* ui = impl->get_core_ui();
            if (ui) {
                ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_WILL_SHOW);
            }
            callback->on_ise_show(ic, impl->get_screen_rotation_degree(), ise_context);
            if (ui) {
                ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_DID_SHOW);
            }
        }
    }
}

static void slot_ise_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            CSCLCoreUI* ui = impl->get_core_ui();
            if (ui) {
                ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_WILL_HIDE);
            }
            callback->on_ise_hide(ic, ic_uuid.c_str());
            if (ui) {
                ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_DID_HIDE);
            }
        }
    }
}

static void slot_get_geometry(const scim::HelperAgent *agent, struct scim::rectinfo &info) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_get_geometry(&(info.pos_x), &(info.pos_y), &(info.width), &(info.height));
        }
    }
}

static void slot_set_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_set_mode(mode);
        }
    }
}

static void slot_set_language(const scim::HelperAgent *agent, scim::uint32 &language) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_set_language(language);
        }
    }
}

static void slot_set_imdata(const scim::HelperAgent *agent, char *buf, size_t &len) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            scl32 _len = static_cast<scl32>(reinterpret_cast<size_t>(len) & 0xffffffff);
            callback->on_set_imdata(buf, _len);
        }
    }
}

static void slot_get_imdata(const scim::HelperAgent *, char **buf, size_t &len) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            sclu32 _len = 0;
            callback->on_get_imdata(buf, &_len);
            len = _len;
        }
    }
}

static void slot_get_language_locale(const scim::HelperAgent *, int ic, char **locale) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_get_language_locale(ic, locale);
        }
    }
}

static void slot_set_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_set_return_key_type(type);
        }
    }
}

static void slot_get_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_get_return_key_type(&type);
        }
    }
}

static void slot_set_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_set_return_key_disable(disabled);
        }
    }
}

static void slot_get_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_get_return_key_disable(&disabled);
        }
    }
}

static void slot_set_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_set_layout(layout);
        }
    }
}

static void slot_get_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_get_layout(&layout);
        }
    }
}

static void slot_set_caps_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_set_caps_mode(mode);
        }
    }
}

static void slot_reset_input_context(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_reset_input_context(ic, uuid.c_str());
        }
    }
}

static void slot_update_candidate_geometry(const scim::HelperAgent *agent, int ic, const scim::String &uuid, const scim::rectinfo &info) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_update_candidate_geometry(ic, uuid.c_str(), info.pos_x, info.pos_y, info.width, info.height);
        }
    }
}
static void slot_update_keyboard_ise(const scim::HelperAgent *agent, int ic, const scim::String &uuid,
                                                  const scim::String &ise_name, const scim::String &ise_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_update_keyboard_ise(ic, uuid.c_str(), ise_name.c_str(), ise_uuid.c_str());
        }
    }
}

static void slot_candidate_more_window_show(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_candidate_more_window_show(ic, uuid.c_str());
        }
    }
}

static void slot_candidate_more_window_hide(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_candidate_more_window_hide(ic, uuid.c_str());
        }
    }
}

static void slot_select_aux(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_select_aux(ic, uuid.c_str(), index);
        }
    }
}

static void slot_select_candidate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_select_candidate(ic, uuid.c_str(), index);
        }
    }
}

static void slot_candidate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_candidate_table_page_up(ic, uuid.c_str());
        }
    }
}

static void slot_candidate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_candidate_table_page_down(ic, uuid.c_str());
        }
    }
}

static void slot_update_candidate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_update_candidate_table_page_size(ic, uuid.c_str(), page_size);
        }
    }
}

static void slot_update_lookup_table(const scim::HelperAgent *, scim::LookupTable &table) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            SclCandidateTable lookup_table;
            lookup_table.page_size = table.get_page_size();
            lookup_table.current_page_start = table.get_current_page_start();
            lookup_table.cursor_pos = table.get_cursor_pos();
            lookup_table.cursor_visible = table.is_cursor_visible();
            lookup_table.page_size_fixed = table.is_page_size_fixed();
            lookup_table.candidate_labels.clear();
            for (int page_index = 0;page_index < lookup_table.page_size;page_index++) {
                scim::WideString label = table.get_candidate_label(page_index);
                lookup_table.candidate_labels.push_back(scim::utf8_wcstombs(label).c_str());
            }

            int nCandidateSize = table.get_current_page_size();
            for (int index = 0; index < nCandidateSize; ++index) {
                scim::WideString candidate_str = table.get_candidate_in_current_page(index);
                lookup_table.candidate.push_back(scim::utf8_wcstombs(candidate_str).c_str());
            }

            callback->on_update_lookup_table(lookup_table);

            std::vector<scim::WideString> labels;
            for (unsigned int loop = 0;loop < lookup_table.candidate_labels.size();loop++) {
                labels.push_back(scim::utf8_mbstowcs(lookup_table.candidate_labels.at(loop).c_str()));
            }
            table.set_candidate_labels(labels);
        }
    }
}

static void slot_select_associate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_select_associate(ic, uuid.c_str(), index);
        }
    }
}

static void slot_associate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_associate_table_page_up(ic, uuid.c_str());
        }
    }
}

static void slot_associate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_associate_table_page_down(ic, uuid.c_str());
        }
    }
}

static void slot_update_associate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_update_associate_table_page_size(ic, uuid.c_str(), page_size);
        }
    }
}

static void slot_show_ise_option_window(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        CSCLCoreUI *core_ui = impl->get_core_ui();
        if (core_ui) {
            LOGD("slot_show_ise_option_window() called!!!\n");
            core_ui->create_option_window(OPTION_WINDOW_TYPE_SETTING_APPLICATION);
        }
    }
}

static void slot_check_ise_option_window(const scim::HelperAgent *agent, sclu32 &avail) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_check_option_window_availability(reinterpret_cast<sclboolean *>(&avail));
        }
    }
}

static void slot_process_key_event(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_process_key_event(key, &ret);
        }
    }
}

static void slot_candidate_show(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_candidate_show(ic, ic_uuid.c_str());
        }
    }
}

static void slot_candidate_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            callback->on_candidate_hide(ic, ic_uuid.c_str());
        }
    }
}

static void slot_process_input_device_event(const scim::HelperAgent *agent, scim::uint32 &type, char *data, size_t &len, scim::uint32 &ret) {
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        ISCLCoreEventCallback *callback = impl->get_core_event_callback();
        if (callback) {
            /* Input Device Event callback is available in versions after 1.1 */
            if (check_interface_version(callback, 1, 1)) {
                callback->on_process_input_device_event(type, data, len, &ret);
            }
        }
    }
}

/* Internal input handler function */
Eina_Bool input_handler(void *data, Ecore_Fd_Handler *fd_handler)
{
    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        scim::HelperAgent *agent = static_cast<scim::HelperAgent*>(data);
        if (agent) {
            if (agent->has_pending_event()) {
                if (!(agent->filter_event())) {
                    LOGD("helper_agent.filter_event() failed!!!\n");
                    impl->fini();
                    elm_exit();
                }
            } else {
                LOGD("helper_agent.has_pending_event() failed!!!\n");
                impl->fini();
                elm_exit();
            }
        }
    }

    return ECORE_CALLBACK_RENEW;
}

CSCLConnectionISF::CSCLConnectionISF()
{
    m_initialized = FALSE;
    m_fd_handler = NULL;

    m_backend_identifier = "ISF";
}

CSCLConnectionISF::~CSCLConnectionISF()
{
}

sclboolean CSCLConnectionISF::init()
{
    LOGD("Enter\n");

    CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
    if (impl) {
        sclchar *uuid = impl->get_uuid();
        if (uuid) {
            m_helper_info.uuid = uuid;
        }
    }

    if (!m_initialized) {
        m_helper_agent.signal_connect_exit(scim::slot(slot_exit));
        m_helper_agent.signal_connect_attach_input_context(scim::slot(slot_attach_input_context));
        m_helper_agent.signal_connect_detach_input_context(scim::slot(slot_detach_input_context));
        m_helper_agent.signal_connect_reload_config(scim::slot(slot_reload_config));
        m_helper_agent.signal_connect_update_screen(scim::slot(slot_update_screen));
        m_helper_agent.signal_connect_update_spot_location(scim::slot(slot_update_spot_location));
        m_helper_agent.signal_connect_update_cursor_position(scim::slot(slot_update_cursor_position));
        m_helper_agent.signal_connect_update_surrounding_text(scim::slot(slot_update_surrounding_text));
        m_helper_agent.signal_connect_trigger_property(scim::slot(slot_trigger_property));
        //m_helper_agent.signal_connect_process_imengine_event (slot (slot_process_imengine_event));
        m_helper_agent.signal_connect_focus_out(scim::slot(slot_focus_out));
        m_helper_agent.signal_connect_focus_in(scim::slot(slot_focus_in));
        m_helper_agent.signal_connect_ise_show(scim::slot(slot_ise_show));
        m_helper_agent.signal_connect_ise_hide(scim::slot(slot_ise_hide));
        m_helper_agent.signal_connect_get_geometry(scim::slot(slot_get_geometry));
        m_helper_agent.signal_connect_set_mode(scim::slot(slot_set_mode));
        m_helper_agent.signal_connect_set_language(scim::slot(slot_set_language));
        m_helper_agent.signal_connect_set_imdata(scim::slot(slot_set_imdata));
        m_helper_agent.signal_connect_get_imdata(scim::slot(slot_get_imdata));
        m_helper_agent.signal_connect_get_language_locale(scim::slot(slot_get_language_locale));
        m_helper_agent.signal_connect_set_return_key_type(scim::slot(slot_set_return_key_type));
        m_helper_agent.signal_connect_get_return_key_type(scim::slot(slot_get_return_key_type));
        m_helper_agent.signal_connect_set_return_key_disable(scim::slot(slot_set_return_key_disable));
        m_helper_agent.signal_connect_get_return_key_disable(scim::slot(slot_get_return_key_disable));
        m_helper_agent.signal_connect_get_layout(scim::slot(slot_get_layout));
        m_helper_agent.signal_connect_set_layout(scim::slot(slot_set_layout));
        m_helper_agent.signal_connect_set_caps_mode(scim::slot(slot_set_caps_mode));
        m_helper_agent.signal_connect_reset_input_context(scim::slot(slot_reset_input_context));
        m_helper_agent.signal_connect_update_candidate_geometry(scim::slot(slot_update_candidate_geometry));
        m_helper_agent.signal_connect_update_keyboard_ise(scim::slot(slot_update_keyboard_ise));
        //m_helper_agent.signal_connect_update_keyboard_ise_list (slot (slot_update_keyboard_ise_list));
        m_helper_agent.signal_connect_candidate_more_window_show(scim::slot(slot_candidate_more_window_show));
        m_helper_agent.signal_connect_candidate_more_window_hide(scim::slot(slot_candidate_more_window_hide));
        m_helper_agent.signal_connect_select_aux(scim::slot(slot_select_aux));
        m_helper_agent.signal_connect_select_candidate(scim::slot(slot_select_candidate));
        m_helper_agent.signal_connect_candidate_table_page_up(scim::slot(slot_candidate_table_page_up));
        m_helper_agent.signal_connect_candidate_table_page_down(scim::slot(slot_candidate_table_page_down));
        m_helper_agent.signal_connect_update_candidate_table_page_size(scim::slot(slot_update_candidate_table_page_size));
        m_helper_agent.signal_connect_update_lookup_table(scim::slot(slot_update_lookup_table));
        m_helper_agent.signal_connect_select_associate(scim::slot(slot_select_associate));
        m_helper_agent.signal_connect_associate_table_page_up(scim::slot(slot_associate_table_page_up));
        m_helper_agent.signal_connect_associate_table_page_down(scim::slot(slot_associate_table_page_down));
        m_helper_agent.signal_connect_update_associate_table_page_size(scim::slot(slot_update_associate_table_page_size));
        m_helper_agent.signal_connect_show_option_window(scim::slot(slot_show_ise_option_window));
        m_helper_agent.signal_connect_check_option_window(scim::slot(slot_check_ise_option_window));
        m_helper_agent.signal_connect_process_key_event(scim::slot(slot_process_key_event));
        m_helper_agent.signal_connect_candidate_show(scim::slot(slot_candidate_show));
        m_helper_agent.signal_connect_candidate_hide(scim::slot(slot_candidate_hide));
        m_helper_agent.signal_connect_process_input_device_event(scim::slot(slot_process_input_device_event));

        m_initialized = TRUE;
    }

    if (_scim_config.null()) {
        scim::ConfigPointer config_pointer = scim::ConfigBase::get(true, "socket");
        if (config_pointer.null()) {
            config_pointer = new scim::DummyConfig();
        }
        _scim_config = config_pointer;
    }

    return TRUE;
}

void CSCLConnectionISF::fini()
{
    if (!_scim_config.null()) {
        _scim_config.reset();
    }
    scim::ConfigBase::set(0);
    close_connection();
    m_initialized = FALSE;
}

void CSCLConnectionISF::open_connection(const sclchar *display)
{
    if (m_initialized) {
        m_helper_agent.open_connection(m_helper_info, display);
        int fd = m_helper_agent.get_connection_number();

        if (fd >= 0) {
#ifndef WAYLAND
            Evas_Object *main_window = NULL;
            CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
            if (impl) {
                main_window = NATIVE_WINDOW_CAST(impl->get_main_window());
            }

            Ecore_X_Window xwindow = elm_win_xwindow_get(main_window);
            char xid[255];
            snprintf(xid, 255, "%d", xwindow);
            scim::Property prop(xid, "XID", "", "");
            scim::PropertyList props;
            props.push_back(prop);
            m_helper_agent.register_properties(props);
#endif

            m_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, input_handler, &m_helper_agent, NULL, NULL);
        }
    }
}
void CSCLConnectionISF::close_connection()
{
    if (m_initialized) {
        if (m_fd_handler) {
            ecore_main_fd_handler_del(m_fd_handler);
            m_fd_handler = NULL;
        }
        m_helper_agent.update_ise_exit();
        m_helper_agent.close_connection();
    }
}

void CSCLConnectionISF::config_reload()
{
    if (m_initialized) {
        m_helper_agent.reload_config();
    }
}

sclboolean CSCLConnectionISF::config_read_int(const sclchar *name, sclint &value)
{
    sclboolean ret = FALSE;
    if (m_initialized && _scim_config) {
        value = _scim_config->read(name, value);
        ret = TRUE;
    }
    return ret;
}

sclboolean CSCLConnectionISF::config_read_string(const sclchar *name, std::string &value)
{
    sclboolean ret = FALSE;
    if (m_initialized && _scim_config) {
        value = _scim_config->read(name, value);
        ret = TRUE;
    }
    return ret;
}

sclboolean CSCLConnectionISF::config_write_int(const sclchar *name, sclint value)
{
    sclboolean ret = FALSE;
    if (m_initialized && _scim_config) {
        _scim_config->write(name, value);
        ret = TRUE;
    }
    return ret;
}

sclboolean CSCLConnectionISF::config_write_string(const sclchar *name, const std::string value)
{
    sclboolean ret = FALSE;
    if (m_initialized && _scim_config) {
        _scim_config->write(name, value);
        ret = TRUE;
    }
    return ret;
}

sclboolean CSCLConnectionISF::config_erase(const sclchar *name)
{
    sclboolean ret = FALSE;
    if (m_initialized && _scim_config) {
        _scim_config->erase(name);
        ret = TRUE;
    }
    return ret;
}

sclboolean CSCLConnectionISF::config_flush(void)
{
    sclboolean ret = FALSE;
    if (m_initialized && _scim_config) {
        _scim_config->flush();
        ret = TRUE;
    }
    return ret;
}

void CSCLConnectionISF::send_imengine_event(sclint ic, const sclchar *ic_uuid, const sclint command, const sclu32 value)
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        scim::Transaction trans;
        trans.put_command(command);
        trans.put_data(value);
        m_helper_agent.send_imengine_event(ic, uuid, trans);
    }
}

void CSCLConnectionISF::reset_keyboard_ise()
{
    if (m_initialized) {
        m_helper_agent.reset_keyboard_ise();
    }
}

void CSCLConnectionISF::send_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        scim::KeyEvent event;
        event.code = keycode;
        event.mask = keymask;
        m_helper_agent.send_key_event(ic, uuid, event);
    }
}

void CSCLConnectionISF::forward_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        scim::KeyEvent event;
        event.code = keycode;
        event.mask = keymask;
        m_helper_agent.forward_key_event(ic, uuid, event);
    }
}

void CSCLConnectionISF::commit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        m_helper_agent.commit_string(ic, uuid, scim::utf8_mbstowcs(str));
    }
}

void CSCLConnectionISF::select_candidate(int index)
{
    if (m_initialized) {
        m_helper_agent.select_candidate(index);
    }
}

void CSCLConnectionISF::show_preedit_string(sclint ic, const sclchar *ic_uuid)
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        m_helper_agent.show_preedit_string(ic, uuid);
    }
}

void CSCLConnectionISF::show_aux_string(void)
{
    if (m_initialized) {
        m_helper_agent.show_aux_string();
    }
}

void CSCLConnectionISF::show_candidate_string(void)
{
    if (m_initialized) {
        m_helper_agent.show_candidate_string();
    }
}

void CSCLConnectionISF::show_associate_string(void)
{
    if (m_initialized) {
        m_helper_agent.show_associate_string();
    }
}

void CSCLConnectionISF::hide_preedit_string(sclint ic, const sclchar *ic_uuid)
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        m_helper_agent.hide_preedit_string(ic, uuid);
    }
}

void CSCLConnectionISF::hide_aux_string(void)
{
    if (m_initialized) {
        m_helper_agent.hide_aux_string();
    }
}

void CSCLConnectionISF::hide_candidate_string(void)
{
    if (m_initialized) {
        m_helper_agent.hide_candidate_string();
    }
}

void CSCLConnectionISF::hide_associate_string(void)
{
    if (m_initialized) {
        m_helper_agent.hide_associate_string();
    }
}

void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
{
    if (m_initialized) {
        scim::AttributeList list;
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), list);

        if (str && strlen(str) > 0) {
            show_preedit_string(ic, ic_uuid);
        } else {
            hide_preedit_string(ic, ic_uuid);
        }
    }
}

void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str, const scim::AttributeList &attrs)
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), attrs);

        if (str && strlen(str) > 0) {
            show_preedit_string(ic, ic_uuid);
        } else {
            hide_preedit_string(ic, ic_uuid);
        }
    }
}

void CSCLConnectionISF::update_aux_string(const sclchar *str)
{
    if (m_initialized) {
        scim::AttributeList list;
        m_helper_agent.update_aux_string(scim::String(str), list);
    }
}

void CSCLConnectionISF::update_input_context(sclu32 type, sclu32 value)
{
    if (m_initialized) {
        m_helper_agent.update_input_context(type, value);
    }
}

void CSCLConnectionISF::update_geometry(sclint x, sclint y, sclint width, sclint height)
{
    if (m_initialized) {
        m_helper_agent.update_geometry(x, y, width, height);
    }
}

void CSCLConnectionISF::get_surrounding_text(const sclchar *ic_uuid, sclint maxlen_before, sclint maxlen_after) const
{
    if (m_initialized) {
        scim::String uuid;
        if (ic_uuid) {
            uuid = scim::String(ic_uuid);
        }
        m_helper_agent.get_surrounding_text(uuid, maxlen_before, maxlen_after);
    }
}

sclint CSCLConnectionISF::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
{
    if (m_initialized) {
        scim::String surrounding_text;
        m_helper_agent.get_surrounding_text(maxlen_before, maxlen_after, surrounding_text, cursor);

        if (text) {
            *text = strdup(surrounding_text.c_str());
            if (*text == NULL) {
                return -1;
            }
        }
    }
    return 0;
}

void CSCLConnectionISF::delete_surrounding_text(sclint offset, sclint len) const
{
    if (m_initialized) {
        m_helper_agent.delete_surrounding_text(offset, len);
    }
}

void CSCLConnectionISF::set_candidate_position(sclint left, sclint top)
{
    if (m_initialized) {
        m_helper_agent.set_candidate_position(left, top);
    }
}

void CSCLConnectionISF::enable_soft_candidate(sclboolean enable)
{
    if (m_initialized) {
        if (enable)
            m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::SOFT_CANDIDATE_WINDOW);
        else
            m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::FIXED_CANDIDATE_WINDOW);
    }
}

void CSCLConnectionISF::candidate_hide(void)
{
    if (m_initialized) {
        m_helper_agent.candidate_hide();
    }
}

void CSCLConnectionISF::set_keyboard_ise_by_uuid(const sclchar *uuid)
{
    if (m_initialized) {
        m_helper_agent.set_keyboard_ise_by_uuid(uuid);
    }
}

void CSCLConnectionISF::get_keyboard_ise(const sclchar *uuid)
{
    if (m_initialized) {
        m_helper_agent.get_keyboard_ise(uuid);
    }
}

void CSCLConnectionISF::set_selection(sclint start, sclint end)
{
    if (m_initialized) {
        m_helper_agent.set_selection(start, end);
    }
}

void CSCLConnectionISF::send_private_command(const sclchar *command)
{
    if (m_initialized) {
        m_helper_agent.send_private_command(command);
    }
}

void CSCLConnectionISF::get_selection_text(sclchar **text)
{
    if (m_initialized) {
        scim::String selection_text;
        m_helper_agent.get_selection_text(selection_text);

        if (text)
            *text = strdup(selection_text.c_str());
    }
}

extern "C"
{
    void scim_module_init(void) {
    }

    void scim_module_exit(void) {
    }

    void scim_helper_module_run_helper(const scim::String &uuid, const scim::ConfigPointer &config, const scim::String &display) {
        _scim_config = config;
        CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
        if (impl) {
            impl->on_run(uuid.c_str(), display.c_str());
        }
    }
}