1 // Copyright 2012 Google Inc.
2 // Author: thorcarpenter@google.com (Thor Carpenter)
4 // Defines variant class ScreencastId that combines WindowId and DesktopId.
6 #ifndef TALK_MEDIA_BASE_SCREENCASTID_H_
7 #define TALK_MEDIA_BASE_SCREENCASTID_H_
12 #include "webrtc/base/window.h"
13 #include "webrtc/base/windowpicker.h"
18 typedef std::vector<ScreencastId> ScreencastIdList;
20 // Used for identifying a window or desktop to be screencast.
23 enum Type { INVALID, WINDOW, DESKTOP };
25 // Default constructor indicates invalid ScreencastId.
26 ScreencastId() : type_(INVALID) {}
27 explicit ScreencastId(const rtc::WindowId& id)
28 : type_(WINDOW), window_(id) {
30 explicit ScreencastId(const rtc::DesktopId& id)
31 : type_(DESKTOP), desktop_(id) {
34 Type type() const { return type_; }
35 const rtc::WindowId& window() const { return window_; }
36 const rtc::DesktopId& desktop() const { return desktop_; }
38 // Title is an optional parameter.
39 const std::string& title() const { return title_; }
40 void set_title(const std::string& desc) { title_ = desc; }
42 bool IsValid() const {
43 if (type_ == INVALID) {
45 } else if (type_ == WINDOW) {
46 return window_.IsValid();
48 return desktop_.IsValid();
51 bool IsWindow() const { return type_ == WINDOW; }
52 bool IsDesktop() const { return type_ == DESKTOP; }
53 bool EqualsId(const ScreencastId& other) const {
54 if (type_ != other.type_) {
57 if (type_ == INVALID) {
59 } else if (type_ == WINDOW) {
60 return window_.Equals(other.window());
62 return desktop_.Equals(other.desktop());
65 // T is assumed to be WindowDescription or DesktopDescription.
67 static cricket::ScreencastIdList Convert(const std::vector<T>& list) {
68 ScreencastIdList screencast_list;
69 screencast_list.reserve(list.size());
70 for (typename std::vector<T>::const_iterator it = list.begin();
71 it != list.end(); ++it) {
72 ScreencastId id(it->id());
73 id.set_title(it->title());
74 screencast_list.push_back(id);
76 return screencast_list;
81 rtc::WindowId window_;
82 rtc::DesktopId desktop_;
83 std::string title_; // Optional.
86 } // namespace cricket
88 #endif // TALK_MEDIA_BASE_SCREENCASTID_H_