Home | History | Annotate | Download | only in message
      1 // Copyright 2012 Google Inc. All Rights Reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #include "polo/pairing/message/optionsmessage.h"
     16 
     17 #include <algorithm>
     18 #include <iterator>
     19 #include <string>
     20 #include <sstream>
     21 
     22 namespace polo {
     23 namespace pairing {
     24 namespace message {
     25 
     26 OptionsMessage::OptionsMessage()
     27     : PoloMessage(PoloMessage::kOptions),
     28       protocol_role_preference_(kUnknown) {
     29 }
     30 
     31 void OptionsMessage::set_protocol_role_preference(
     32     OptionsMessage::ProtocolRole preference) {
     33   protocol_role_preference_ = preference;
     34 }
     35 
     36 OptionsMessage::ProtocolRole OptionsMessage::protocol_role_preference() const {
     37   return protocol_role_preference_;
     38 }
     39 
     40 void OptionsMessage::AddInputEncoding(
     41     const encoding::EncodingOption& encoding) {
     42   input_encodings_.insert(encoding);
     43 }
     44 
     45 void OptionsMessage::AddOutputEncoding(
     46     const encoding::EncodingOption& encoding) {
     47   output_encodings_.insert(encoding);
     48 }
     49 
     50 bool OptionsMessage::SupportsInputEncoding(
     51     const encoding::EncodingOption& encoding) const {
     52   return std::find_if(input_encodings_.begin(), input_encodings_.end(),
     53       encoding::EncodingOption::EncodingOptionPredicate(encoding))
     54       != input_encodings_.end();
     55 }
     56 
     57 bool OptionsMessage::SupportsOutputEncoding(
     58     const encoding::EncodingOption& encoding) const {
     59   return std::find_if(output_encodings_.begin(), output_encodings_.end(),
     60       encoding::EncodingOption::EncodingOptionPredicate(encoding))
     61       != output_encodings_.end();
     62 }
     63 
     64 const encoding::EncodingOption::EncodingSet&
     65     OptionsMessage::input_encodings() const {
     66   return input_encodings_;
     67 }
     68 
     69 const encoding::EncodingOption::EncodingSet&
     70     OptionsMessage::output_encodings() const {
     71   return output_encodings_;
     72 }
     73 
     74 std::string OptionsMessage::ToString() const {
     75   std::ostringstream ss;
     76   ss << "[OptionsMessage inputs=";
     77   encoding::EncodingOption::EncodingSet::const_iterator iter
     78       = input_encodings_.begin();
     79   while (iter != input_encodings_.end()) {
     80     ss << iter->ToString();
     81     if (++iter != input_encodings_.end()) {
     82       ss << ",";
     83     }
     84   }
     85 
     86   ss << ", outputs=";
     87   iter = output_encodings_.begin();
     88   while (iter != output_encodings_.end()) {
     89     ss << iter->ToString() << ",";
     90     if (++iter != output_encodings_.end()) {
     91       ss << ",";
     92     }
     93   }
     94 
     95   ss << ", pref=" << protocol_role_preference_ << "]";
     96   return ss.str();
     97 }
     98 
     99 }  // namespace message
    100 }  // namespace pairing
    101 }  // namespace polo
    102 
    103