Home | History | Annotate | Download | only in host
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "remoting/host/chromoting_param_traits.h"
      6 
      7 #include "base/strings/stringprintf.h"
      8 
      9 namespace IPC {
     10 
     11 // static
     12 void ParamTraits<webrtc::DesktopVector>::Write(Message* m,
     13                                                const webrtc::DesktopVector& p) {
     14   m->WriteInt(p.x());
     15   m->WriteInt(p.y());
     16 }
     17 
     18 // static
     19 bool ParamTraits<webrtc::DesktopVector>::Read(const Message* m,
     20                                               PickleIterator* iter,
     21                                               webrtc::DesktopVector* r) {
     22   int x, y;
     23   if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y))
     24     return false;
     25   *r = webrtc::DesktopVector(x, y);
     26   return true;
     27 }
     28 
     29 // static
     30 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p,
     31                                              std::string* l) {
     32   l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)",
     33                                p.x(), p.y()));
     34 }
     35 
     36 // static
     37 void ParamTraits<webrtc::DesktopSize>::Write(Message* m,
     38                                              const webrtc::DesktopSize& p) {
     39   m->WriteInt(p.width());
     40   m->WriteInt(p.height());
     41 }
     42 
     43 // static
     44 bool ParamTraits<webrtc::DesktopSize>::Read(const Message* m,
     45                                             PickleIterator* iter,
     46                                             webrtc::DesktopSize* r) {
     47   int width, height;
     48   if (!m->ReadInt(iter, &width) || !m->ReadInt(iter, &height))
     49     return false;
     50   *r = webrtc::DesktopSize(width, height);
     51   return true;
     52 }
     53 
     54 // static
     55 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p,
     56                                            std::string* l) {
     57   l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)",
     58                                p.width(), p.height()));
     59 }
     60 
     61 // static
     62 void ParamTraits<webrtc::DesktopRect>::Write(Message* m,
     63                                              const webrtc::DesktopRect& p) {
     64   m->WriteInt(p.left());
     65   m->WriteInt(p.top());
     66   m->WriteInt(p.right());
     67   m->WriteInt(p.bottom());
     68 }
     69 
     70 // static
     71 bool ParamTraits<webrtc::DesktopRect>::Read(const Message* m,
     72                                             PickleIterator* iter,
     73                                             webrtc::DesktopRect* r) {
     74   int left, right, top, bottom;
     75   if (!m->ReadInt(iter, &left) || !m->ReadInt(iter, &top) ||
     76       !m->ReadInt(iter, &right) || !m->ReadInt(iter, &bottom)) {
     77     return false;
     78   }
     79   *r = webrtc::DesktopRect::MakeLTRB(left, top, right, bottom);
     80   return true;
     81 }
     82 
     83 // static
     84 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p,
     85                                            std::string* l) {
     86   l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)",
     87                                p.left(), p.top(), p.right(), p.bottom()));
     88 }
     89 
     90 // static
     91 void ParamTraits<remoting::ScreenResolution>::Write(
     92     Message* m,
     93     const remoting::ScreenResolution& p) {
     94   ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions());
     95   ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi());
     96 }
     97 
     98 // static
     99 bool ParamTraits<remoting::ScreenResolution>::Read(
    100     const Message* m,
    101     PickleIterator* iter,
    102     remoting::ScreenResolution* r) {
    103   webrtc::DesktopSize size;
    104   webrtc::DesktopVector dpi;
    105   if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) ||
    106       !ParamTraits<webrtc::DesktopVector>::Read(m, iter, &dpi)) {
    107     return false;
    108   }
    109   if (size.width() < 0 || size.height() < 0 ||
    110       dpi.x() < 0 || dpi.y() < 0) {
    111     return false;
    112   }
    113   *r = remoting::ScreenResolution(size, dpi);
    114   return true;
    115 }
    116 
    117 // static
    118 void ParamTraits<remoting::ScreenResolution>::Log(
    119     const remoting::ScreenResolution& p,
    120     std::string* l) {
    121   l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)",
    122                                p.dimensions().width(), p.dimensions().height(),
    123                                p.dpi().x(), p.dpi().y()));
    124 }
    125 
    126 }  // namespace IPC
    127 
    128