• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 OHOS_IPC_PROCESS_SKELETON_H
17 #define OHOS_IPC_PROCESS_SKELETON_H
18 
19 #include <map>
20 #include <mutex>
21 #include <shared_mutex>
22 #include <refbase.h>
23 
24 #include "iremote_object.h"
25 
26 namespace OHOS {
27 class ProcessSkeleton : public virtual RefBase {
28 public:
29 
30     static ProcessSkeleton* GetInstance();
31     sptr<IRemoteObject> GetRegistryObject();
32     void SetRegistryObject(sptr<IRemoteObject> &object);
33     void SetSamgrFlag(bool flag);
34     bool GetSamgrFlag();
35 
36     bool IsContainsObject(IRemoteObject *object);
37     sptr<IRemoteObject> QueryObject(const std::u16string &descriptor);
38     bool AttachObject(IRemoteObject *object, const std::u16string &descriptor);
39     bool DetachObject(IRemoteObject *object, const std::u16string &descriptor);
40 
41 private:
42     DISALLOW_COPY_AND_MOVE(ProcessSkeleton);
43     ProcessSkeleton() = default;
44     ~ProcessSkeleton();
45 
46     static ProcessSkeleton* instance_;
47     static std::mutex mutex_;
48     std::shared_mutex objMutex_;
49     sptr<IRemoteObject> registryObject_ = nullptr;
50     bool isSamgr_ = false;
51 
52     std::map<std::u16string, wptr<IRemoteObject>> objects_;
53     std::map<IRemoteObject *, bool> isContainStub_;
54 };
55 } // namespace OHOS
56 #endif // OHOS_IPC_PROCESS_SKELETON_H
57