blob: d1f84f3354c5ca0a22c6c2a1b8a77dabe9b2d28c [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001// Copyright 2012 Google Inc.
2// Author: thorcarpenter@google.com (Thor Carpenter)
3//
4// Defines variant class ScreencastId that combines WindowId and DesktopId.
5
6#ifndef TALK_MEDIA_BASE_SCREENCASTID_H_
7#define TALK_MEDIA_BASE_SCREENCASTID_H_
8
9#include <string>
10#include <vector>
11
12#include "talk/base/window.h"
13#include "talk/base/windowpicker.h"
14
15namespace cricket {
16
17class ScreencastId;
18typedef std::vector<ScreencastId> ScreencastIdList;
19
20// Used for identifying a window or desktop to be screencast.
21class ScreencastId {
22 public:
23 enum Type { INVALID, WINDOW, DESKTOP };
24
25 // Default constructor indicates invalid ScreencastId.
26 ScreencastId() : type_(INVALID) {}
27 explicit ScreencastId(const talk_base::WindowId& id)
28 : type_(WINDOW), window_(id) {
29 }
30 explicit ScreencastId(const talk_base::DesktopId& id)
31 : type_(DESKTOP), desktop_(id) {
32 }
33
34 Type type() const { return type_; }
35 const talk_base::WindowId& window() const { return window_; }
36 const talk_base::DesktopId& desktop() const { return desktop_; }
37
38 // Title is an optional parameter.
39 const std::string& title() const { return title_; }
40 void set_title(const std::string& desc) { title_ = desc; }
41
42 bool IsValid() const {
43 if (type_ == INVALID) {
44 return false;
45 } else if (type_ == WINDOW) {
46 return window_.IsValid();
47 } else {
48 return desktop_.IsValid();
49 }
50 }
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_) {
55 return false;
56 }
57 if (type_ == INVALID) {
58 return true;
59 } else if (type_ == WINDOW) {
60 return window_.Equals(other.window());
61 }
62 return desktop_.Equals(other.desktop());
63 }
64
65 // T is assumed to be WindowDescription or DesktopDescription.
66 template<class T>
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);
75 }
76 return screencast_list;
77 }
78
79 private:
80 Type type_;
81 talk_base::WindowId window_;
82 talk_base::DesktopId desktop_;
83 std::string title_; // Optional.
84};
85
86} // namespace cricket
87
88#endif // TALK_MEDIA_BASE_SCREENCASTID_H_