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.
6 #ifndef XWALK_TIZEN_MOBILE_UI_TIZEN_SYSTEM_INDICATOR_WATCHER_H_
7 #define XWALK_TIZEN_MOBILE_UI_TIZEN_SYSTEM_INDICATOR_WATCHER_H_
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"
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 {
29 virtual void OnImageUpdated(const gfx::ImageSkia& img_skia) = 0;
32 virtual ~WatcherClient() {}
35 TizenSystemIndicatorWatcher(WatcherClient* client,
36 const gfx::Display& display);
37 virtual ~TizenSystemIndicatorWatcher();
39 // base::MessagePumpLibevent::Watcher implementation.
40 void OnFileCanReadWithoutBlocking(int fd) override;
41 void OnFileCanWriteWithoutBlocking(int fd) override;
47 void OnMouseDown(int x, int y);
49 void OnMouseMove(int x, int y);
51 gfx::Size GetSize() const;
54 size_t GetHeaderSize(unsigned int header_instructions);
55 bool UpdateMessageHeader(unsigned int header_instructions,
56 uint8_t* header_payload);
58 bool MapSharedMemory();
59 bool OnResize(const uint8_t* payload, size_t size);
62 bool OnShmRef(const uint8_t* payload, size_t size);
63 bool ProcessPayload();
64 void UpdateIndicatorImage();
65 void SetSizeFromEnvVar();
66 void ResizeIndicator();
68 WatcherClient* client_;
69 gfx::Display display_;
71 TizenPlugMessageWriter writer_;
74 base::ScopedFD fd_closer_;
75 base::MessagePumpLibevent::FileDescriptorWatcher fd_watcher_;
77 scoped_ptr<base::SharedMemory> shared_memory_;
83 std::string shm_name_;
84 std::string service_name_;
85 struct EcoreIPCMsgHeader current_msg_header_;
87 base::WeakPtrFactory<TizenSystemIndicatorWatcher> weak_ptr_factory_;
89 DISALLOW_COPY_AND_ASSIGN(TizenSystemIndicatorWatcher);
94 #endif // XWALK_TIZEN_MOBILE_UI_TIZEN_SYSTEM_INDICATOR_WATCHER_H_