Key down/up event path added
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 25 Jan 2013 07:42:48 +0000 (07:42 +0000)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 25 Jan 2013 07:42:48 +0000 (07:42 +0000)
Change-Id: Iff30c273203e6dbc3dcf25c388806b5e55bdccf8

src/server.c

index ac13fe3..d896eb8 100644 (file)
@@ -2219,6 +2219,238 @@ out:
        return NULL;
 }
 
+static struct packet *client_pd_key_down(pid_t pid, int handle, const struct packet *packet)
+{
+       struct client_node *client;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+       const struct pkg_info *pkg;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Invalid parameter\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /*!
+        * \NOTE:
+        * Trust the package name which are sent by the client.
+        * The package has to be a livebox package name.
+        */
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ErrPrint("Instance[%s] is not exists\n", id);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       pkg = instance_package(inst);
+       if (!pkg) {
+               ErrPrint("Package[%s] info is not found\n", pkgname);
+               ret = -EFAULT;
+               goto out;
+       }
+
+       if (package_is_fault(pkg)) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               DbgPrint("Package[%s] is faulted\n", pkgname);
+               ret = -EFAULT;
+       } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
+               struct buffer_info *buffer;
+               struct slave_node *slave;
+               // struct packet *packet;
+
+               buffer = instance_pd_buffer(inst);
+               if (!buffer) {
+                       ErrPrint("Instance[%s] has no buffer\n", id);
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               slave = package_slave(pkg);
+               if (!slave) {
+                       ErrPrint("Package[%s] has no slave\n", pkgname);
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               /*
+               packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
+               if (!packet) {
+                       ErrPrint("Failed to create a packet[%s]\n", pkgname);
+                       ret = -EFAULT;
+                       goto out;
+               }
+               */
+
+               packet_ref((struct packet *)packet);
+               ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
+       } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_pd_script(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, -1);
+               /*!
+                * \TODO: Push up the KEY_DOWN event
+                */
+               ret = 0;
+       } else {
+               ErrPrint("Unsupported package\n");
+               ret = -EINVAL;
+       }
+
+out:
+       /*! \note No reply packet */
+       return NULL;
+}
+
+static struct packet *client_pd_key_up(pid_t pid, int handle, const struct packet *packet)
+{
+       struct client_node *client;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+       const struct pkg_info *pkg;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Invalid parameter\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /*!
+        * \NOTE:
+        * Trust the package name which are sent by the client.
+        * The package has to be a livebox package name.
+        */
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ErrPrint("Instance[%s] is not exists\n", id);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       pkg = instance_package(inst);
+       if (!pkg) {
+               ErrPrint("Package[%s] info is not found\n", pkgname);
+               ret = -EFAULT;
+               goto out;
+       }
+
+       if (package_is_fault(pkg)) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               DbgPrint("Package[%s] is faulted\n", pkgname);
+               ret = -EFAULT;
+       } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
+               struct buffer_info *buffer;
+               struct slave_node *slave;
+               // struct packet *packet;
+
+               buffer = instance_pd_buffer(inst);
+               if (!buffer) {
+                       ErrPrint("Instance[%s] has no buffer\n", id);
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               slave = package_slave(pkg);
+               if (!slave) {
+                       ErrPrint("Package[%s] has no slave\n", pkgname);
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               /*
+               packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
+               if (!packet) {
+                       ErrPrint("Failed to create a packet[%s]\n", pkgname);
+                       ret = -EFAULT;
+                       goto out;
+               }
+               */
+
+               packet_ref((struct packet *)packet);
+               ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
+       } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_pd_script(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, -1);
+               /*!
+                * \TODO: Push up the KEY_UP event
+                */
+               ret = 0;
+       } else {
+               ErrPrint("Unsupported package\n");
+               ret = -EINVAL;
+       }
+
+out:
+       /*! \note No reply packet */
+       return NULL;
+}
+
 static struct packet *client_lb_access_read(pid_t pid, int handle, const struct packet *packet)
 {
        struct client_node *client;
@@ -2687,6 +2919,240 @@ out:
        return NULL;
 }
 
