1 /*
2  * Copyright (C) 2021 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 
16 #ifndef PLUGIN_SERVICE_H
17 #define PLUGIN_SERVICE_H
18 
19 namespace OHOS {
20 namespace MultimediaPlugin {
21 constexpr uint8_t SUBID_BIT_NUM = 12;
22 constexpr uint16_t INVALID_IID = 0xFFFF;
23 
24 constexpr uint16_t IID_TYPE_GENERAL = 0;
25 constexpr uint16_t IID_TYPE_PIPELINE = 1;
26 
MakeInterfaceID(uint16_t interfaceIDType,uint16_t subID)27 constexpr uint16_t MakeInterfaceID(uint16_t interfaceIDType, uint16_t subID)
28 {
29     return ((interfaceIDType << SUBID_BIT_NUM) | subID);
30 }
31 
GetInterfaceIDType(uint16_t interfaceID)32 constexpr uint16_t GetInterfaceIDType(uint16_t interfaceID)
33 {
34     return (interfaceID >> SUBID_BIT_NUM);
35 }
36 
37 constexpr uint16_t PLUGIN_EXAMPLE_IID = MakeInterfaceID(IID_TYPE_GENERAL, 0);
38 constexpr uint16_t IMAGE_FORMAT_AGENT_IID = MakeInterfaceID(IID_TYPE_GENERAL, 1);
39 constexpr uint16_t IMAGE_DECODER_IID = MakeInterfaceID(IID_TYPE_GENERAL, 2);
40 constexpr uint16_t IMAGE_ENCODER_IID = MakeInterfaceID(IID_TYPE_GENERAL, 3);
41 constexpr uint16_t IMAGE_DECOMPRESS_COMP_IID = MakeInterfaceID(IID_TYPE_GENERAL, 4);
42 constexpr uint16_t IMAGE_EXIF_IID = MakeInterfaceID(IID_TYPE_GENERAL, 5);
43 
GetInterfaceId()44 template<class T> inline uint16_t GetInterfaceId()
45 {
46     return INVALID_IID;
47 }
48 #define GET_INTERFACE_ID OHOS::MultimediaPlugin::GetInterfaceId
49 #define DECLARE_INTERFACE(Type, ID) template<> inline uint16_t GET_INTERFACE_ID<Type>() { return ID; }
50 } // namespace MultimediaPlugin
51 } // namespace OHOS
52 
53 #endif // PLUGIN_SERVICE_H
54