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 #ifndef POLO_PAIRING_MESSAGE_CONFIGURATIONMESSAGE_H_
16 #define POLO_PAIRING_MESSAGE_CONFIGURATIONMESSAGE_H_
17 
18 #include <string>
19 #include "polo/encoding/encodingoption.h"
20 #include "polo/pairing/message/optionsmessage.h"
21 #include "polo/pairing/message/polomessage.h"
22 
23 namespace polo {
24 namespace pairing {
25 namespace message {
26 
27 // A message that contains Polo configuration options.
28 class ConfigurationMessage : public PoloMessage {
29  public:
30   // Creates a configuration message with the given encoding and role.
31   // @param encoding the configured encoding options
32   // @param client_role the client role
33   ConfigurationMessage(const encoding::EncodingOption &encoding,
34                        OptionsMessage::ProtocolRole client_role);
35 
36   // Gets the configured encoding options.
37   const ::polo::encoding::EncodingOption& encoding() const;
38 
39   // Gets the client role.
40   OptionsMessage::ProtocolRole client_role() const;
41 
42   // @override
43   virtual std::string ToString() const;
44 
45   // Computes the best configuration given the local and peer options. This
46   // performs a negotiation of the local and peer options and selects the most
47   // complex common input and output encodings and a local role.
48   // @param local_options the local options
49   // @param peer_options the peer options
50   static ConfigurationMessage* GetBestConfiguration(
51       const OptionsMessage& local_options,
52       const OptionsMessage& peer_options);
53 
54  private:
55   encoding::EncodingOption encoding_;
56   OptionsMessage::ProtocolRole client_role_;
57 
58   DISALLOW_COPY_AND_ASSIGN(ConfigurationMessage);
59 };
60 
61 }  // namespace message
62 }  // namespace pairing
63 }  // namespace polo
64 
65 #endif  // POLO_PAIRING_MESSAGE_CONFIGURATIONMESSAGE_H_
66