OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 // Author: thorcarpenter@google.com (Thor Carpenter) | |
12 // | |
13 // Defines variant class ScreencastId that combines WindowId and DesktopId. | |
14 | |
15 #ifndef WEBRTC_MEDIA_BASE_SCREENCASTID_H_ | |
16 #define WEBRTC_MEDIA_BASE_SCREENCASTID_H_ | |
17 | |
18 #include <string> | |
19 #include <vector> | |
20 | |
21 #include "webrtc/base/window.h" | |
22 #include "webrtc/base/windowpicker.h" | |
23 | |
24 namespace cricket { | |
25 | |
26 class ScreencastId; | |
27 typedef std::vector<ScreencastId> ScreencastIdList; | |
28 | |
29 // Used for identifying a window or desktop to be screencast. | |
30 class ScreencastId { | |
31 public: | |
32 enum Type { INVALID, WINDOW, DESKTOP }; | |
33 | |
34 // Default constructor indicates invalid ScreencastId. | |
35 ScreencastId() : type_(INVALID) {} | |
36 explicit ScreencastId(const rtc::WindowId& id) | |
37 : type_(WINDOW), window_(id) { | |
38 } | |
39 explicit ScreencastId(const rtc::DesktopId& id) | |
40 : type_(DESKTOP), desktop_(id) { | |
41 } | |
42 | |
43 Type type() const { return type_; } | |
44 const rtc::WindowId& window() const { return window_; } | |
45 const rtc::DesktopId& desktop() const { return desktop_; } | |
46 | |
47 // Title is an optional parameter. | |
48 const std::string& title() const { return title_; } | |
49 void set_title(const std::string& desc) { title_ = desc; } | |
50 | |
51 bool IsValid() const { | |
52 if (type_ == INVALID) { | |
53 return false; | |
54 } else if (type_ == WINDOW) { | |
55 return window_.IsValid(); | |
56 } else { | |
57 return desktop_.IsValid(); | |
58 } | |
59 } | |
60 bool IsWindow() const { return type_ == WINDOW; } | |
61 bool IsDesktop() const { return type_ == DESKTOP; } | |
62 bool EqualsId(const ScreencastId& other) const { | |
63 if (type_ != other.type_) { | |
64 return false; | |
65 } | |
66 if (type_ == INVALID) { | |
67 return true; | |
68 } else if (type_ == WINDOW) { | |
69 return window_.Equals(other.window()); | |
70 } | |
71 return desktop_.Equals(other.desktop()); | |
72 } | |
73 | |
74 // T is assumed to be WindowDescription or DesktopDescription. | |
75 template<class T> | |
76 static cricket::ScreencastIdList Convert(const std::vector<T>& list) { | |
77 ScreencastIdList screencast_list; | |
78 screencast_list.reserve(list.size()); | |
79 for (typename std::vector<T>::const_iterator it = list.begin(); | |
80 it != list.end(); ++it) { | |
81 ScreencastId id(it->id()); | |
82 id.set_title(it->title()); | |
83 screencast_list.push_back(id); | |
84 } | |
85 return screencast_list; | |
86 } | |
87 | |
88 private: | |
89 Type type_; | |
90 rtc::WindowId window_; | |
91 rtc::DesktopId desktop_; | |
92 std::string title_; // Optional. | |
93 }; | |
94 | |
95 } // namespace cricket | |
96 | |
97 #endif // WEBRTC_MEDIA_BASE_SCREENCASTID_H_ | |
OLD | NEW |