• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 OHOS_RESPONSE_SESSION_H
16 #define OHOS_RESPONSE_SESSION_H
17 
18 #include <string>
19 #include <vector>
20 #include <mutex>
21 #include <semaphore.h>
22 
23 #include "single_instance.h"
24 #include "dm_device_info.h"
25 #include "msg_response_auth.h"
26 #include "msg_request_auth.h"
27 #include "hichain_connector.h"
28 #include "dm_timer.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 enum ResponseSessionStatus : int32_t {
33     SESSION_INIT = 0,
34     SESSION_WAITTING_USER_CONFIRM = 1,
35     SESSION_WAITTING_GROUP_CREATED = 2,
36     SESSION_WAITTING_PIN_CODE = 3
37 };
38 
39 class ResponseSession : public HichainConnectorCallback, public std::enable_shared_from_this<ResponseSession> {
40 public:
41     ResponseSession();
~ResponseSession()42     virtual ~ResponseSession() {};
43     int32_t SendResponseMessage(int32_t reply);
44     void OnUserOperate(int32_t action);
45     void OnGroupCreated(int64_t requestId, const std::string &groupId) override;
46     void OnMemberJoin(int64_t requestId, int32_t status) override;
47     void BuildAuthenticationInfo(DmAuthParam &authParam);
48     void OnReceiveMsg(long long channelId, std::string &message);
49     int64_t GetRequestId();
50     int32_t GetPinCodeByReqId(int64_t requestId);
51     bool IsMyChannelId(long long channelId);
52     void Release();
53     void CancelDisplay();
54     int32_t GetStatus();
55 
56 private:
57     int32_t DecodeReqMsg(std::string &message);
58     int32_t StartFaService();
59     std::string GenerateGroupName();
60     void OnUserConfirm();
61     void OnUserReject(int32_t errorCode);
62     int32_t GeneratePincode();
63 
64 private:
65     int64_t mRequestId_;
66     std::string mGroupId_;
67     std::string mGroupName_;
68     std::string mReqDeviceId_;
69     sem_t mSem_;
70     std::shared_ptr<MsgRequestAuth> mMsgRequestAuthPtr_;
71     int64_t mChannelId_;
72     int32_t mPincode_;
73     int32_t mSessionStatus_;
74     std::shared_ptr<DmTimer> mReceiveTimerPtr_;
75     std::shared_ptr<DmTimer> mMemberJoinTimerPtr_;
76 };
77 } // namespace DistributedHardware
78 } // namespace OHOS
79 
80 
81 #endif
82