|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "CdlCompilerToolkit/CdlTkProcess.h" |
|
18 #include "CdlTkPriv.h" |
|
19 #include <fstream> |
|
20 #include <iomanip> |
|
21 #include <iostream> |
|
22 using namespace std; |
|
23 |
|
24 namespace CdlCompilerToolkit { |
|
25 |
|
26 |
|
27 CCdlTkWriteClientHeader::CCdlTkWriteClientHeader(const CCdlTkInterface& aCdl) |
|
28 : iCdl(aCdl) |
|
29 { |
|
30 AssertInterfaceNotExtended(iCdl); |
|
31 } |
|
32 |
|
33 CCdlTkWriteClientHeader::~CCdlTkWriteClientHeader() |
|
34 { |
|
35 } |
|
36 |
|
37 void CCdlTkWriteClientHeader::Process() |
|
38 { |
|
39 string baseName = CdlBaseNameAndPath(iCdl); |
|
40 |
|
41 string commonHeaderName(baseName + KCommonHeader); |
|
42 CCdlTkWriteCommonDefs::ExportCommonDefs(iCdl, commonHeaderName); |
|
43 |
|
44 CCdlTkFileCleanup temp; |
|
45 ofstream out; |
|
46 CdlTkUtil::OpenTempOutput(out, temp); |
|
47 string clientHeaderName(baseName + ".h"); |
|
48 ProcessApi(out, clientHeaderName); |
|
49 out.close(); |
|
50 CdlTkUtil::ExportFile(temp, clientHeaderName); |
|
51 } |
|
52 |
|
53 const string KClientApi = "$COMMENT $INDENT inline $TYPE $NAME $PARAMS $CONST\t\t{ $RETURN $CALL; }"; |
|
54 const string KClientDataCall = "*($TYPE)($SCOPE::GetData($UID, EApiId_$NAME))"; |
|
55 const string KClientFuncCall = "(*($TYPE)($SCOPE::GetFunction($UID, EApiId_$NAME)))($PARAMS)"; |
|
56 |
|
57 void CCdlTkWriteClientHeader::WriteApi(const CCdlTkApi& aApi, ofstream& aStream, bool aCInstanceMember, const string& aIndent) const |
|
58 { |
|
59 CdlTkUtil::CReplaceSet callSet; |
|
60 callSet.Add("$TYPE", aApi.PointerType()); |
|
61 callSet.Add("$SCOPE::", aCInstanceMember ? "" : "CdlEngine::"); |
|
62 callSet.Add("$UID, ", aCInstanceMember ? "" : "KCdlInterfaceUid, "); |
|
63 callSet.Add("$NAME", aApi.Name()); |
|
64 callSet.Add("$PARAMS", aApi.IsFunc() ? aApi.AsFunc().ParamNameList() : ""); |
|
65 string call = CdlTkUtil::MultiReplace(callSet, aApi.IsFunc() ? KClientFuncCall : KClientDataCall); |
|
66 |
|
67 string comment = CdlTkUtil::Replace("//", aIndent+"//", aApi.Comment()); |
|
68 |
|
69 CdlTkUtil::CReplaceSet apiSet; |
|
70 apiSet.Add("$TYPE", ClientReturnType(aApi)); |
|
71 apiSet.Add("$NAME ", aApi.Name()); |
|
72 apiSet.Add("$PARAMS ", aApi.IsFunc() ? aApi.ParamsTypeAndNameList() : string("()")); |
|
73 apiSet.Add("$CONST", aCInstanceMember ? " const" : ""); |
|
74 apiSet.Add("$RETURN ", (!aApi.IsFunc() || !aApi.IsVoidReturn()) ? "return " : ""); |
|
75 apiSet.Add("$CALL", call); |
|
76 apiSet.Add("$INDENT ", aIndent); |
|
77 apiSet.Add("$COMMENT ", comment); |
|
78 string api = CdlTkUtil::MultiReplace(apiSet, KClientApi); |
|
79 |
|
80 aStream << api << endl; |
|
81 aStream << endl; |
|
82 } |
|
83 |
|
84 string CCdlTkWriteClientHeader::ClientReturnType(const CCdlTkApi& aApi) const |
|
85 { |
|
86 string ret = aApi.ReturnType(); |
|
87 if (!aApi.IsFunc()) |
|
88 ret += " const&"; |
|
89 return ret; |
|
90 } |
|
91 |
|
92 |
|
93 const string KBodyStart = "\ |
|
94 /*\n\ |
|
95 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\ |
|
96 * All rights reserved.\n\ |
|
97 * This component and the accompanying materials are made available\n\ |
|
98 * under the terms of \"Eclipse Public License v1.0\"\n\ |
|
99 * which accompanies this distribution, and is available\n\ |
|
100 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\ |
|
101 *\n\ |
|
102 * Initial Contributors:\n\ |
|
103 * Nokia Corporation - initial contribution.\n\ |
|
104 *\n\ |
|
105 * Contributors:\n\ |
|
106 *\n\ |
|
107 * Description:\n\ |
|
108 *\n\ |
|
109 */\n\n\ |
|
110 // This file was generated by:\n\ |
|
111 // $CMDLINE\n\ |
|
112 // It contains the client API.\n\ |
|
113 // It should not be modified manually.\n\ |
|
114 \n\ |
|
115 $ADDITIONAL\ |
|
116 #ifndef $CDLGUARD\n\ |
|
117 #define $CDLGUARD\n\ |
|
118 \n\ |
|
119 #include <cdlengine.h>\n\ |
|
120 #include <$FILE.common.h>\n\ |
|
121 \n\ |
|
122 namespace $CDLNS\n\ |
|
123 {\n\ |
|
124 \n\ |
|
125 class CInstance;\n\ |
|
126 \n\ |
|
127 // Standard interface functions \n\ |
|
128 inline void LoadCustomisationL(const TCdlRef& aRef) { CdlEngine::LoadCustomisationL(aRef); }\n\ |
|
129 inline void LoadCustomisationL(const TDesC& aLibName, TInt aInstId) { TCdlRef ref = { aInstId, { KCdlInterfaceUidValue }, &aLibName }; LoadCustomisationL(ref); }\n\ |
|
130 inline void RequireCustomisationL() { CdlEngine::RequireCustomisationL(&KCdlInterface); }\n\ |
|
131 inline TBool IsCustomisationStarted() { return CdlEngine::IsCustomisationStarted(&KCdlInterface); }\n\ |
|
132 inline const CInstance& CustomisationInstance() { return (const CInstance&)(CdlEngine::CustomisationInstance(KCdlInterfaceUid)); }\n\ |
|
133 inline void SetCustomisationChangeObserverL(MCdlChangeObserver* aObserver) { CdlEngine::SetCustomisationChangeObserverL(aObserver, KCdlInterfaceUid); }\n\ |
|
134 \n\ |
|
135 inline const TCdlRef& LastAccessedRef() { return CdlEngine::LastAccessedRef(KCdlInterfaceUid); }\n\ |
|
136 inline void FileNameRelativeToLastAccessedInstance(TFileName& aFileName) { CdlEngine::FileNameRelativeToLastAccessedInstance(KCdlInterfaceUid, aFileName); }\n\ |
|
137 \n\ |
|
138 \n\ |
|
139 // CDL API functions, as defined in $FILE\n\ |
|
140 \n"; |
|
141 |
|
142 const string KPragmaMinTypeInfo = "\ |
|
143 #ifdef __VC32__\n\ |
|
144 #pragma component(mintypeinfo, $ONOFF)\n\ |
|
145 #endif\n\ |
|
146 \n"; |
|
147 |
|
148 const string KBodyMid = "\ |
|
149 \n\ |
|
150 \n\ |
|
151 class CInstance : public CCdlInstance\n\ |
|
152 \t{\n\ |
|
153 public:\n\ |
|
154 \tenum { ETypeId = KCdlInterfaceUidValue };\n\ |
|
155 \n\ |
|
156 \tinline static const CInstance& CustomisationInstance() { return (const CInstance&)(CdlEngine::CustomisationInstance(KCdlInterfaceUid)); }\n\ |
|
157 \tinline static CInstance* NewL(const TCdlRef& aRef, const CCdlInstance* aSubLayer = NULL) { return (CInstance*) CCdlInstance::NewL(aRef, &KCdlInterface, aSubLayer); }\n\ |
|
158 \tinline static CInstance* NewLC(const TCdlRef& aRef, const CCdlInstance* aSubLayer = NULL) { return (CInstance*) CCdlInstance::NewLC(aRef, &KCdlInterface, aSubLayer); }\n\ |
|
159 \tinline static CInstance* NewL(const TDesC& aLibName, TInt aImplId, const CCdlInstance* aSubLayer = NULL) { TCdlRef ref = { aImplId, { KCdlInterfaceUidValue }, &aLibName }; return NewL(ref, aSubLayer); }\n\ |
|
160 \tinline static CInstance* NewLC(const TDesC& aLibName, TInt aImplId, const CCdlInstance* aSubLayer = NULL) { TCdlRef ref = { aImplId, { KCdlInterfaceUidValue }, &aLibName }; return NewLC(ref, aSubLayer); }\n\ |
|
161 \n\ |
|
162 \tinline const CInstance* SubLayer() { return static_cast<const CInstance*>(CCdlInstance::SubLayer()); }\n\ |
|
163 \n\ |
|
164 // CDL API functions, as defined in $FILE\n\ |
|
165 \n"; |
|
166 |
|
167 const string KBodyEnd = "\ |
|
168 private:\n\ |
|
169 \tCInstance();\n\ |
|
170 \t};\n\ |
|
171 \n"; |
|
172 |
|
173 const string KBodyEndNameSpace = "\ |
|
174 } // end of namespace $CDLNS\n\ |
|
175 #endif // $CDLGUARD\n"; |
|
176 |
|
177 const int KMsvcClassMaxSize = 1000; |
|
178 const string KTypeInfoOn = "on"; |
|
179 const string KTypeInfoOff = "off"; |
|
180 |
|
181 void CCdlTkWriteClientHeader::ProcessApi(ofstream& aStream, const string& aFileName) const |
|
182 { |
|
183 CdlTkUtil::CReplaceSet replace; |
|
184 replace.Add("$FILE", CdlTkUtil::ToLower(CdlTkUtil::StripPath(iCdl.FileName()))); |
|
185 replace.Add("$CDLGUARD", HeaderGuardName(iCdl.FileName())); |
|
186 replace.Add("$CDLNS", iCdl.NamespaceName()); |
|
187 replace.Add("$CMDLINE", CdlTkUtil::CommandLine()); |
|
188 replace.Add("$ADDITIONAL", iCdl.AdditionalComment()); |
|
189 |
|
190 bool tooMuchTypeInfo = iCdl.ApiList().size() > KMsvcClassMaxSize; |
|
191 |
|
192 aStream << CdlTkUtil::MultiReplace(replace, KBodyStart); |
|
193 |
|
194 CCdlTkApiList::const_iterator pApi; |
|
195 for (pApi = iCdl.ApiList().begin(); pApi != iCdl.ApiList().end(); ++pApi) |
|
196 WriteApi(**pApi, aStream, false, ""); |
|
197 |
|
198 if(tooMuchTypeInfo) |
|
199 aStream << CdlTkUtil::Replace("$ONOFF", KTypeInfoOn, KPragmaMinTypeInfo); |
|
200 |
|
201 aStream << CdlTkUtil::MultiReplace(replace, KBodyMid); |
|
202 |
|
203 for (pApi = iCdl.ApiList().begin(); pApi != iCdl.ApiList().end(); ++pApi) |
|
204 WriteApi(**pApi, aStream, true, "\t"); |
|
205 |
|
206 aStream << CdlTkUtil::MultiReplace(replace, KBodyEnd); |
|
207 |
|
208 if(tooMuchTypeInfo) |
|
209 aStream << CdlTkUtil::Replace("$ONOFF", KTypeInfoOff, KPragmaMinTypeInfo); |
|
210 |
|
211 aStream << CdlTkUtil::MultiReplace(replace, KBodyEndNameSpace); |
|
212 } |
|
213 |
|
214 |
|
215 } // end of namespace CdlCompilerToolkit |
|
216 |