- add sources.
[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
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
60 // Utility methods for building and identifying MCS protobufs.
61 GCM_EXPORT scoped_ptr<google::protobuf::MessageLite>
62     BuildProtobufFromTag(uint8 tag);
63 GCM_EXPORT int GetMCSProtoTag(const google::protobuf::MessageLite& message);
64
65 // RMQ utility methods for extracting/setting common data from/to protobufs.
66 GCM_EXPORT std::string GetPersistentId(
67     const google::protobuf::MessageLite& message);
68 GCM_EXPORT void SetPersistentId(
69     const std::string& persistent_id,
70     google::protobuf::MessageLite* message);
71 GCM_EXPORT uint32 GetLastStreamIdReceived(
72     const google::protobuf::MessageLite& protobuf);
73 GCM_EXPORT void SetLastStreamIdReceived(
74     uint32 last_stream_id_received,
75     google::protobuf::MessageLite* protobuf);
76
77 }  // namespace gcm
78
79 #endif  // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_