|
1 /* |
|
2 * Copyright (c) 2002-2004 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 */ |
|
18 |
|
19 |
|
20 |
|
21 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
22 #pragma warning (disable:4786) |
|
23 #include "UpdateLayoutApi.h" |
|
24 #include <cdlcompilertoolkit/cdltkprocess.h> |
|
25 #include "Lay2Cdl.h" |
|
26 #include "LayoutParse.h" |
|
27 #include "LayoutCompilerErr.h" |
|
28 #include <sstream> |
|
29 #include <iostream> |
|
30 |
|
31 using namespace std; |
|
32 |
|
33 typedef LayoutProcessArgsErr<UpdateLayoutApi> UpdateLayoutApiArgsErr; |
|
34 |
|
35 |
|
36 int UpdateLayoutApi::Process(const vector<string>& args) |
|
37 { |
|
38 if (args.size() != 6) |
|
39 throw UpdateLayoutApiArgsErr(); |
|
40 |
|
41 const string& cdlName = args[2]; |
|
42 const string& layoutName = args[3]; |
|
43 const string& legacyName = args[4]; |
|
44 const string& newName = args[5]; |
|
45 |
|
46 UpdateLayoutApi(cdlName, layoutName, legacyName, newName); |
|
47 |
|
48 return 0; |
|
49 } |
|
50 |
|
51 void UpdateLayoutApi::ShowHelp(ostream& stream) |
|
52 { |
|
53 stream << "UpdateLayoutApi <LayoutCdlApi> <CurrentLayout> <LegacyLayout> <NewLayout>" << endl; |
|
54 } |
|
55 |
|
56 UpdateLayoutApi::UpdateLayoutApi(const std::string& aCdlName, const std::string& aLayoutName, const std::string& aLegacyName, const std::string& aNewName) |
|
57 : iCdlName(aCdlName), iLegacyName(aLegacyName), iInterface(0), iLayout(0), iLegacy(0), iNew(0), iInterfaceChanged(false) |
|
58 { |
|
59 LoadFiles(aLayoutName, aNewName); |
|
60 MergeAndCheck(); |
|
61 ProcessNewApi(); |
|
62 WriteFiles(); |
|
63 Report(); |
|
64 } |
|
65 |
|
66 UpdateLayoutApi::~UpdateLayoutApi() |
|
67 { |
|
68 delete iInterface; |
|
69 delete iLayout; |
|
70 delete iLegacy; |
|
71 delete iNew; |
|
72 } |
|
73 |
|
74 void UpdateLayoutApi::LoadFiles(const std::string& aLayoutName, const std::string& aNewName) |
|
75 { |
|
76 CCdlTkCdlFileParser cdlParser(iCdlName); |
|
77 auto_ptr<CCdlTkInterface> iface(cdlParser.LoadAndParse(false)); |
|
78 iInterface = iface.get(); |
|
79 iface.release(); |
|
80 |
|
81 auto_ptr<TLayParseLayout> layout(TLayParseLayout::Parse(aLayoutName)); |
|
82 iLayout = layout.get(); |
|
83 layout.release(); |
|
84 |
|
85 auto_ptr<TLayParseLayout> legacy(TLayParseLayout::Parse(iLegacyName)); |
|
86 iLegacy = legacy.get(); |
|
87 legacy.release(); |
|
88 |
|
89 auto_ptr<TLayParseLayout> newLay(TLayParseLayout::Parse(aNewName)); |
|
90 iNew = newLay.get(); |
|
91 newLay.release(); |
|
92 } |
|
93 |
|
94 void UpdateLayoutApi::MergeAndCheck() |
|
95 { |
|
96 TLayout combined(*iLayout); |
|
97 combined.Merge(TLayout::KMergeModeMerge, *iLegacy); |
|
98 auto_ptr<CCdlTkInterface> iface(LayoutToCdl::LayoutToInterface(combined)); |
|
99 InterfaceCheck check; |
|
100 CCdlTkApiChecker process(*iInterface, *iface, check); |
|
101 process.Process(); |
|
102 } |
|
103 |
|
104 void UpdateLayoutApi::ProcessNewApi() |
|
105 { |
|
106 auto_ptr<CCdlTkInterface> newIface(LayoutToCdl::LayoutToInterface(*iNew)); |
|
107 CCdlTkApiChecker process(*iInterface, *newIface, *this); |
|
108 process.Process(); |
|
109 if (iInterfaceChanged) |
|
110 { |
|
111 CCdlTkInterface* curExt = iInterface->UltimateExtension(); |
|
112 if (!iExt) |
|
113 iExt = new CCdlTkInterface(); |
|
114 curExt->SetExtension(iExt); |
|
115 iExt->SetBase(curExt); |
|
116 iExt->Header().SetVersion(CCdlTkInterfaceHeader::CVersion(curExt->Header().Version().Major(), curExt->Header().Version().Minor()+1)); |
|
117 } |
|
118 } |
|
119 |
|
120 void UpdateLayoutApi::WriteFiles() |
|
121 { |
|
122 if (iInterfaceChanged) |
|
123 { |
|
124 } |
|
125 if (iLegacyUpdated) |
|
126 { |
|
127 } |
|
128 } |
|
129 |
|
130 void UpdateLayoutApi::Report() |
|
131 { |
|
132 if (!iReport.empty()) |
|
133 cout << iReport; |
|
134 } |
|
135 |
|
136 void UpdateLayoutApi::StartCheck() |
|
137 { |
|
138 } |
|
139 |
|
140 void UpdateLayoutApi::CheckComplete() |
|
141 { |
|
142 } |
|
143 |
|
144 void UpdateLayoutApi::ApiInBoth(const CCdlTkApi& aApi) |
|
145 { |
|
146 } |
|
147 |
|
148 void UpdateLayoutApi::ApiNotInLeft(const CCdlTkApi& aApi) |
|
149 { |
|
150 // new API present - add it to the extension |
|
151 iInterfaceChanged = true; |
|
152 iExt->ApiList().push_back(aApi.Clone(*iExt)); |
|
153 } |
|
154 |
|
155 void UpdateLayoutApi::ApiNotInRight(const CCdlTkApi& aApi) |
|
156 { |
|
157 // old API not present - rename it in the API, add data to legacy. |
|
158 iInterfaceChanged = true; |
|
159 |
|
160 string oldName = aApi.Name(); |
|
161 CCdlTkApi* api = iInterface->ApiList().Find(oldName); |
|
162 |
|
163 CCdlTkInterfaceHeader& header = iInterface->UltimateExtension()->Header(); |
|
164 stringstream newName; |
|
165 newName << oldName << "_V" << header.Version().Major() << "_" << header.Version().Minor(); |
|
166 |
|
167 api->SetName(newName.str()); |
|
168 AddDataToLegacy(oldName, newName.str()); |
|
169 } |
|
170 |
|
171 void UpdateLayoutApi::AddDataToLegacy(const std::string& /*aOldName*/, const std::string& /*aNewName*/) |
|
172 { |
|
173 iLegacyUpdated = true; |
|
174 } |
|
175 |
|
176 |
|
177 void UpdateLayoutApi::InterfaceCheck::StartCheck() |
|
178 { |
|
179 } |
|
180 |
|
181 void UpdateLayoutApi::InterfaceCheck::CheckComplete() |
|
182 { |
|
183 } |
|
184 |
|
185 void UpdateLayoutApi::InterfaceCheck::ApiInBoth(const CCdlTkApi&) |
|
186 { |
|
187 } |
|
188 |
|
189 void UpdateLayoutApi::InterfaceCheck::ApiNotInLeft(const CCdlTkApi&) |
|
190 { |
|
191 throw false; |
|
192 } |
|
193 |
|
194 void UpdateLayoutApi::InterfaceCheck::ApiNotInRight(const CCdlTkApi&) |
|
195 { |
|
196 throw false; |
|
197 } |