• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #ifndef SESSION_TOKEN_H
17 #define SESSION_TOKEN_H
18 
19 #include "ipc_object_stub.h"
20 #include "parcel.h"
21 #include "message_parcel.h"
22 
23 namespace OHOS::testserver {
24     using namespace OHOS::HiviewDFX;
25     constexpr OHOS::HiviewDFX::HiLogLabel LABEL_SESSION_TOKEN = { LOG_CORE, 0xD003110, "SessionToken"};
26 
27     class SessionToken : public Parcelable {
28     public:
29         SessionToken(sptr<IPCObjectStub> ipcObjectStub = new(std::nothrow) IPCObjectStub(),
30                                                                     sptr<IRemoteObject> iRemoteObject = nullptr)
31         {
32             HiLog::Debug(LABEL_SESSION_TOKEN, "%{public}s called. ", __func__);
33             ipcObjectStub_ = ipcObjectStub;
34             iRemoteObject_ = iRemoteObject;
35         }
36 
~SessionToken()37         ~SessionToken()
38         {
39             HiLog::Debug(LABEL_SESSION_TOKEN, "%{public}s called. ", __func__);
40         }
41 
Marshalling(Parcel & out)42         bool Marshalling(Parcel &out) const override
43         {
44             HiLog::Debug(LABEL_SESSION_TOKEN, "%{public}s called. ", __func__);
45             static_cast<MessageParcel *>(&out)->WriteRemoteObject(ipcObjectStub_);
46             return true;
47         }
48 
Unmarshalling(Parcel & in)49         static SessionToken *Unmarshalling(Parcel &in)
50         {
51             HiLog::Debug(LABEL_SESSION_TOKEN, "%{public}s called. ", __func__);
52             sptr<IRemoteObject> iRemoteObject = static_cast<MessageParcel *>(&in)->ReadRemoteObject();
53             SessionToken *sessionToken = new SessionToken(nullptr, iRemoteObject);
54             return sessionToken;
55         }
56 
AddDeathRecipient(const sptr<IRemoteObject::DeathRecipient> & recipient)57         bool AddDeathRecipient(const sptr<IRemoteObject::DeathRecipient> &recipient) const
58         {
59             HiLog::Debug(LABEL_SESSION_TOKEN, "%{public}s called. ", __func__);
60             if (iRemoteObject_ == nullptr) {
61                 return false;
62             }
63             return iRemoteObject_->AddDeathRecipient(recipient);
64         }
65 
66     private:
67         sptr<IPCObjectStub> ipcObjectStub_;
68         sptr<IRemoteObject> iRemoteObject_;
69     };
70 } // namespace OHOS::testserver
71 #endif // SESSION_TOKEN_H