c45c76b85f0ab726f6fde881be4c0a44ce20716b
[platform/framework/web/provider.git] / src / provider_buffer.c
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <sys/types.h>
19 #include <errno.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include <com-core.h>
26 #include <packet.h>
27 #include <com-core_packet.h>
28
29 #include <dlog.h>
30 #include <livebox-errno.h>
31
32 #include "dlist.h"
33 #include "util.h"
34 #include "debug.h"
35 #include "fb.h"
36 #include "provider.h"
37 #include "provider_buffer.h"
38 #include "provider_buffer_internal.h"
39
40 #define EAPI __attribute__((visibility("default")))
41
42 static struct {
43         struct dlist *buffer_list;
44 } s_info = {
45         .buffer_list = NULL,
46 };
47
48 static inline struct fb_info *send_acquire_request(enum target_type type, const char *pkgname, const char *id, int w, int h, int size)
49 {
50         struct packet *packet;
51         struct packet *result;
52         const char *buffer_id;
53         struct fb_info *ret;
54         int status;
55
56         packet = packet_create("acquire_buffer", "issiii", type, pkgname, id, w, h, size);
57         if (!packet) {
58                 ErrPrint("Failed to build a packet\n");
59                 return NULL;
60         }
61
62         result = com_core_packet_oneshot_send(SLAVE_SOCKET, packet, 0.0f);
63         packet_destroy(packet);
64
65         if (!result) {
66                 ErrPrint("Failed to send a request\n");
67                 return NULL;
68         }
69
70         if (packet_get(result, "is", &status, &buffer_id) != 2) {
71                 ErrPrint("Failed to get a result packet\n");
72                 packet_unref(result);
73                 return NULL;
74         }
75
76         if (status != 0) {
77                 ErrPrint("Failed to acquire buffer: %d\n", status);
78                 packet_unref(result);
79                 return NULL;
80         }
81
82         ret = fb_create(buffer_id, w, h);
83         /*!
84          * \TODO: Implements me
85          */
86         DbgPrint("type: 0x%X, name: %s, pkgname[%s], id[%s], w[%d], h[%d], size[%d], buffer_id[%s], fb[%p]\n", type, provider_name(), pkgname, id, w, h, size, buffer_id, ret);
87         packet_unref(result);
88
89         return ret;
90 }
91
92 static inline int send_release_request(enum target_type type, const char *pkgname, const char *id)
93 {
94         struct packet *packet;
95         struct packet *result;
96         int ret;
97
98         packet = packet_create("release_buffer", "iss", type, pkgname, id);
99         if (!packet) {
100                 ErrPrint("Failed to build a packet\n");
101                 return LB_STATUS_ERROR_FAULT;
102         }
103
104         result = com_core_packet_oneshot_send(SLAVE_SOCKET, packet, 0.0f);
105         packet_destroy(packet);
106         if (!result) {
107                 ErrPrint("Failed to send a request\n");
108                 return LB_STATUS_ERROR_FAULT;
109         }
110
111         if (packet_get(result, "i", &ret) != 1) {
112                 ErrPrint("Invalid result packet\n");
113                 ret = LB_STATUS_ERROR_INVALID;
114         }
115
116         packet_unref(result);
117         return ret;
118 }
119
120 static inline struct fb_info *send_resize_request(enum target_type type, const char *pkgname, const char *id, int w, int h)
121 {
122         struct packet *packet;
123         struct packet *result;
124         int ret;
125         const char *buffer_id;
126         struct fb_info *fb;
127
128         packet = packet_create("resize_buffer", "issii", type, pkgname, id, w, h);
129         if (!packet) {
130                 ErrPrint("Faield to build a packet\n");
131                 return NULL;
132         }
133
134         result = com_core_packet_oneshot_send(SLAVE_SOCKET, packet, 0.0f);
135         packet_destroy(packet);
136         if (!result) {
137                 ErrPrint("Failed to send a request\n");
138                 return NULL;
139         }
140
141         if (packet_get(result, "is", &ret, &buffer_id) != 2) {
142                 ErrPrint("Invalid result packet\n");
143                 packet_unref(result);
144                 return NULL;
145         }
146
147         fb = (ret == 0) ? fb_create(buffer_id, w, h) : NULL;
148         packet_unref(result);
149         return fb;
150 }
151
152 struct livebox_buffer *provider_buffer_find_buffer(enum target_type type, const char *pkgname, const char *id)
153 {
154         struct dlist *l;
155         struct dlist *n;
156         struct livebox_buffer *info;
157
158         dlist_foreach_safe(s_info.buffer_list, l, n, info) {
159                 if (info->type != type)
160                         continue;
161
162                 if (!strcmp(info->pkgname, pkgname) && !strcmp(info->id, id))
163                         return info;
164         }
165
166         return NULL;
167 }
168
169 EAPI int provider_buffer_set_user_data(struct livebox_buffer *handle, void *data)
170 {
171         if (!handle || handle->state != BUFFER_CREATED) {
172                 ErrPrint("info is not valid\n");
173                 return LB_STATUS_ERROR_INVALID;
174         }
175
176         handle->user_data = data;
177         return LB_STATUS_SUCCESS;
178 }
179
180 EAPI void *provider_buffer_user_data(struct livebox_buffer *handle)
181 {
182         if (!handle || handle->state != BUFFER_CREATED) {
183                 ErrPrint("info is not valid\n");
184                 return NULL;
185         }
186
187         return handle->user_data;
188 }
189
190 EAPI struct livebox_buffer *provider_buffer_acquire(enum target_type type, const char *pkgname, const char *id, int width, int height, int pixel_size, int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *), void *data)
191 {
192         struct livebox_buffer *info;
193
194         if (width <= 0 || height <= 0 || pixel_size <= 0) {
195                 ErrPrint("Invalid size: %dx%d, %d\n", width, height, pixel_size);
196                 return NULL;
197         }
198
199         if (!pkgname) {
200                 ErrPrint("Invalid parameter: pkgname is NIL\n");
201                 return NULL;
202         }
203
204         if (!id) {
205                 ErrPrint("Invalid ID: id is NIL\n");
206                 return NULL;
207         }
208
209         if (!handler)
210                 DbgPrint("Event handler is not speicified\n");
211
212         DbgPrint("acquire_buffer: [%s] %s, %dx%d, size: %d, handler: %p\n",
213                                                 type == TYPE_LB ? "LB" : "PD", id,
214                                                 width, height, pixel_size, handler);
215
216         info = malloc(sizeof(*info));
217         if (!info) {
218                 ErrPrint("Heap: %s\n", strerror(errno));
219                 return NULL;
220         }
221
222         info->pkgname = strdup(pkgname);
223         if (!info->pkgname) {
224                 ErrPrint("Heap: %s\n", strerror(errno));
225                 free(info);
226                 return NULL;
227         }
228
229         info->id = strdup(id);
230         if (!info->id) {
231                 ErrPrint("Heap: %s\n", strerror(errno));
232                 free(info->pkgname);
233                 free(info);
234                 return NULL;
235         }
236
237         info->fb = send_acquire_request(type, pkgname, id, width, height, pixel_size);
238         if (!info->fb) {
239                 ErrPrint("Failed to acquire a info\n");
240                 free(info->pkgname);
241                 free(info->id);
242                 free(info);
243                 return NULL;
244         }
245
246         info->width = width;
247         info->height = height;
248         info->pixel_size = pixel_size;
249         info->handler = handler;
250         info->type = type;
251         info->data = data;
252         info->state = BUFFER_CREATED;
253
254         s_info.buffer_list = dlist_prepend(s_info.buffer_list, info);
255         return info;
256 }
257
258 EAPI int provider_buffer_resize(struct livebox_buffer *info, int w, int h)
259 {
260         struct fb_info *fb;
261
262         if (!info || info->state != BUFFER_CREATED) {
263                 ErrPrint("info is not valid\n");
264                 return LB_STATUS_ERROR_INVALID;
265         }
266
267         fb = send_resize_request(info->type, info->pkgname, info->id, w, h);
268         if (!fb)
269                 return LB_STATUS_ERROR_INVALID;
270
271         /*!
272          * \note
273          * Even if we destroy the buffer object,
274          * if the user references it, it will not be destroyed,
275          * it only can be destroyed when there is no reference exists.
276          */
277         info->fb = fb;
278         return LB_STATUS_SUCCESS;
279 }
280
281 EAPI void *provider_buffer_ref(struct livebox_buffer *info)
282 {
283         if (!info || info->state != BUFFER_CREATED) {
284                 ErrPrint("info is not valid\n");
285                 return NULL;
286         }
287
288         return fb_acquire_buffer(info->fb);
289 }
290
291 EAPI int provider_buffer_unref(void *ptr)
292 {
293         if (!ptr) {
294                 ErrPrint("PTR is not valid\n");
295                 return LB_STATUS_ERROR_INVALID;
296         }
297
298         return fb_release_buffer(ptr);
299 }
300
301 EAPI int provider_buffer_release(struct livebox_buffer *info)
302 {
303         int ret;
304
305         if (!info || info->state != BUFFER_CREATED) {
306                 ErrPrint("Buffer handler is NULL\n");
307                 return LB_STATUS_ERROR_INVALID;
308         }
309
310         dlist_remove_data(s_info.buffer_list, info);
311
312         ret = send_release_request(info->type, info->pkgname, info->id);
313         if (ret < 0) {
314                 ErrPrint("Failed to send a release request\n");
315                 /*!
316                  * \note
317                  * But go ahead to destroy this buffer object
318                  */
319         }
320
321         info->state = BUFFER_DESTROYED;
322         free(info->pkgname);
323         free(info->id);
324         free(info);
325         return LB_STATUS_SUCCESS;
326 }
327
328 EAPI int provider_buffer_sync(struct livebox_buffer *info)
329 {
330         if (!info || info->state != BUFFER_CREATED) {
331                 ErrPrint("Buffer handler is NULL\n");
332                 return LB_STATUS_ERROR_INVALID;
333         }
334
335         return fb_sync(info->fb);
336 }
337
338 EAPI enum target_type provider_buffer_type(struct livebox_buffer *info)
339 {
340         if (!info || info->state != BUFFER_CREATED) {
341                 ErrPrint("Buffer handler is NULL\n");
342                 return TYPE_ERROR;
343         }
344
345         return info->type;
346 }
347
348 EAPI const char *provider_buffer_pkgname(struct livebox_buffer *info)
349 {
350         if (!info || info->state != BUFFER_CREATED) {
351                 ErrPrint("Buffer handler is NULL\n");
352                 return NULL;
353         }
354
355         return info->pkgname;
356 }
357
358 /*!
359  * \brief
360  * Getting the URI of given buffer.
361  */
362 EAPI const char *provider_buffer_id(struct livebox_buffer *info)
363 {
364         if (!info || info->state != BUFFER_CREATED) {
365                 ErrPrint("Buffer handler is NULL\n");
366                 return NULL;
367         }
368
369         return info->id;
370 }
371
372 EAPI int provider_buffer_get_size(struct livebox_buffer *info, int *w, int *h, int *pixel_size)
373 {
374         if (!info || info->state != BUFFER_CREATED) {
375                 ErrPrint("Buffer handler is NULL\n");
376                 return LB_STATUS_ERROR_INVALID;
377         }
378
379         if (w)
380                 *w = info->width;
381
382         if (h)
383                 *h = info->height;
384
385         if (pixel_size)
386                 *pixel_size = info->pixel_size;
387
388         return LB_STATUS_SUCCESS;
389 }
390
391 EAPI const char *provider_buffer_uri(struct livebox_buffer *info)
392 {
393         if (!info || info->state != BUFFER_CREATED) {
394                 ErrPrint("Buffer handler is NULL\n");
395                 return NULL;
396         }
397
398         return fb_id(info->fb);
399 }
400
401 /*!
402  * \brief
403  * If the given buffer is created as pixmap,
404  * This function returns pixmap ID.
405  */
406 EAPI unsigned long provider_buffer_pixmap_id(struct livebox_buffer *info)
407 {
408         const char *id;
409         unsigned long pixmap;
410
411         if (!info || info->state != BUFFER_CREATED) {
412                 ErrPrint("Buffer handler is NULL\n");
413                 return 0;
414         }
415
416         id = fb_id(info->fb);
417         if (!id)
418                 return 0;
419
420         if (sscanf(id, SCHEMA_PIXMAP "%lu", &pixmap) != 1) {
421                 ErrPrint("Invalid ID: %s\n", id);
422                 return 0;
423         }
424
425         return pixmap;
426 }
427
428 EAPI int provider_buffer_pixmap_is_support_hw(struct livebox_buffer *info)
429 {
430         if (!info)
431                 return LB_STATUS_ERROR_INVALID;
432
433         return fb_has_gem(info->fb);
434 }
435
436 EAPI int provider_buffer_pixmap_create_hw(struct livebox_buffer *info)
437 {
438         if (!fb_has_gem(info->fb))
439                 return LB_STATUS_ERROR_INVALID;
440
441         return fb_create_gem(info->fb);
442 }
443
444 EAPI int provider_buffer_pixmap_destroy_hw(struct livebox_buffer *info)
445 {
446         if (!info || !fb_has_gem(info->fb))
447                 return LB_STATUS_ERROR_INVALID;
448
449         return fb_destroy_gem(info->fb);
450 }
451
452 EAPI void *provider_buffer_pixmap_hw_addr(struct livebox_buffer *info)
453 {
454         void *addr;
455
456         if (!info || !fb_has_gem(info->fb))
457                 return NULL;
458
459         addr = fb_acquire_gem(info->fb);
460         fb_release_gem(info->fb);
461
462         return addr;
463 }
464
465 EAPI int provider_buffer_pre_render(struct livebox_buffer *info)
466 {
467         int ret = LB_STATUS_SUCCESS;
468
469         if (!info)
470                 return LB_STATUS_ERROR_INVALID;
471
472         if (fb_has_gem(info->fb))
473                 ret = fb_acquire_gem(info->fb) ? 0 : -EFAULT;
474
475         return ret;
476 }
477
478 EAPI int provider_buffer_post_render(struct livebox_buffer *info)
479 {
480         int ret = LB_STATUS_SUCCESS;
481
482         if (!info)
483                 return LB_STATUS_ERROR_INVALID;
484
485         if (fb_has_gem(info->fb))
486                 ret = fb_release_gem(info->fb);
487
488         return ret;
489 }
490
491 int provider_buffer_init(void *display)
492 {
493         return fb_init(display);
494 }
495
496 int provider_buffer_fini(void)
497 {
498         return fb_fini();
499 }
500
501 struct packet *provider_buffer_lb_key_down(pid_t pid, int handle, const struct packet *packet)
502 {
503         const char *pkgname;
504         const char *id;
505         int x;
506         int y;
507         double timestamp;
508         struct livebox_buffer *info;
509
510         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
511                 ErrPrint("Invalid packet\n");
512                 goto out;
513         }
514
515         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
516         if (!info) {
517                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
518                 goto out;
519         }
520
521         if (info->handler) {
522                 int w;
523                 int h;
524
525                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
526                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
527                         goto out;
528                 }
529
530                 (void)info->handler(info, BUFFER_EVENT_KEY_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
531         }
532
533 out:
534         return NULL;
535 }
536
537 struct packet *provider_buffer_lb_key_up(pid_t pid, int handle, const struct packet *packet)
538 {
539         const char *pkgname;
540         const char *id;
541         int x;
542         int y;
543         double timestamp;
544         struct livebox_buffer *info;
545
546         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
547                 ErrPrint("Invalid packet\n");
548                 goto out;
549         }
550
551         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
552         if (!info) {
553                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
554                 goto out;
555         }
556
557         if (info->handler) {
558                 int w;
559                 int h;
560
561                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
562                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
563                         goto out;
564                 }
565
566                 (void)info->handler(info, BUFFER_EVENT_KEY_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
567         }
568
569 out:
570         return NULL;
571 }
572
573 struct packet *provider_buffer_lb_mouse_enter(pid_t pid, int handle, const struct packet *packet)
574 {
575         const char *pkgname;
576         const char *id;
577         int x;
578         int y;
579         double timestamp;
580         struct livebox_buffer *info;
581
582         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
583                 ErrPrint("Invalid packet\n");
584                 goto out;
585         }
586
587         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
588         if (!info) {
589                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
590                 goto out;
591         }
592
593         if (info->handler) {
594                 int w;
595                 int h;
596                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
597                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
598                         goto out;
599                 }
600
601                 (void)info->handler(info, BUFFER_EVENT_ENTER, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
602         }
603
604 out:
605         return NULL;
606 }
607
608 struct packet *provider_buffer_lb_mouse_leave(pid_t pid, int handle, const struct packet *packet)
609 {
610         const char *pkgname;
611         const char *id;
612         int x;
613         int y;
614         double timestamp;
615         struct livebox_buffer *info;
616
617         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
618                 ErrPrint("Invalid packet\n");
619                 goto out;
620         }
621
622         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
623         if (!info) {
624                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
625                 goto out;
626         }
627
628         if (info->handler) {
629                 int w;
630                 int h;
631                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
632                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
633                         goto out;
634                 }
635
636                 (void)info->handler(info, BUFFER_EVENT_LEAVE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
637         }
638
639 out:
640         return NULL;
641 }
642
643 struct packet *provider_buffer_lb_mouse_down(pid_t pid, int handle, const struct packet *packet)
644 {
645         const char *pkgname;
646         const char *id;
647         int x;
648         int y;
649         double timestamp;
650         struct livebox_buffer *info;
651
652         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
653                 ErrPrint("Invalid packet\n");
654                 goto out;
655         }
656
657         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
658         if (!info) {
659                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
660                 goto out;
661         }
662
663         if (info->handler) {
664                 int w;
665                 int h;
666                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
667                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
668                         goto out;
669                 }
670
671                 (void)info->handler(info, BUFFER_EVENT_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
672         }
673
674 out:
675         return NULL;
676 }
677
678 struct packet *provider_buffer_lb_mouse_up(pid_t pid, int handle, const struct packet *packet)
679 {
680         const char *pkgname;
681         const char *id;
682         int x;
683         int y;
684         double timestamp;
685         struct livebox_buffer *info;
686
687         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
688                 ErrPrint("Invalid packet\n");
689                 goto out;
690         }
691
692         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
693         if (!info) {
694                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
695                 goto out;
696         }
697
698         if (info->handler) {
699                 int w;
700                 int h;
701                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
702                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
703                         goto out;
704                 }
705
706                 (void)info->handler(info, BUFFER_EVENT_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
707         }
708
709 out:
710         return NULL;
711 }
712
713 struct packet *provider_buffer_lb_mouse_move(pid_t pid, int handle, const struct packet *packet)
714 {
715         const char *pkgname;
716         const char *id;
717         int x;
718         int y;
719         double timestamp;
720         struct livebox_buffer *info;
721
722         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
723                 ErrPrint("Invalid packet\n");
724                 goto out;
725         }
726
727         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
728         if (!info) {
729                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
730                 goto out;
731         }
732
733         if (info->handler) {
734                 int w;
735                 int h;
736                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
737                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
738                         goto out;
739                 }
740                 (void)info->handler(info, BUFFER_EVENT_MOVE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
741         }
742
743 out:
744         return NULL;
745 }
746
747 struct packet *provider_buffer_pd_key_down(pid_t pid, int handle, const struct packet *packet)
748 {
749         const char *pkgname;
750         const char *id;
751         int x;
752         int y;
753         double timestamp;
754         struct livebox_buffer *info;
755
756         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
757                 ErrPrint("Invalid packet\n");
758                 goto out;
759         }
760
761         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
762         if (!info) {
763                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
764                 goto out;
765         }
766
767         if (info->handler) {
768                 int w;
769                 int h;
770                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
771                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
772                         goto out;
773                 }
774
775                 (void)info->handler(info, BUFFER_EVENT_KEY_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
776         }
777
778 out:
779         return NULL;
780 }
781
782 struct packet *provider_buffer_pd_key_up(pid_t pid, int handle, const struct packet *packet)
783 {
784         const char *pkgname;
785         const char *id;
786         int x;
787         int y;
788         double timestamp;
789         struct livebox_buffer *info;
790
791         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
792                 ErrPrint("Invalid packet\n");
793                 goto out;
794         }
795
796         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
797         if (!info) {
798                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
799                 goto out;
800         }
801
802         if (info->handler) {
803                 int w;
804                 int h;
805                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
806                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
807                         goto out;
808                 }
809
810                 (void)info->handler(info, BUFFER_EVENT_KEY_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
811         }
812
813 out:
814         return NULL;
815 }
816
817 struct packet *provider_buffer_pd_mouse_enter(pid_t pid, int handle, const struct packet *packet)
818 {
819         const char *pkgname;
820         const char *id;
821         int x;
822         int y;
823         double timestamp;
824         struct livebox_buffer *info;
825
826         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
827                 ErrPrint("Invalid packet\n");
828                 goto out;
829         }
830
831         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
832         if (!info) {
833                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
834                 goto out;
835         }
836
837         if (info->handler) {
838                 int w;
839                 int h;
840                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
841                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
842                         goto out;
843                 }
844
845                 (void)info->handler(info, BUFFER_EVENT_ENTER, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
846         }
847
848 out:
849         return NULL;
850 }
851
852 struct packet *provider_buffer_pd_mouse_leave(pid_t pid, int handle, const struct packet *packet)
853 {
854         const char *pkgname;
855         const char *id;
856         int x;
857         int y;
858         double timestamp;
859         struct livebox_buffer *info;
860
861         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
862                 ErrPrint("Invalid packet\n");
863                 goto out;
864         }
865
866         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
867         if (!info) {
868                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
869                 goto out;
870         }
871
872         if (info->handler) {
873                 int w;
874                 int h;
875                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
876                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
877                         goto out;
878                 }
879
880                 (void)info->handler(info, BUFFER_EVENT_LEAVE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
881         }
882
883 out:
884         return NULL;
885 }
886
887 struct packet *provider_buffer_pd_mouse_down(pid_t pid, int handle, const struct packet *packet)
888 {
889         const char *pkgname;
890         const char *id;
891         int x;
892         int y;
893         double timestamp;
894         struct livebox_buffer *info;
895
896         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
897                 ErrPrint("Invalid packet\n");
898                 goto out;
899         }
900
901         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
902         if (!info) {
903                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
904                 goto out;
905         }
906
907         if (info->handler) {
908                 int w;
909                 int h;
910                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
911                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
912                         goto out;
913                 }
914
915                 (void)info->handler(info, BUFFER_EVENT_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
916         }
917
918 out:
919         return NULL;
920 }
921
922 struct packet *provider_buffer_pd_mouse_up(pid_t pid, int handle, const struct packet *packet)
923 {
924         const char *pkgname;
925         const char *id;
926         int x;
927         int y;
928         double timestamp;
929         struct livebox_buffer *info;
930
931         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
932                 ErrPrint("Invalid packet\n");
933                 goto out;
934         }
935
936         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
937         if (!info) {
938                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
939                 goto out;
940         }
941
942         if (info->handler) {
943                 int w;
944                 int h;
945                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
946                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
947                         goto out;
948                 }
949
950                 (void)info->handler(info, BUFFER_EVENT_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
951         }
952
953 out:
954         return NULL;
955 }
956
957 struct packet *provider_buffer_pd_mouse_move(pid_t pid, int handle, const struct packet *packet)
958 {
959         const char *pkgname;
960         const char *id;
961         int x;
962         int y;
963         double timestamp;
964         struct livebox_buffer *info;
965
966         if (packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y) != 5) {
967                 ErrPrint("Invalid packet\n");
968                 goto out;
969         }
970
971         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
972         if (!info) {
973                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
974                 goto out;
975         }
976
977         if (info->handler) {
978                 int w;
979                 int h;
980                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0) {
981                         ErrPrint("Failed to get buffer size [%s:%s]\n", pkgname, id);
982                         goto out;
983                 }
984
985                 (void)info->handler(info, BUFFER_EVENT_MOVE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
986         }
987
988 out:
989         return NULL;
990 }
991
992 struct packet *provider_buffer_pd_access_action_up(pid_t pid, int handle, const struct packet *packet)
993 {
994         const char *pkgname;
995         const char *id;
996         double timestamp;
997         int ret;
998         int x;
999         int y;
1000         struct livebox_buffer *info;
1001
1002         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1003         if (ret != 5) {
1004                 ErrPrint("Invalid packet\n");
1005                 goto out;
1006         }
1007
1008         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1009         if (!info) {
1010                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1011                 goto out;
1012         }
1013
1014         if (info->handler) {
1015                 int w;
1016                 int h;
1017
1018                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1019                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1020
1021                 (void)info->handler(info, BUFFER_EVENT_ACTION_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1022         }
1023
1024 out:
1025         return NULL;
1026 }
1027
1028 struct packet *provider_buffer_pd_access_action_down(pid_t pid, int handle, const struct packet *packet)
1029 {
1030         const char *pkgname;
1031         const char *id;
1032         double timestamp;
1033         int ret;
1034         int x;
1035         int y;
1036         struct livebox_buffer *info;
1037
1038         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1039         if (ret != 5) {
1040                 ErrPrint("Invalid packet\n");
1041                 goto out;
1042         }
1043
1044         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1045         if (!info) {
1046                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1047                 goto out;
1048         }
1049
1050         if (info->handler) {
1051                 int w;
1052                 int h;
1053
1054                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1055                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1056
1057                 (void)info->handler(info, BUFFER_EVENT_ACTION_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1058         }
1059
1060 out:
1061         return NULL;
1062 }
1063
1064 struct packet *provider_buffer_pd_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
1065 {
1066         const char *pkgname;
1067         const char *id;
1068         double timestamp;
1069         int ret;
1070         int x;
1071         int y;
1072         struct livebox_buffer *info;
1073
1074         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1075         if (ret != 5) {
1076                 ErrPrint("Invalid packet\n");
1077                 goto out;
1078         }
1079
1080         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1081         if (!info) {
1082                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1083                 goto out;
1084         }
1085
1086         if (info->handler) {
1087                 int w;
1088                 int h;
1089
1090                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1091                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1092
1093                 (void)info->handler(info, BUFFER_EVENT_SCROLL_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1094         }
1095
1096 out:
1097         return NULL;
1098 }
1099
1100 struct packet *provider_buffer_pd_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
1101 {
1102         const char *pkgname;
1103         const char *id;
1104         double timestamp;
1105         int ret;
1106         int x;
1107         int y;
1108         struct livebox_buffer *info;
1109
1110         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1111         if (ret != 5) {
1112                 ErrPrint("Invalid packet\n");
1113                 goto out;
1114         }
1115
1116         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1117         if (!info) {
1118                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1119                 goto out;
1120         }
1121
1122         if (info->handler) {
1123                 int w;
1124                 int h;
1125
1126                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1127                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1128
1129                 (void)info->handler(info, BUFFER_EVENT_SCROLL_MOVE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1130         }
1131
1132 out:
1133         return NULL;
1134 }
1135
1136 struct packet *provider_buffer_pd_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
1137 {
1138         const char *pkgname;
1139         const char *id;
1140         double timestamp;
1141         int ret;
1142         int x;
1143         int y;
1144         struct livebox_buffer *info;
1145
1146         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1147         if (ret != 5) {
1148                 ErrPrint("Invalid packet\n");
1149                 goto out;
1150         }
1151
1152         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1153         if (!info) {
1154                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1155                 goto out;
1156         }
1157
1158         if (info->handler) {
1159                 int w;
1160                 int h;
1161
1162                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1163                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1164
1165                 (void)info->handler(info, BUFFER_EVENT_SCROLL_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1166         }
1167
1168 out:
1169         return NULL;
1170 }
1171
1172 struct packet *provider_buffer_pd_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
1173 {
1174         const char *pkgname;
1175         const char *id;
1176         double timestamp;
1177         int ret;
1178         int x;
1179         int y;
1180         struct livebox_buffer *info;
1181
1182         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1183         if (ret != 5) {
1184                 ErrPrint("Invalid packet\n");
1185                 goto out;
1186         }
1187
1188         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1189         if (!info) {
1190                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1191                 goto out;
1192         }
1193
1194         if (info->handler) {
1195                 int w;
1196                 int h;
1197
1198                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1199                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1200
1201                 (void)info->handler(info, BUFFER_EVENT_UNHIGHLIGHT, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1202         }
1203
1204 out:
1205         return NULL;
1206 }
1207
1208 struct packet *provider_buffer_pd_access_hl(pid_t pid, int handle, const struct packet *packet)
1209 {
1210         const char *pkgname;
1211         const char *id;
1212         double timestamp;
1213         int ret;
1214         int x;
1215         int y;
1216         struct livebox_buffer *info;
1217
1218         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1219         if (ret != 5) {
1220                 ErrPrint("Invalid packet\n");
1221                 goto out;
1222         }
1223
1224         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1225         if (!info) {
1226                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1227                 goto out;
1228         }
1229
1230         if (info->handler) {
1231                 int w;
1232                 int h;
1233
1234                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1235                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1236
1237                 (void)info->handler(info, BUFFER_EVENT_HIGHLIGHT, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1238         }
1239
1240 out:
1241         return NULL;
1242 }
1243
1244 struct packet *provider_buffer_pd_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
1245 {
1246         const char *pkgname;
1247         const char *id;
1248         double timestamp;
1249         int ret;
1250         int x;
1251         int y;
1252         struct livebox_buffer *info;
1253
1254         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1255         if (ret != 5) {
1256                 ErrPrint("Invalid packet\n");
1257                 goto out;
1258         }
1259
1260         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1261         if (!info) {
1262                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1263                 goto out;
1264         }
1265
1266         if (info->handler) {
1267                 int w;
1268                 int h;
1269
1270                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1271                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1272
1273                 (void)info->handler(info, BUFFER_EVENT_HIGHLIGHT_PREV, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1274         }
1275
1276 out:
1277         return NULL;
1278 }
1279
1280 struct packet *provider_buffer_pd_access_hl_next(pid_t pid, int handle, const struct packet *packet)
1281 {
1282         const char *pkgname;
1283         const char *id;
1284         double timestamp;
1285         int ret;
1286         int x;
1287         int y;
1288         struct livebox_buffer *info;
1289
1290         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1291         if (ret != 5) {
1292                 ErrPrint("Invalid packet\n");
1293                 goto out;
1294         }
1295
1296         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1297         if (!info) {
1298                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1299                 goto out;
1300         }
1301
1302         if (info->handler) {
1303                 int w;
1304                 int h;
1305
1306                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1307                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1308
1309                 (void)info->handler(info, BUFFER_EVENT_HIGHLIGHT_NEXT, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1310         }
1311
1312 out:
1313         return NULL;
1314 }
1315
1316 struct packet *provider_buffer_pd_access_activate(pid_t pid, int handle, const struct packet *packet)
1317 {
1318         const char *pkgname;
1319         const char *id;
1320         double timestamp;
1321         int ret;
1322         int x;
1323         int y;
1324         struct livebox_buffer *info;
1325
1326         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1327         if (ret != 5) {
1328                 ErrPrint("Invalid packet\n");
1329                 goto out;
1330         }
1331
1332         info = provider_buffer_find_buffer(TYPE_PD, pkgname, id);
1333         if (!info) {
1334                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1335                 goto out;
1336         }
1337
1338         if (info->handler) {
1339                 int w;
1340                 int h;
1341
1342                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1343                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1344
1345                 (void)info->handler(info, BUFFER_EVENT_ACTIVATE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1346         }
1347
1348 out:
1349         return NULL;
1350 }
1351
1352 struct packet *provider_buffer_lb_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
1353 {
1354         const char *pkgname;
1355         const char *id;
1356         double timestamp;
1357         int ret;
1358         int x;
1359         int y;
1360         struct livebox_buffer *info;
1361
1362         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1363         if (ret != 5) {
1364                 ErrPrint("Invalid packet\n");
1365                 goto out;
1366         }
1367
1368         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1369         if (!info) {
1370                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1371                 goto out;
1372         }
1373
1374         if (info->handler) {
1375                 int w;
1376                 int h;
1377
1378                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1379                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1380
1381                 (void)info->handler(info, BUFFER_EVENT_UNHIGHLIGHT, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1382         }
1383
1384 out:
1385         return NULL;
1386 }
1387
1388 struct packet *provider_buffer_lb_access_hl(pid_t pid, int handle, const struct packet *packet)
1389 {
1390         const char *pkgname;
1391         const char *id;
1392         double timestamp;
1393         int ret;
1394         int x;
1395         int y;
1396         struct livebox_buffer *info;
1397
1398         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1399         if (ret != 5) {
1400                 ErrPrint("Invalid packet\n");
1401                 goto out;
1402         }
1403
1404         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1405         if (!info) {
1406                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1407                 goto out;
1408         }
1409
1410         if (info->handler) {
1411                 int w;
1412                 int h;
1413
1414                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1415                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1416
1417                 (void)info->handler(info, BUFFER_EVENT_HIGHLIGHT, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1418         }
1419
1420 out:
1421         return NULL;
1422 }
1423
1424 struct packet *provider_buffer_lb_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
1425 {
1426         const char *pkgname;
1427         const char *id;
1428         double timestamp;
1429         int ret;
1430         int x;
1431         int y;
1432         struct livebox_buffer *info;
1433
1434         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1435         if (ret != 5) {
1436                 ErrPrint("Invalid packet\n");
1437                 goto out;
1438         }
1439
1440         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1441         if (!info) {
1442                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1443                 goto out;
1444         }
1445
1446         if (info->handler) {
1447                 int w;
1448                 int h;
1449
1450                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1451                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1452
1453                 (void)info->handler(info, BUFFER_EVENT_HIGHLIGHT_PREV, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1454         }
1455
1456 out:
1457         return NULL;
1458 }
1459
1460 struct packet *provider_buffer_lb_access_hl_next(pid_t pid, int handle, const struct packet *packet)
1461 {
1462         const char *pkgname;
1463         const char *id;
1464         double timestamp;
1465         int ret;
1466         int x;
1467         int y;
1468         struct livebox_buffer *info;
1469
1470         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1471         if (ret != 5) {
1472                 ErrPrint("Invalid packet\n");
1473                 goto out;
1474         }
1475
1476         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1477         if (!info) {
1478                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1479                 goto out;
1480         }
1481
1482         if (info->handler) {
1483                 int w;
1484                 int h;
1485
1486                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1487                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1488
1489                 (void)info->handler(info, BUFFER_EVENT_HIGHLIGHT_NEXT, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1490         }
1491
1492 out:
1493         return NULL;
1494 }
1495
1496 struct packet *provider_buffer_lb_access_action_up(pid_t pid, int handle, const struct packet *packet)
1497 {
1498         const char *pkgname;
1499         const char *id;
1500         double timestamp;
1501         int ret;
1502         int x;
1503         int y;
1504         struct livebox_buffer *info;
1505
1506         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1507         if (ret != 5) {
1508                 ErrPrint("Invalid packet\n");
1509                 goto out;
1510         }
1511
1512         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1513         if (!info) {
1514                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1515                 goto out;
1516         }
1517
1518         if (info->handler) {
1519                 int w;
1520                 int h;
1521
1522                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1523                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1524
1525                 (void)info->handler(info, BUFFER_EVENT_ACTION_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1526         }
1527
1528 out:
1529         return NULL;
1530 }
1531
1532 struct packet *provider_buffer_lb_access_action_down(pid_t pid, int handle, const struct packet *packet)
1533 {
1534         const char *pkgname;
1535         const char *id;
1536         double timestamp;
1537         int ret;
1538         int x;
1539         int y;
1540         struct livebox_buffer *info;
1541
1542         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1543         if (ret != 5) {
1544                 ErrPrint("Invalid packet\n");
1545                 goto out;
1546         }
1547
1548         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1549         if (!info) {
1550                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1551                 goto out;
1552         }
1553
1554         if (info->handler) {
1555                 int w;
1556                 int h;
1557
1558                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1559                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1560
1561                 (void)info->handler(info, BUFFER_EVENT_ACTION_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1562         }
1563
1564 out:
1565         return NULL;
1566 }
1567
1568 struct packet *provider_buffer_lb_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
1569 {
1570         const char *pkgname;
1571         const char *id;
1572         double timestamp;
1573         int ret;
1574         int x;
1575         int y;
1576         struct livebox_buffer *info;
1577
1578         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1579         if (ret != 5) {
1580                 ErrPrint("Invalid packet\n");
1581                 goto out;
1582         }
1583
1584         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1585         if (!info) {
1586                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1587                 goto out;
1588         }
1589
1590         if (info->handler) {
1591                 int w;
1592                 int h;
1593
1594                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1595                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1596
1597                 (void)info->handler(info, BUFFER_EVENT_SCROLL_DOWN, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1598         }
1599
1600 out:
1601         return NULL;
1602 }
1603
1604 struct packet *provider_buffer_lb_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
1605 {
1606         const char *pkgname;
1607         const char *id;
1608         double timestamp;
1609         int ret;
1610         int x;
1611         int y;
1612         struct livebox_buffer *info;
1613
1614         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1615         if (ret != 5) {
1616                 ErrPrint("Invalid packet\n");
1617                 goto out;
1618         }
1619
1620         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1621         if (!info) {
1622                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1623                 goto out;
1624         }
1625
1626         if (info->handler) {
1627                 int w;
1628                 int h;
1629
1630                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1631                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1632
1633                 (void)info->handler(info, BUFFER_EVENT_SCROLL_MOVE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1634         }
1635
1636 out:
1637         return NULL;
1638 }
1639
1640 struct packet *provider_buffer_lb_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
1641 {
1642         const char *pkgname;
1643         const char *id;
1644         double timestamp;
1645         int ret;
1646         int x;
1647         int y;
1648         struct livebox_buffer *info;
1649
1650         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1651         if (ret != 5) {
1652                 ErrPrint("Invalid packet\n");
1653                 goto out;
1654         }
1655
1656         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1657         if (!info) {
1658                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1659                 goto out;
1660         }
1661
1662         if (info->handler) {
1663                 int w;
1664                 int h;
1665
1666                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1667                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1668
1669                 (void)info->handler(info, BUFFER_EVENT_SCROLL_UP, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1670         }
1671
1672 out:
1673         return NULL;
1674 }
1675
1676 struct packet *provider_buffer_lb_access_activate(pid_t pid, int handle, const struct packet *packet)
1677 {
1678         const char *pkgname;
1679         const char *id;
1680         double timestamp;
1681         int ret;
1682         int x;
1683         int y;
1684         struct livebox_buffer *info;
1685
1686         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1687         if (ret != 5) {
1688                 ErrPrint("Invalid packet\n");
1689                 goto out;
1690         }
1691
1692         info = provider_buffer_find_buffer(TYPE_LB, pkgname, id);
1693         if (!info) {
1694                 ErrPrint("Failed to find a buffer [%s:%s]\n", pkgname, id);
1695                 goto out;
1696         }
1697
1698         if (info->handler) {
1699                 int w;
1700                 int h;
1701
1702                 if (provider_buffer_get_size(info, &w, &h, NULL) < 0)
1703                         ErrPrint("Failed to get buffer size[%s:%s]\n", pkgname, id);
1704
1705                 (void)info->handler(info, BUFFER_EVENT_ACTIVATE, timestamp, (double)x / (double)w, (double)y / (double)h, info->data);
1706         }
1707
1708 out:
1709         return NULL;
1710 }
1711
1712 /* End of a file */