1* // Copyright 2021 Google LLC
2* //
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* #include "handler.hpp"
16* 
17* #include <blobs-ipmid/blobs.hpp>
18* 
19* #include <memory>
20* 
21* // Extern "C" is used due to the usage of dlopen() for loading IPMI handlers
22* // and IPMI blob handlers. This happens in two steps:
23* //
24* // 1) ipmid loads all libraries in /usr/lib/ipmid-providers from its
25* //    loadLibraries() function using dlopen().
26* // 2) The blobs library, libblobcmds.so, loads all libraries in
27* //    /usr/lib/blobs-ipmid from its loadLibraries() function. It uses dlsym()
28* //    to locate the createHandler function by its un-mangled name
29* //    "createHandler". Using extern "C" prevents its name from being mangled
30* //    into, for example, "_Z13createHandlerv".
31* 
32* extern "C" std::unique_ptr<blobs::GenericBlobInterface> createHandler()
33* {
34*     return std::make_unique<blobs::MetricBlobHandler>();
35* }
36*