1 /* 2 * Copyright (C) 2017 The Android Open Source Project 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 express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef VENDOR_MODULES_H 18 #define VENDOR_MODULES_H 19 20 #include <map> 21 #include <vector> 22 #include <string> 23 24 #include <SharedLibrary.h> 25 26 using ::android::hardware::drm::V1_0::helper::SharedLibrary; 27 28 class DrmHalVTSVendorModule; 29 30 namespace drm_vts { 31 class VendorModules { 32 public: 33 /** 34 * Initialize with a file system path where the shared libraries 35 * are to be found. 36 */ VendorModules(const std::string & dir)37 explicit VendorModules(const std::string& dir) { 38 scanModules(dir); 39 } ~VendorModules()40 ~VendorModules() {} 41 42 /** 43 * Retrieve a DrmHalVTSVendorModule given its full path. The 44 * getAPIVersion method can be used to determine the versioned 45 * subclass type. 46 */ 47 DrmHalVTSVendorModule* getModule(const std::string& path); 48 49 /** 50 * Return the list of paths to available vendor modules. 51 */ getPathList()52 std::vector<std::string> getPathList() const {return mPathList;} 53 54 /** 55 * Retrieve a DrmHalVTSVendorModule given a service name. 56 */ 57 DrmHalVTSVendorModule* getModuleByName(const std::string& name); 58 59 private: 60 std::vector<std::string> mPathList; 61 std::map<std::string, std::unique_ptr<SharedLibrary>> mOpenLibraries; 62 63 /** 64 * Scan the list of paths to available vendor modules. 65 */ 66 void scanModules(const std::string& dir); 67 endsWith(const std::string & str,const std::string & suffix)68 inline bool endsWith(const std::string& str, const std::string& suffix) const { 69 if (suffix.size() > str.size()) return false; 70 return std::equal(suffix.rbegin(), suffix.rend(), str.rbegin()); 71 } 72 73 VendorModules(const VendorModules&) = delete; 74 void operator=(const VendorModules&) = delete; 75 }; 76 }; 77 78 #endif // VENDOR_MODULES_H 79