2 Copyright (C) 2009 Red Hat, Inc.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #ifndef _H_FOREIGN_MENU
19 #define _H_FOREIGN_MENU
21 #include "named_pipe.h"
24 class ForeignMenuConnection;
28 class ForeignMenuInterface : public CommandTarget {
30 virtual ~ForeignMenuInterface() {}
32 virtual int get_foreign_menu_item_id(int32_t opaque_conn_ref, uint32_t msg_id) = 0;
33 virtual void clear_menu_items(int32_t opaque_conn_ref) = 0;
34 virtual void remove_menu_item(int item_id) = 0;
35 virtual Menu* get_app_menu() = 0;
36 virtual void update_menu() = 0;
39 class ForeignMenu : public NamedPipe::ListenerInterface {
41 ForeignMenu(ForeignMenuInterface *handler, bool active = false);
42 virtual ~ForeignMenu();
44 ForeignMenu* ref() { _refs++; return this;}
45 void unref() { if (!--_refs) delete this;}
47 virtual NamedPipe::ConnectionInterface &create();
48 void add_connection(NamedPipe::ConnectionRef conn_ref, ForeignMenuConnection *conn);
49 void remove_connection(NamedPipe::ConnectionRef conn_ref);
51 void on_command(NamedPipe::ConnectionRef conn_ref, int32_t id);
56 void send_active_state(ForeignMenuConnection *conn, int32_t cmd);
59 ForeignMenuInterface *_handler;
60 std::map<NamedPipe::ConnectionRef, ForeignMenuConnection*> _connections;
61 NamedPipe::ListenerRef _foreign_menu;
66 #define FOREIGN_MENU_BUF_SIZE 4096
68 class ForeignMenuConnection : public NamedPipe::ConnectionInterface {
70 ForeignMenuConnection(ForeignMenuInterface *handler, ForeignMenu& parent);
71 virtual ~ForeignMenuConnection();
73 virtual void bind(NamedPipe::ConnectionRef conn_ref);
74 virtual void on_data();
75 bool write_msg(const void *buf, int len);
76 void reset_handler() { _handler = NULL;}
81 bool handle_init(FrgMenuInit *init);
82 bool handle_message(FrgMenuMsg *hdr);
83 int get_item_state(int item_type);
86 ForeignMenuInterface *_handler;
93 uint8_t _write_buf[FOREIGN_MENU_BUF_SIZE];
94 uint8_t _read_buf[FOREIGN_MENU_BUF_SIZE];
95 RecurciveMutex _write_lock;