1 /*
2  * Copyright (c) 2011-2014, Intel Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #pragma once
31 
32 #include "ConfigurableElement.h"
33 #include "SubsystemPlugins.h"
34 #include <list>
35 #include <string>
36 
37 class CSubsystemLibrary;
38 
39 class CSystemClass : public CConfigurableElement
40 {
41 public:
42     CSystemClass();
43     virtual ~CSystemClass();
44 
45     /** Load subsystem plugin and fill the corresponding libraries.
46      *
47      * @param[out] strError is filled with new line separated errors if the function returns false,
48      *                         undefined otherwise.
49      * @param[in] pSubsystemPlugins The plugins to load.
50      * @param[in] bVirtualSubsystemFallback If a subsystem can not be found, use the virtual one.
51      *
52      * @return true if the plugins succesfully started or that a fallback is available,
53                false otherwise.
54      */
55     bool loadSubsystems(std::string& strError, const CSubsystemPlugins* pSubsystemPlugins,
56                         bool bVirtualSubsystemFallback = false);
57     // Subsystem factory
58     const CSubsystemLibrary* getSubsystemLibrary() const;
59 
60     /**
61       * Look for subsystems that need to be resynchronized.
62       * Consume the need to be resynchronized
63       * and fill a syncer set with all syncers that need to be resynchronized
64       *
65       * @param[out] syncerSet The syncer set to fill
66       */
67     void checkForSubsystemsToResync(CSyncerSet& syncerSet);
68 
69     /**
70       * Reset subsystems need to resync flag.
71       */
72     void cleanSubsystemsNeedToResync();
73 
74     // base
75     virtual std::string getKind() const;
76 
77 private:
78     CSystemClass(const CSystemClass&);
79     CSystemClass& operator=(const CSystemClass&);
80     // base
81     virtual bool childrenAreDynamic() const;
82 
83     /** Load shared libraries subsystem plugins.
84      *
85      * @param[out] lstrError is the list of error that occured during loadings.
86      * @param[in] pSubsystemPlugins The plugins to load.
87      *
88      * @return true if all plugins have been succesfully loaded, false otherwises.
89      */
90     bool loadSubsystemsFromSharedLibraries(std::list<std::string>& lstrError,
91                                            const CSubsystemPlugins* pSubsystemPlugins);
92 
93     // Plugin symbol computation
94     static std::string getPluginSymbol(const std::string& strPluginPath);
95 
96     /** Load subsystem plugin shared libraries.
97      *
98      * @param[in:out] lstrPluginFiles is the path list of the plugins shared libraries to load.
99      *                Successfully loaded plugins are removed from the list.
100      * @param[out] lstrError is the list of error that occured during loadings.
101      *
102      * @return true if at least one plugin has been succesfully loaded, false otherwise.
103      *         When false is returned, some plugins MIHGT have been loaded
104      *         but the lstrPluginFiles is accurate.
105      */
106     bool loadPlugins(std::list<std::string>& lstrPluginFiles, std::list<std::string>& lstrError);
107 
108     // Subsystem factory
109     CSubsystemLibrary* _pSubsystemLibrary;
110     std::list<void*> _subsystemLibraryHandleList; /**< Contains the list of all open plugin libs. */
111 };
112 
113