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.
5 // Utility methods for MCS interactions.
7 #ifndef GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_
8 #define GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_
13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "google_apis/gcm/base/gcm_export.h"
17 #include "google_apis/gcm/protocol/mcs.pb.h"
30 // WARNING: the order of these tags must remain the same, as the tag values
31 // must be consistent with those used on the server.
33 kHeartbeatPingTag
= 0,
41 kDataMessageStanzaTag
,
42 kBatchPresenceStanzaTag
,
43 kStreamErrorStanzaTag
,
46 kBindAccountRequestTag
,
47 kBindAccountResponseTag
,
52 enum MCSIqStanzaExtension
{
57 // Builds a LoginRequest with the hardcoded local data.
58 GCM_EXPORT scoped_ptr
<mcs_proto::LoginRequest
> BuildLoginRequest(
61 const std::string
& version_string
);
63 // Builds a StreamAck IqStanza message.
64 GCM_EXPORT scoped_ptr
<mcs_proto::IqStanza
> BuildStreamAck();
65 GCM_EXPORT scoped_ptr
<mcs_proto::IqStanza
> BuildSelectiveAck(
66 const std::vector
<std::string
>& acked_ids
);
68 // Utility methods for building and identifying MCS protobufs.
69 GCM_EXPORT scoped_ptr
<google::protobuf::MessageLite
>
70 BuildProtobufFromTag(uint8 tag
);
71 GCM_EXPORT
int GetMCSProtoTag(const google::protobuf::MessageLite
& message
);
73 // RMQ utility methods for extracting/setting common data from/to protobufs.
74 GCM_EXPORT
std::string
GetPersistentId(
75 const google::protobuf::MessageLite
& message
);
76 GCM_EXPORT
void SetPersistentId(
77 const std::string
& persistent_id
,
78 google::protobuf::MessageLite
* message
);
79 GCM_EXPORT uint32
GetLastStreamIdReceived(
80 const google::protobuf::MessageLite
& protobuf
);
81 GCM_EXPORT
void SetLastStreamIdReceived(
82 uint32 last_stream_id_received
,
83 google::protobuf::MessageLite
* protobuf
);
85 // Returns whether the TTL (time to live) for this message has expired, based
86 // on the |sent| timestamps and base::TimeTicks::Now(). If |protobuf| is not
87 // for a DataMessageStanza or the TTL is 0, will return false.
88 GCM_EXPORT
bool HasTTLExpired(const google::protobuf::MessageLite
& protobuf
,
90 GCM_EXPORT
int GetTTL(const google::protobuf::MessageLite
& protobuf
);
94 #endif // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_