1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CODEMAKER_REGISTRY_HXX_
25 #define _CODEMAKER_REGISTRY_HXX_
26 
27 #include <rtl/alloc.h>
28 #include <osl/interlck.h>
29 #include	<registry/registry.hxx>
30 #include "registry/reader.hxx"
31 #include "registry/version.h"
32 #include	<codemaker/options.hxx>
33 
34 struct TypeReader_Impl
35 {
TypeReader_ImplTypeReader_Impl36 	TypeReader_Impl(const sal_uInt8* buffer,
37 			   	    sal_uInt32 bufferLen,
38 			   	    sal_Bool copyData)
39 		: m_refCount(0)
40 		, m_copyData(copyData)
41 		, m_blopSize(bufferLen)
42 		, m_pBlop(buffer)
43 		{
44 			if (copyData)
45 			{
46 				m_pBlop = (sal_uInt8*)rtl_allocateMemory(bufferLen);
47 				rtl_copyMemory((void*)m_pBlop, buffer, bufferLen);
48 			} else
49 			{
50 				m_blopSize = bufferLen;
51 				m_pBlop = buffer;
52 			}
53 
54 			m_pReader = new typereg::Reader(
55                 m_pBlop, m_blopSize, false, TYPEREG_VERSION_1);
56 		}
57 
~TypeReader_ImplTypeReader_Impl58 	~TypeReader_Impl()
59 		{
60 			if (m_copyData && m_pReader)
61 			{
62 				delete m_pReader;
63 			}
64 		}
65 
66 	sal_Int32			m_refCount;
67 	sal_Bool			m_copyData;
68 	sal_Int32			m_blopSize;
69 	const sal_uInt8* 	m_pBlop;
70 	typereg::Reader*	m_pReader;
71 };
72 
73 class TypeReader
74 {
75 /*
76 	inline TypeReader(const RegistryTypeReader_Api* pApi,
77 							  const sal_uInt8* buffer,
78 							  sal_uInt32 bufferLen,
79 							  sal_Bool copyData);
80 */
81 public:
TypeReader()82 	inline TypeReader()
83 		: m_pImpl(NULL)
84 	{}
85 
TypeReader(const sal_uInt8 * buffer,sal_uInt32 bufferLen,sal_Bool copyData)86 	inline TypeReader(        const sal_uInt8* buffer,
87 							  sal_uInt32 bufferLen,
88 							  sal_Bool copyData)
89 	{
90 		m_pImpl = new TypeReader_Impl(buffer, bufferLen, copyData);
91 		acquire();
92 	}
93 
TypeReader(const TypeReader & toCopy)94 	inline TypeReader(const TypeReader& toCopy)
95 		: m_pImpl(toCopy.m_pImpl)
96 	{
97 		acquire();
98 	}
99 
~TypeReader()100     inline ~TypeReader()
101 	{
102 		release();
103 	}
104 
acquire()105     inline void acquire()
106 	{
107 		if (m_pImpl)
108 			osl_incrementInterlockedCount(&m_pImpl->m_refCount);
109 	}
110 
release()111 	inline void release()
112 	{
113 		if (m_pImpl && 0 == osl_decrementInterlockedCount(&m_pImpl->m_refCount))
114 		{
115 			delete m_pImpl;
116 		}
117 	}
118 
operator =(const TypeReader & value)119 	inline TypeReader& operator = ( const TypeReader& value )
120 	{
121 		release();
122 		m_pImpl = value.m_pImpl;
123 		acquire();
124 		return *this;
125 	}
126 
isValid() const127 	inline sal_Bool			isValid() const
128 		{
129 			if (m_pImpl)
130 				return m_pImpl->m_pReader->isValid();
131 			else
132 				return sal_False;
133 		}
134 
getTypeClass() const135 	inline RTTypeClass 				getTypeClass() const
136 		{ return m_pImpl->m_pReader->getTypeClass(); }
getTypeName() const137 	inline const ::rtl::OString 	getTypeName() const
138 		{ return inGlobalSet( m_pImpl->m_pReader->getTypeName() ); }
getSuperTypeCount() const139     inline sal_uInt16 getSuperTypeCount() const
140         { return m_pImpl->m_pReader->getSuperTypeCount(); }
getSuperTypeName(sal_uInt16 index) const141 	inline const ::rtl::OString 	getSuperTypeName(sal_uInt16 index) const
142 		{ return inGlobalSet( m_pImpl->m_pReader->getSuperTypeName(index) ); }
getDoku() const143 	inline const ::rtl::OString 	getDoku() const
144 		{ return inGlobalSet( m_pImpl->m_pReader->getDocumentation() ); }
getFileName() const145 	inline const ::rtl::OString 	getFileName() const
146 		{ return inGlobalSet( m_pImpl->m_pReader->getFileName() ); }
getFieldCount() const147 	inline sal_uInt32				getFieldCount() const
148 		{ return m_pImpl->m_pReader->getFieldCount(); }
getFieldName(sal_uInt16 index) const149 	inline const ::rtl::OString 	getFieldName( sal_uInt16 index ) const
150 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldName(index) ); }
getFieldType(sal_uInt16 index) const151 	inline const ::rtl::OString		getFieldType( sal_uInt16 index ) const
152 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldTypeName(index) ); }
getFieldAccess(sal_uInt16 index) const153 	inline RTFieldAccess			getFieldAccess( sal_uInt16 index ) const
154 		{ return m_pImpl->m_pReader->getFieldFlags(index); }
getFieldConstValue(sal_uInt16 index) const155 	inline RTConstValue				getFieldConstValue( sal_uInt16 index ) const
156 		{ return m_pImpl->m_pReader->getFieldValue(index); }
getFieldDoku(sal_uInt16 index) const157 	inline const ::rtl::OString 	getFieldDoku( sal_uInt16 index ) const
158 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldDocumentation(index) ); }
getFieldFileName(sal_uInt16 index) const159 	inline const ::rtl::OString 	getFieldFileName( sal_uInt16 index ) const
160 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldFileName(index) ); }
getMethodCount() const161 	inline sal_uInt32				getMethodCount() const
162 		{ return m_pImpl->m_pReader->getMethodCount(); }
getMethodName(sal_uInt16 index) const163 	inline const ::rtl::OString 	getMethodName( sal_uInt16 index ) const
164 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodName(index) ); }
getMethodParamCount(sal_uInt16 index) const165 	inline sal_uInt32    			getMethodParamCount( sal_uInt16 index ) const
166 		{ return m_pImpl->m_pReader->getMethodParameterCount(index); }
getMethodParamType(sal_uInt16 index,sal_uInt16 paramIndex) const167 	inline const ::rtl::OString 	getMethodParamType( sal_uInt16 index, sal_uInt16 paramIndex ) const
168 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodParameterTypeName(index,paramIndex) ); }
getMethodParamName(sal_uInt16 index,sal_uInt16 paramIndex) const169 	inline const ::rtl::OString 	getMethodParamName( sal_uInt16 index, sal_uInt16 paramIndex ) const
170 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodParameterName(index,paramIndex) ); }
getMethodParamMode(sal_uInt16 index,sal_uInt16 paramIndex) const171 	inline RTParamMode				getMethodParamMode( sal_uInt16 index, sal_uInt16 paramIndex ) const
172 		{ return m_pImpl->m_pReader->getMethodParameterFlags(index,paramIndex); }
getMethodExcCount(sal_uInt16 index) const173 	inline sal_uInt32    			getMethodExcCount( sal_uInt16 index ) const
174 		{ return m_pImpl->m_pReader->getMethodExceptionCount(index); }
getMethodExcType(sal_uInt16 index,sal_uInt16 excIndex) const175 	inline const ::rtl::OString 	getMethodExcType( sal_uInt16 index, sal_uInt16 excIndex ) const
176 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodExceptionTypeName(index,excIndex) ); }
getMethodReturnType(sal_uInt16 index) const177 	inline const ::rtl::OString 	getMethodReturnType( sal_uInt16 index ) const
178 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodReturnTypeName(index) ); }
getMethodMode(sal_uInt16 index) const179 	inline RTMethodMode				getMethodMode( sal_uInt16 index ) const
180 		{ return m_pImpl->m_pReader->getMethodFlags(index); }
getMethodDoku(sal_uInt16 index) const181 	inline const ::rtl::OString 	getMethodDoku( sal_uInt16 index ) const
182 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodDocumentation(index) ); }
183 
getReferenceCount() const184 	inline sal_uInt32				getReferenceCount() const
185 		{ return m_pImpl->m_pReader->getReferenceCount(); }
getReferenceName(sal_uInt16 index) const186 	inline const ::rtl::OString 	getReferenceName( sal_uInt16 index ) const
187 		{ return inGlobalSet( m_pImpl->m_pReader->getReferenceTypeName(index) ); }
getReferenceType(sal_uInt16 index) const188 	inline RTReferenceType			getReferenceType( sal_uInt16 index ) const
189 		{ return m_pImpl->m_pReader->getReferenceSort(index); }
getReferenceDoku(sal_uInt16 index) const190 	inline const ::rtl::OString 	getReferenceDoku( sal_uInt16 index ) const
191 		{ return inGlobalSet( m_pImpl->m_pReader->getReferenceDocumentation(index) ); }
192 
getBlopSize() const193 	inline sal_uInt32 getBlopSize() const
194 		{ return m_pImpl->m_blopSize; }
195 
getBlop() const196 	inline const sal_uInt8* getBlop() const
197 		{ return m_pImpl->m_pBlop; }
198 
199 private:
200 	TypeReader_Impl* m_pImpl;
201 };
202 
203 
204 #endif // _CODEMAKER_REGISTRY_HXX_
205