Merge branch 'sandbox/knimitz/fix_set_role'
[apps/agl-service-windowmanager.git] / src / window_manager.hpp
index afafeb1..6811110 100644 (file)
 #include <memory>
 #include <unordered_map>
 #include <experimental/optional>
-#include "controller_hooks.hpp"
-//#include "layers.hpp"
-// #include "layout.hpp"
-//#include "wayland_ivi_wm.hpp"
 #include "result.hpp"
 #include "pm_wrapper.hpp"
 #include "util.hpp"
@@ -38,16 +34,6 @@ extern "C"
 
 struct json_object;
 
-namespace wl
-{
-struct display;
-}
-
-namespace compositor
-{
-struct controller;
-}
-
 namespace wm
 {
 
@@ -143,6 +129,23 @@ struct id_allocator
     }
 };
 
+struct TmpClient
+{
+    std::string   appid;
+    unsigned pid;
+};
+
+struct TmpService
+{
+    std::string appid;  // Used to search who create service surface
+    std::string dest;   // Used to attach service to destination application
+    std::string service;// The name of service surface
+    std::string uuid;   // uuid
+    TmpService(const std::string& app, const std::string& dst,
+               const std::string& svc, const std::string& uuid)
+    : appid(app), dest(dst), service(svc), uuid(uuid) {}
+};
+
 class WindowManager
 {
   public:
@@ -169,29 +172,6 @@ class WindowManager
         Event_Val_Max = Event_Error,
     };
 
-    const std::vector<const char *> kListEventName{
-        "active",
-        "inactive",
-        "visible",
-        "invisible",
-        "syncDraw",
-        "flushDraw",
-        "screenUpdated",
-        "error"};
-
-    struct controller_hooks chooks;
-
-    // ID allocation and proxy methods for lookup
-    struct id_allocator id_alloc;
-
-    std::map<const char *, struct afb_event> map_afb_event;
-
-    // Surface are info (x, y, w, h)
-    rect_map area_info;
-
-    // FOR CES DEMO
-    std::vector<int> surface_bg;
-
     explicit WindowManager();
     ~WindowManager() = default;
 
@@ -204,20 +184,20 @@ class WindowManager
 
     result<int> api_request_surface(char const *appid, char const *role);
     char const *api_request_surface(char const *appid, char const *role, char const *ivi_id);
-    bool api_set_role(char const *appid, char const *role, unsigned pid);
+    bool api_set_role(char const *appid, char const *role);
     void api_activate_surface(char const *appid, char const *role, char const *drawing_area, const reply_func &reply);
     void api_deactivate_surface(char const *appid, char const *role, const reply_func &reply);
     void api_enddraw(char const *appid, char const *role);
+    bool api_client_set_render_order(const char *appid, const std::vector<std::string> &render_order);
+    std::string api_client_attach_service_surface(const char* appid, const char* dest, const char* service_surface);
     result<json_object *> api_get_display_info();
     result<json_object *> api_get_area_info(char const *role);
-    void api_ping();
     void send_event(char const *evname, char const *label);
     void send_event(char const *evname, char const *label, char const *area, int x, int y, int w, int h);
 
     // Events from the compositor we are interested in
-    void surface_created(uint32_t surface_id);
-    void surface_removed(uint32_t surface_id);
-    void surface_properties(uint32_t surface_id, uint32_t pid);
+    void surface_created(unsigned pid, unsigned surface_id);
+    void surface_removed(unsigned surface_id);
 
     void removeClient(const std::string &appid);
     void exceptionProcessForTransition();
@@ -227,14 +207,21 @@ class WindowManager
     void timerHandler();
     void startTransitionWrapper(std::vector<WMAction> &actions);
     void processError(WMError error);
+    std::string searchApp(unsigned pid, unsigned ppid, unsigned surface, json_object* resp);
+    void storeSurface(const std::string& appid, unsigned ppid, unsigned surface);
 
-  private:
-    optional<int> lookup_id(char const *name);
-    optional<std::string> lookup_name(int id);
-    int init_layers();
-    void surface_set_layout(int surface_id, const std::string& area = "");
-    void layout_commit();
+    const std::vector<const char *> kListEventName{
+        "active",
+        "inactive",
+        "visible",
+        "invisible",
+        "syncDraw",
+        "flushDraw",
+        "screenUpdated",
+        "error"};
+    std::map<const char *, struct afb_event> map_afb_event;
 
+  private:
     // WM Events to clients
     void emit_activated(char const *label);
     void emit_deactivated(char const *label);
@@ -249,14 +236,10 @@ class WindowManager
     void deactivate(int id);
     WMError setRequest(const std::string &appid, const std::string &role, const std::string &area,
                              Task task, unsigned *req_num);
-    WMError doTransition(unsigned sequence_number);
     WMError checkPolicy(unsigned req_num);
     WMError startTransition(unsigned req_num);
 
     WMError doEndDraw(unsigned req_num);
-    WMError layoutChange(const WMAction &action);
-    WMError visibilityChange(const WMAction &action);
-    WMError setSurfaceSize(unsigned surface, const std::string& area);
     void    emitScreenUpdated(unsigned req_num);
 
     void setTimer();
@@ -268,12 +251,18 @@ class WindowManager
     const char *check_surface_exist(const char *role);
 
   private:
-    std::unordered_map<std::string, struct rect> area2size;
     std::unordered_map<std::string, std::string> roleold2new;
     std::unordered_map<std::string, std::string> rolenew2old;
     std::shared_ptr<LayerControl> lc;
     PMWrapper pmw;
 
+    // ID allocation and proxy methods for lookup
+    struct id_allocator id_alloc;
+    // Surface are info (x, y, w, h)
+    rect_map area_info;
+    // FOR CES DEMO
+    std::unordered_map<unsigned, struct TmpClient> tmp_surface2app;
+    std::vector<struct TmpService> tmp_services;
     static const char* kDefaultOldRoleDb;
 };