1 /*
2  * libjingle
3  * Copyright 2012 Google Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *  1. Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  *  3. The name of the author may not be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 // Author: thorcarpenter@google.com (Thor Carpenter)
29 //
30 // Defines variant class ScreencastId that combines WindowId and DesktopId.
31 
32 #ifndef TALK_MEDIA_BASE_SCREENCASTID_H_
33 #define TALK_MEDIA_BASE_SCREENCASTID_H_
34 
35 #include <string>
36 #include <vector>
37 
38 #include "webrtc/base/window.h"
39 #include "webrtc/base/windowpicker.h"
40 
41 namespace cricket {
42 
43 class ScreencastId;
44 typedef std::vector<ScreencastId> ScreencastIdList;
45 
46 // Used for identifying a window or desktop to be screencast.
47 class ScreencastId {
48  public:
49   enum Type { INVALID, WINDOW, DESKTOP };
50 
51   // Default constructor indicates invalid ScreencastId.
ScreencastId()52   ScreencastId() : type_(INVALID) {}
ScreencastId(const rtc::WindowId & id)53   explicit ScreencastId(const rtc::WindowId& id)
54       : type_(WINDOW), window_(id) {
55   }
ScreencastId(const rtc::DesktopId & id)56   explicit ScreencastId(const rtc::DesktopId& id)
57       : type_(DESKTOP), desktop_(id) {
58   }
59 
type()60   Type type() const { return type_; }
window()61   const rtc::WindowId& window() const { return window_; }
desktop()62   const rtc::DesktopId& desktop() const { return desktop_; }
63 
64   // Title is an optional parameter.
title()65   const std::string& title() const { return title_; }
set_title(const std::string & desc)66   void set_title(const std::string& desc) { title_ = desc; }
67 
IsValid()68   bool IsValid() const {
69     if (type_ == INVALID) {
70       return false;
71     } else if (type_ == WINDOW) {
72       return window_.IsValid();
73     } else {
74       return desktop_.IsValid();
75     }
76   }
IsWindow()77   bool IsWindow() const { return type_ == WINDOW; }
IsDesktop()78   bool IsDesktop() const { return type_ == DESKTOP; }
EqualsId(const ScreencastId & other)79   bool EqualsId(const ScreencastId& other) const {
80     if (type_ != other.type_) {
81       return false;
82     }
83     if (type_ == INVALID) {
84       return true;
85     } else if (type_ == WINDOW) {
86       return window_.Equals(other.window());
87     }
88     return desktop_.Equals(other.desktop());
89   }
90 
91   // T is assumed to be WindowDescription or DesktopDescription.
92   template<class T>
Convert(const std::vector<T> & list)93   static cricket::ScreencastIdList Convert(const std::vector<T>& list) {
94     ScreencastIdList screencast_list;
95     screencast_list.reserve(list.size());
96     for (typename std::vector<T>::const_iterator it = list.begin();
97          it != list.end(); ++it) {
98       ScreencastId id(it->id());
99       id.set_title(it->title());
100       screencast_list.push_back(id);
101     }
102     return screencast_list;
103   }
104 
105  private:
106   Type type_;
107   rtc::WindowId window_;
108   rtc::DesktopId desktop_;
109   std::string title_;  // Optional.
110 };
111 
112 }  // namespace cricket
113 
114 #endif  // TALK_MEDIA_BASE_SCREENCASTID_H_
115