1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef OSCL_SHARED_LIBRARY_H_INCLUDED 19 #define OSCL_SHARED_LIBRARY_H_INCLUDED 20 21 #ifndef OSCL_BASE_H_INCLUDED 22 #include "oscl_base.h" 23 #endif 24 25 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED 26 #include "oscl_string_containers.h" 27 #endif 28 29 #ifndef OSCL_SHARED_LIB_INTERFACE_H_INCLUDED 30 #include "oscl_shared_lib_interface.h" 31 #endif 32 33 #ifndef OSCL_LIBRARY_COMMON_H_INCLUDED 34 #include "oscl_library_common.h" 35 #endif 36 37 struct OsclUuid; 38 class PVLogger; 39 40 /** 41 * OsclSharedLibrary gives access to shared libraries in the user specified location 42 **/ 43 class OsclSharedLibrary 44 { 45 public: 46 47 /** 48 * Default object Constructor function 49 **/ 50 51 OSCL_IMPORT_REF OsclSharedLibrary(); 52 53 /** 54 * Constructor that accepts a path to the library to load. The library 55 * isn't loaded at this point. It is only loaded after a call to LoadLib. 56 * 57 * @param aPath path name of a specific library to load 58 */ 59 OSCL_IMPORT_REF OsclSharedLibrary(const OSCL_String& aPath); 60 61 /** 62 * Object destructor function 63 **/ 64 OSCL_IMPORT_REF ~OsclSharedLibrary(); 65 66 /** 67 * Attempts to load the library specified by the pathname. 68 * 69 * @param aPath path name of a specific library to load 70 * @returns Returns some status information about whether the library loaded. 71 */ 72 OSCL_IMPORT_REF OsclLibStatus LoadLib(const OSCL_String& aPath); 73 74 /** 75 * Attempts to load the library specified by the stored pathname (as set 76 * in the constructor or SetLibPath). 77 * 78 * @returns Returns some status information about whether the library loaded. 79 */ 80 OSCL_IMPORT_REF OsclLibStatus LoadLib(); 81 82 /** 83 * Sets iLibPath to the pathname provided 84 * 85 * @param aPath path name of a specific library to load 86 */ 87 OSCL_IMPORT_REF void SetLibPath(const OSCL_String& aPath); 88 89 /** 90 * Query for the instance of a particular interface based on the request interface ID 91 * 92 * @param aInterfaceId ID 93 * 94 * @param aInterfacePtr - output parameter filled in with the requested interface 95 * pointer or NULL if the interface pointer is not supported. 96 * @returns OsclLibStatus information about query for the interface 97 **/ 98 OSCL_IMPORT_REF OsclLibStatus QueryInterface(const OsclUuid& aInterfaceId, 99 OsclAny*& aInterfacePtr); 100 101 /** 102 * Close the library. The library will be closed only when there are no live references 103 * @returns success or fail in case of closing the library 104 **/ 105 OSCL_IMPORT_REF OsclLibStatus Close(); 106 107 /** 108 * Increment the reference count for tracking number of live references of node 109 * by the shared lib instance. 110 **/ 111 OSCL_IMPORT_REF void AddRef(); 112 113 /** 114 * Decrement the reference count when done with live reference node 115 * by the shared lib instance. 116 **/ 117 OSCL_IMPORT_REF void RemoveRef(); 118 119 private: 120 OsclLibStatus loadlibrary(const OSCL_String& alib); 121 122 PVLogger* ipLogger; 123 int32 iRefCount; 124 OsclSharedLibraryInterface *pSharedLibInterface; 125 #if OSCL_LIBRARY_PERF_LOGGING 126 PVLogger* iDiagnosticsLogger; 127 uint32 iLibCount; 128 uint32 iLibLoadTime; 129 uint32 delta; 130 #endif 131 void* ipHandle; 132 OSCL_HeapString<OsclMemAllocator> iLibPath; 133 bool iLoaded; 134 }; 135 136 #include "oscl_vector.h" 137 138 /* 139 ** OsclSharedLibraryList is a handy class for locating and using libraries that support 140 ** a given interface. 141 */ 142 class OsclSharedLibraryList 143 { 144 public: 145 OSCL_IMPORT_REF OsclSharedLibraryList(); 146 OSCL_IMPORT_REF ~OsclSharedLibraryList(); 147 148 /* 149 ** Give a config file directory, locate all the libraries that support the given 150 ** interface ID. For each library, create a shared library object for it and add 151 ** it to the list. 152 */ 153 OSCL_IMPORT_REF void Populate(const OSCL_String& aPath, const OsclUuid& aInterfaceId); 154 155 /* 156 ** Return the size of the list 157 */ Size()158 uint32 Size() 159 { 160 return iList.size(); 161 } 162 163 /* 164 ** Query interface for the given library. This will load the library if needed. 165 */ 166 OSCL_IMPORT_REF OsclLibStatus QueryInterfaceAt(uint32 aIndex, OsclAny*& aInterfacePtr); 167 168 /* 169 ** Close all open libraries and clear the list. 170 */ 171 OSCL_IMPORT_REF void CloseAll(); 172 173 private: 174 Oscl_Vector<OsclSharedLibrary*, OsclMemAllocator> iList; 175 OsclUuid iInterfaceId; 176 PVLogger* iLogger; 177 }; 178 179 #endif //OSCL_SHARED_LIBRARY_H_INCLUDED 180 181