1 /* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 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 "feature.h" 16 #include "feature_impl.h" 17 #include "memory_adapter.h" 18 SAMGR_AddInterface(FeatureImpl * featureImpl,IUnknown * iUnknown)19BOOL SAMGR_AddInterface(FeatureImpl *featureImpl, IUnknown *iUnknown) 20 { 21 if (featureImpl == NULL || iUnknown == NULL || featureImpl->iUnknown != NULL) { 22 return FALSE; 23 } 24 25 featureImpl->iUnknown = iUnknown; 26 return TRUE; 27 } 28 SAMGR_DelInterface(FeatureImpl * featureImpl)29IUnknown *SAMGR_DelInterface(FeatureImpl *featureImpl) 30 { 31 if (featureImpl == NULL) { 32 return NULL; 33 } 34 IUnknown *iUnknown = featureImpl->iUnknown; 35 featureImpl->iUnknown = NULL; 36 return iUnknown; 37 } 38 SAMGR_GetInterface(FeatureImpl * featureImpl)39IUnknown *SAMGR_GetInterface(FeatureImpl *featureImpl) 40 { 41 if (featureImpl == NULL) { 42 return NULL; 43 } 44 return featureImpl->iUnknown; 45 } 46 SAMGR_IsNoInterface(FeatureImpl * featureImpl)47BOOL SAMGR_IsNoInterface(FeatureImpl *featureImpl) 48 { 49 return (BOOL)(featureImpl == NULL || featureImpl->iUnknown == NULL); 50 } 51 FEATURE_CreateInstance(Feature * feature)52FeatureImpl *FEATURE_CreateInstance(Feature *feature) 53 { 54 if (feature == NULL) { 55 return NULL; 56 } 57 FeatureImpl *featureImpl = (FeatureImpl *)SAMGR_Malloc(sizeof(FeatureImpl)); 58 if (featureImpl == NULL) { 59 return NULL; 60 } 61 featureImpl->feature = feature; 62 featureImpl->iUnknown = NULL; 63 return featureImpl; 64 }