+static struct packet *client_lb_key_down(pid_t pid, int handle, const struct packet *packet)
+{
+       struct client_node *client;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+       const struct pkg_info *pkg;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /*!
+        * \NOTE:
+        * Trust the package name which are sent by the client.
+        * The package has to be a livebox package name.
+        */
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ErrPrint("Instance[%s] is not exists\n", id);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       pkg = instance_package(inst);
+       if (!pkg) {
+               ErrPrint("Package[%s] info is not exists\n", pkgname);
+               ret = -EFAULT;
+               goto out;
+       }
+
+       if (package_is_fault(pkg)) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               DbgPrint("Package[%s] is faulted\n", pkgname);
+               ret = -EFAULT;
+       } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
+               struct buffer_info *buffer;
+               struct slave_node *slave;
+               //struct packet *packet;
+
+               buffer = instance_lb_buffer(inst);
+               if (!buffer) {
+                       ErrPrint("Instance[%s] has no buffer\n", id);
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               slave = package_slave(pkg);
+               if (!slave) {
+                       ErrPrint("Package[%s] has no slave\n", pkgname);
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               /*
+               packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
+               if (!packet) {
+                       ErrPrint("Failed to create a packet[%s]\n", pkgname);
+                       ret = -EFAULT;
+                       goto out;
+               }
+               */
+
+               packet_ref((struct packet *)packet);
+               ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
+       } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_lb_script(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, -1);
+
+               /*!
+                * \TODO: Feed up this KEY_DOWN event
+                */
+               ret = 0;
+       } else {
+               ErrPrint("Unsupported package\n");
+               ret = -EINVAL;
+       }
+
+out:
+       /*! \note No reply packet */
+       return NULL;
+}
+
+static struct packet *client_lb_key_up(pid_t pid, int handle, const struct packet *packet)
+{
+       struct client_node *client;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+       const struct pkg_info *pkg;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /*!
+        * \NOTE:
+        * Trust the package name which are sent by the client.
+        * The package has to be a livebox package name.
+        */
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ErrPrint("Instance[%s] is not exists\n", id);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       pkg = instance_package(inst);
+       if (!pkg) {
+               ErrPrint("Package[%s] info is not exists\n", pkgname);
+               ret = -EFAULT;
+               goto out;
+       }
+
+       if (package_is_fault(pkg)) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               DbgPrint("Package[%s] is faulted\n", pkgname);
+               ret = -EFAULT;
+       } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
+               struct buffer_info *buffer;
+               struct slave_node *slave;
+               //struct packet *packet;
+
+               buffer = instance_lb_buffer(inst);
+               if (!buffer) {
+                       ErrPrint("Instance[%s] has no buffer\n", id);
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               slave = package_slave(pkg);
+               if (!slave) {
+                       ErrPrint("Package[%s] has no slave\n", pkgname);
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               /*
+               packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
+               if (!packet) {
+                       ErrPrint("Failed to create a packet[%s]\n", pkgname);
+                       ret = -EFAULT;
+                       goto out;
+               }
+               */
+
+               packet_ref((struct packet *)packet);
+               ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
+       } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_lb_script(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, -1);
+
+               /*!
+                * \TODO: Feed up this KEY_UP event
+                */
+               ret = 0;
+       } else {
+               ErrPrint("Unsupported package\n");
+               ret = -EINVAL;
+       }
+
+out:
+       /*! \note No reply packet */
+       return NULL;
+}
+
 static int release_pixmap_cb(struct client_node *client, void *canvas)
 {
        DbgPrint("Forcely unref the \"buffer\"\n");
@@ -4676,6 +5142,24 @@ static struct method s_client_table[] = {
        },
 
        {
+               .cmd = "lb_key_down",
+               .handler = client_lb_key_down,
+       },
+       {
+               .cmd = "lb_key_up",
+               .handler = client_lb_key_up,
+       },
+
+       {
+               .cmd = "pd_key_down",
+               .handler = client_pd_key_down,
+       },
+       {
+               .cmd = "pd_key_up",
+               .handler = client_pd_key_up,
+       },
+
+       {
                .cmd = NULL,
                .handler = NULL,
        },