Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / google_apis / gcm / base / mcs_util.h
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 #include <vector>
12
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"
18
19 namespace base {
20 class Clock;
21 }
22
23 namespace net {
24 class StreamSocket;
25 }
26
27 namespace gcm {
28
29 // MCS Message tags.
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.
32 enum MCSProtoTag {
33   kHeartbeatPingTag = 0,
34   kHeartbeatAckTag,
35   kLoginRequestTag,
36   kLoginResponseTag,
37   kCloseTag,
38   kMessageStanzaTag,
39   kPresenceStanzaTag,
40   kIqStanzaTag,
41   kDataMessageStanzaTag,
42   kBatchPresenceStanzaTag,
43   kStreamErrorStanzaTag,
44   kHttpRequestTag,
45   kHttpResponseTag,
46   kBindAccountRequestTag,
47   kBindAccountResponseTag,
48   kTalkMetadataTag,
49   kNumProtoTypes,
50 };
51
52 enum MCSIqStanzaExtension {
53   kSelectiveAck = 12,
54   kStreamAck = 13,
55 };
56
57 // Builds a LoginRequest with the hardcoded local data.
58 GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(
59     uint64 auth_id,
60     uint64 auth_token,
61     const std::string& version_string);
62
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);
67
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);
72
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);
84
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,
89                               base::Clock* clock);
90 GCM_EXPORT int GetTTL(const google::protobuf::MessageLite& protobuf);
91
92 }  // namespace gcm
93
94 #endif  // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_