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
19 #include "pvmf_cpmplugin_factory_registry.h"
20 #include "oscl_registry_client.h"
21 #include "oscl_mem.h"
22 #include "pvmf_return_codes.h"
23
PVMFCPMPluginFactoryRegistryClient()24 OSCL_EXPORT_REF PVMFCPMPluginFactoryRegistryClient::PVMFCPMPluginFactoryRegistryClient()
25 {
26 iClient = NULL;
27 }
28
~PVMFCPMPluginFactoryRegistryClient()29 OSCL_EXPORT_REF PVMFCPMPluginFactoryRegistryClient::~PVMFCPMPluginFactoryRegistryClient()
30 {
31 if (iClient)
32 OSCL_DELETE(iClient);
33 }
34
Connect(bool aPerThread)35 OSCL_EXPORT_REF PVMFStatus PVMFCPMPluginFactoryRegistryClient::Connect(bool aPerThread)
36 {
37 if (!iClient)
38 {
39 int32 err;
40 OSCL_TRY(err, iClient = OSCL_NEW(OsclRegistryClient, ()););
41 if (err != OsclErrNone || !iClient)
42 return PVMFErrNoMemory;
43 }
44 switch (iClient->Connect(aPerThread))
45 {
46 case OsclErrNone:
47 return PVMFSuccess;
48 default:
49 return PVMFFailure;
50 }
51 }
52
RegisterPlugin(OSCL_String & aMimeType,PVMFCPMPluginFactory & aFactory)53 OSCL_EXPORT_REF PVMFStatus PVMFCPMPluginFactoryRegistryClient::RegisterPlugin(OSCL_String& aMimeType,
54 PVMFCPMPluginFactory& aFactory)
55 {
56 if (!iClient)
57 return PVMFErrInvalidState;
58
59 //Make sure it's a valid mime-string for a CPM-plugin. the access
60 //interface side will lookup plugins using "X-CPM-PLUGIN" as the
61 //header, so all plugins have to match.
62 OSCL_HeapString<OsclMemAllocator> cpmregid(PVMF_MIME_CPM_PLUGIN);
63 //hierarchical string match.
64 //tells whether "id" is a prefix of the component ID (or an exact match).
65
66 if (aMimeType.get_size() >= cpmregid.get_size()
67 && oscl_CIstrncmp(cpmregid.get_cstr(), aMimeType.get_cstr(), cpmregid.get_size()) == 0
68 && (aMimeType.get_cstr()[cpmregid.get_size()] == '/'
69 || aMimeType.get_cstr()[cpmregid.get_size()] == '\0'))
70 {
71 switch (iClient->Register(aMimeType, (OsclComponentFactory)&aFactory))
72 {
73 case OsclErrNone:
74 return PVMFSuccess;
75 case OsclErrAlreadyExists:
76 return PVMFErrAlreadyExists;
77 case OsclErrNoMemory:
78 return PVMFErrNoMemory;
79 default:
80 return PVMFFailure;
81 }
82 }
83 else
84 {
85 return PVMFErrArgument;
86 }
87 }
88
UnRegisterPlugin(OSCL_String & aMimeType)89 OSCL_EXPORT_REF PVMFStatus PVMFCPMPluginFactoryRegistryClient::UnRegisterPlugin(OSCL_String& aMimeType)
90 {
91 if (!iClient)
92 return PVMFErrInvalidState;
93 switch (iClient->UnRegister(aMimeType))
94 {
95 case OsclErrNone:
96 return PVMFSuccess;
97 default:
98 return PVMFFailure;
99 }
100 }
101
Close()102 OSCL_EXPORT_REF void PVMFCPMPluginFactoryRegistryClient::Close()
103 {
104 if (iClient)
105 iClient->Close();
106 }
107
108
109
110