Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / tizen / mobile / ui / tizen_system_indicator_watcher.h
1 // Copyright (C) 2000-2011 Carsten Haitzler and various contributors.
2 // Copyright (c) 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef XWALK_TIZEN_MOBILE_UI_TIZEN_SYSTEM_INDICATOR_WATCHER_H_
7 #define XWALK_TIZEN_MOBILE_UI_TIZEN_SYSTEM_INDICATOR_WATCHER_H_
8
9 #include <string>
10 #include "base/files/file_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_pump_libevent.h"
15 #include "ui/gfx/display.h"
16 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/size.h"
18 #include "xwalk/tizen/mobile/ui/tizen_plug_message_writer.h"
19
20 namespace xwalk {
21
22 // Implementation of the socket protocol for sharing memory used by Elementary
23 // "Plugs" in EFL. This class implements the low level protocol and is used by
24 // TizenSystemIndicator to update its image.
25 class TizenSystemIndicatorWatcher : public base::MessagePumpLibevent::Watcher {
26  public:
27   class WatcherClient {
28    public:
29     virtual void OnImageUpdated(const gfx::ImageSkia& img_skia) = 0;
30
31    protected:
32     virtual ~WatcherClient() {}
33   };
34
35   TizenSystemIndicatorWatcher(WatcherClient* client,
36                               const gfx::Display& display);
37   virtual ~TizenSystemIndicatorWatcher();
38
39   // base::MessagePumpLibevent::Watcher implementation.
40   void OnFileCanReadWithoutBlocking(int fd) override;
41   void OnFileCanWriteWithoutBlocking(int fd) override;
42
43   void StartWatching();
44   void StopWatching();
45   bool Connect();
46
47   void OnMouseDown(int x, int y);
48   void OnMouseUp();
49   void OnMouseMove(int x, int y);
50
51   gfx::Size GetSize() const;
52
53  private:
54   size_t GetHeaderSize(unsigned int header_instructions);
55   bool UpdateMessageHeader(unsigned int header_instructions,
56                            uint8_t* header_payload);
57   bool GetHeader();
58   bool MapSharedMemory();
59   bool OnResize(const uint8_t* payload, size_t size);
60   bool OnUpdate();
61   bool OnUpdateDone();
62   bool OnShmRef(const uint8_t* payload, size_t size);
63   bool ProcessPayload();
64   void UpdateIndicatorImage();
65   void SetSizeFromEnvVar();
66   void ResizeIndicator();
67
68   WatcherClient* client_;
69   gfx::Display display_;
70
71   TizenPlugMessageWriter writer_;
72
73   int fd_;
74   base::ScopedFD fd_closer_;
75   base::MessagePumpLibevent::FileDescriptorWatcher fd_watcher_;
76
77   scoped_ptr<base::SharedMemory> shared_memory_;
78
79   int width_;
80   int height_;
81   int alpha_;
82   bool updated_;
83   std::string shm_name_;
84   std::string service_name_;
85   struct EcoreIPCMsgHeader current_msg_header_;
86
87   base::WeakPtrFactory<TizenSystemIndicatorWatcher> weak_ptr_factory_;
88
89   DISALLOW_COPY_AND_ASSIGN(TizenSystemIndicatorWatcher);
90 };
91
92 }  // namespace xwalk
93
94 #endif  // XWALK_TIZEN_MOBILE_UI_TIZEN_SYSTEM_INDICATOR_WATCHER_H_