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 // Utility methods for MCS interactions. 6 7 #ifndef GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ 8 #define GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ 9 10 #include <string> 11 12 #include "base/basictypes.h" 13 #include "base/memory/ref_counted.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "google_apis/gcm/base/gcm_export.h" 16 #include "google_apis/gcm/protocol/mcs.pb.h" 17 18 namespace net { 19 class StreamSocket; 20 } 21 22 namespace gcm { 23 24 // MCS Message tags. 25 // WARNING: the order of these tags must remain the same, as the tag values 26 // must be consistent with those used on the server. 27 enum MCSProtoTag { 28 kHeartbeatPingTag = 0, 29 kHeartbeatAckTag, 30 kLoginRequestTag, 31 kLoginResponseTag, 32 kCloseTag, 33 kMessageStanzaTag, 34 kPresenceStanzaTag, 35 kIqStanzaTag, 36 kDataMessageStanzaTag, 37 kBatchPresenceStanzaTag, 38 kStreamErrorStanzaTag, 39 kHttpRequestTag, 40 kHttpResponseTag, 41 kBindAccountRequestTag, 42 kBindAccountResponseTag, 43 kTalkMetadataTag, 44 kNumProtoTypes, 45 }; 46 47 enum MCSIqStanzaExtension { 48 kSelectiveAck = 12, 49 kStreamAck = 13, 50 }; 51 52 // Builds a LoginRequest with the hardcoded local data. 53 GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest( 54 uint64 auth_id, 55 uint64 auth_token); 56 57 // Builds a StreamAck IqStanza message. 58 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildStreamAck(); 59 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildSelectiveAck( 60 const std::vector<std::string>& acked_ids); 61 62 // Utility methods for building and identifying MCS protobufs. 63 GCM_EXPORT scoped_ptr<google::protobuf::MessageLite> 64 BuildProtobufFromTag(uint8 tag); 65 GCM_EXPORT int GetMCSProtoTag(const google::protobuf::MessageLite& message); 66 67 // RMQ utility methods for extracting/setting common data from/to protobufs. 68 GCM_EXPORT std::string GetPersistentId( 69 const google::protobuf::MessageLite& message); 70 GCM_EXPORT void SetPersistentId( 71 const std::string& persistent_id, 72 google::protobuf::MessageLite* message); 73 GCM_EXPORT uint32 GetLastStreamIdReceived( 74 const google::protobuf::MessageLite& protobuf); 75 GCM_EXPORT void SetLastStreamIdReceived( 76 uint32 last_stream_id_received, 77 google::protobuf::MessageLite* protobuf); 78 79 } // namespace gcm 80 81 #endif // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ 82