Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / Linux / PlatformManagerImpl.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2018 Nest Labs, Inc.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 /**
20  *    @file
21  *          Provides an implementation of the PlatformManager object.
22  */
23
24 #pragma once
25
26 #include <memory>
27 #include <platform/internal/GenericPlatformManagerImpl_POSIX.h>
28
29 #if CHIP_WITH_GIO
30 #include <gio/gio.h>
31 #endif
32
33 namespace chip {
34 namespace DeviceLayer {
35
36 /**
37  * Concrete implementation of the PlatformManager singleton object for Linux platforms.
38  */
39 class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl_POSIX<PlatformManagerImpl>
40 {
41     // Allow the PlatformManager interface class to delegate method calls to
42     // the implementation methods provided by this class.
43     friend PlatformManager;
44
45     // Allow the generic implementation base class to call helper methods on
46     // this class.
47 #ifndef DOXYGEN_SHOULD_SKIP_THIS
48     friend Internal::GenericPlatformManagerImpl_POSIX<PlatformManagerImpl>;
49 #endif
50
51 public:
52     // ===== Platform-specific members that may be accessed directly by the application.
53 #if CHIP_WITH_GIO
54     GDBusConnection * GetGDBusConnection();
55 #endif
56
57 private:
58     // ===== Methods that implement the PlatformManager abstract interface.
59
60     CHIP_ERROR _InitChipStack();
61
62     // ===== Members for internal use by the following friends.
63
64     friend PlatformManager & PlatformMgr();
65     friend PlatformManagerImpl & PlatformMgrImpl();
66     friend class Internal::BLEManagerImpl;
67
68     static PlatformManagerImpl sInstance;
69
70     // The temporary hack for getting IP address change on linux for network provisioning in the rendezvous session.
71     // This should be removed or find a better place once we depercate the rendezvous session.
72     static void WiFIIPChangeListener();
73
74 #if CHIP_WITH_GIO
75     struct GDBusConnectionDeleter
76     {
77         void operator()(GDBusConnection * conn) { g_object_unref(conn); }
78     };
79     using UniqueGDBusConnection = std::unique_ptr<GDBusConnection, GDBusConnectionDeleter>;
80     UniqueGDBusConnection mpGDBusConnection;
81 #endif
82 };
83
84 /**
85  * Returns the public interface of the PlatformManager singleton object.
86  *
87  * chip applications should use this to access features of the PlatformManager object
88  * that are common to all platforms.
89  */
90 inline PlatformManager & PlatformMgr()
91 {
92     return PlatformManagerImpl::sInstance;
93 }
94
95 /**
96  * Returns the platform-specific implementation of the PlatformManager singleton object.
97  *
98  * chip applications can use this to gain access to features of the PlatformManager
99  * that are specific to the ESP32 platform.
100  */
101 inline PlatformManagerImpl & PlatformMgrImpl()
102 {
103     return PlatformManagerImpl::sInstance;
104 }
105
106 } // namespace DeviceLayer
107 } // namespace chip