BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / terminal / TerminalRoster.h
blob26ad8a40349eb03c72508bdb5ca55da28e4fbca3
1 /*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef TERMINAL_ROSTER_H
6 #define TERMINAL_ROSTER_H
9 #include <Clipboard.h>
10 #include <Handler.h>
11 #include <Locker.h>
13 #include <ObjectList.h>
16 /*! Provides access to the (virtual) global terminal roster.
18 Register() registers our terminal with the roster and establishes the link
19 to the roster. From then on CountTerminals() and TerminalAt() provide
20 access to the terminal list and allows to post our window status via
21 SetWindowInfo(). The list is automatically kept up to date. Unregister()
22 will remove our terminal from the roster and terminate the connection.
24 A single Listener can be set. It is notified whenever the terminal list
25 has changed.
27 class TerminalRoster : private BHandler {
28 public:
29 class Listener;
31 public:
32 struct Info {
33 int32 id;
34 team_id team;
35 uint32 workspaces;
36 bool minimized;
38 public:
39 Info(int32 id, team_id team);
40 Info(const BMessage& archive);
42 status_t Archive(BMessage& archive) const;
44 bool operator==(const Info& other) const;
45 bool operator!=(const Info& other) const
46 { return !(*this == other); }
49 public:
50 TerminalRoster();
52 bool Lock();
53 void Unlock();
55 status_t Register(team_id teamID, BLooper* looper);
56 void Unregister();
57 bool IsRegistered() const
58 { return fOurInfo != NULL; }
60 int32 ID() const;
62 void SetWindowInfo(bool minimized,
63 uint32 workspaces);
65 // roster must be locked
66 int32 CountTerminals() const
67 { return fInfos.CountItems(); }
68 const Info* TerminalAt(int32 index) const
69 { return fInfos.ItemAt(index); }
71 void SetListener(Listener* listener)
72 { fListener = listener; }
74 private:
75 // BHandler
76 virtual void MessageReceived(BMessage* message);
78 private:
79 typedef BObjectList<Info> InfoList;
81 private:
82 status_t _UpdateInfos(bool checkApps);
83 status_t _UpdateClipboard();
85 void _NotifyListener();
87 static int _CompareInfos(const Info* a, const Info* b);
88 static int _CompareIDInfo(const int32* id,
89 const Info* info);
91 bool _TeamIsRunning(team_id teamID);
93 private:
94 BLocker fLock;
95 BClipboard fClipboard;
96 InfoList fInfos;
97 Info* fOurInfo;
98 bigtime_t fLastCheckedTime;
99 Listener* fListener;
100 bool fInfosUpdated;
104 class TerminalRoster::Listener {
105 public:
106 virtual ~Listener();
108 virtual void TerminalInfosUpdated(TerminalRoster* roster)
109 = 0;
113 #endif // TERMINAL_ROSTER_H