Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "dependy.hxx"
22 : : #include <iostream>
23 : : #include "../support/syshelp.hxx"
24 : : #include "../support/list.hxx"
25 : : #include "xmltree.hxx"
26 : : #include "parse.hxx"
27 : :
28 : :
29 : :
30 : : Simstr ShortName(const Simstr & i_rService);
31 : :
32 : :
33 : :
34 : 0 : Service::Service( const char * i_sName )
35 [ # # ]: 0 : : sName(i_sName)
36 : : // aImplementations
37 : : {
38 : 0 : }
39 : :
40 : : ServiceInfo &
41 : 0 : Service::AddImplementation( const char * i_sLibrary )
42 : : {
43 [ # # ][ # # ]: 0 : ServiceInfo * ret = new ServiceInfo(i_sLibrary);
44 [ # # ]: 0 : aImplementations.push_back(ret);
45 : 0 : return *ret;
46 : : }
47 : :
48 : 0 : ServiceInfo::ServiceInfo( const char * i_sLibrary )
49 [ # # ]: 0 : : sImplementingLibrary(i_sLibrary)
50 : : // aNeededServices
51 : : {
52 : 0 : }
53 : :
54 : : void
55 : 0 : ServiceInfo::AddDependency( const char * i_sNeededService )
56 : : {
57 [ # # ]: 0 : aNeededServices.push_back(i_sNeededService);
58 : 0 : }
59 : :
60 [ # # ][ # # ]: 0 : DependencyFinder::DependencyFinder()
61 : : {
62 : 0 : }
63 : :
64 : 0 : DependencyFinder::~DependencyFinder()
65 : : {
66 [ # # ]: 0 : for (Map_Services::const_iterator aIter = aServices.begin(); aIter != aServices.end(); ++aIter)
67 [ # # ][ # # ]: 0 : delete aIter->second;
68 : 0 : }
69 : :
70 : : void
71 : 0 : DependencyFinder::GatherData( const char * i_sSearchDirectory )
72 : : {
73 [ # # ]: 0 : List<Simstr> aFiles;
74 [ # # ]: 0 : GatherFileNames( aFiles, i_sSearchDirectory );
75 : :
76 [ # # ]: 0 : for ( unsigned i = 0; i < aFiles.size(); ++i )
77 : : {
78 [ # # ][ # # ]: 0 : ReadFile( aFiles[i].str() );
79 [ # # ]: 0 : }
80 : 0 : }
81 : :
82 : : void
83 : 0 : DependencyFinder::FindNeededServices( StringVector & o_rLibraries,
84 : : StringVector & o_rServices,
85 : : const Simstr & i_rService )
86 : : {
87 [ # # ]: 0 : Map_Services::const_iterator itService = aServices.find(i_rService);
88 [ # # ]: 0 : if ( itService == aServices.end() )
89 : : {
90 [ # # ]: 0 : std::cerr << "Error: Service \""
91 [ # # ]: 0 : << i_rService.str()
92 [ # # ]: 0 : << "\" not found."
93 [ # # ]: 0 : << std::endl;
94 : 0 : return ;
95 : : }
96 : :
97 [ # # ]: 0 : aResult_Libraries.erase( aResult_Libraries.begin(), aResult_Libraries.end() );
98 [ # # ]: 0 : aResult_Services.erase( aResult_Services.begin(), aResult_Services.end() );
99 : :
100 [ # # ]: 0 : Add2Result( *(*itService).second );
101 : :
102 [ # # ]: 0 : for ( std::set< Simstr >::const_iterator il = aResult_Libraries.begin();
103 : 0 : il != aResult_Libraries.end();
104 : : ++il )
105 : : {
106 [ # # ]: 0 : o_rLibraries.push_back(*il);
107 : : }
108 : :
109 [ # # ]: 0 : for ( std::set< Simstr >::const_iterator is = aResult_Services.begin();
110 : 0 : is != aResult_Services.end();
111 : : ++is )
112 : : {
113 [ # # ]: 0 : o_rServices.push_back(*is);
114 : : }
115 : : }
116 : :
117 : : void
118 : 0 : DependencyFinder::ReadFile( const char * i_sFilename )
119 : : {
120 [ # # ]: 0 : ModuleDescription aModule;
121 [ # # ]: 0 : X2CParser aParser(aModule);
122 : :
123 [ # # ][ # # ]: 0 : if ( !aParser.Parse(i_sFilename) )
124 : : {
125 [ # # ]: 0 : std::cerr << "Error: File \""
126 [ # # ]: 0 : << i_sFilename
127 [ # # ]: 0 : << "\" could not be parsed."
128 [ # # ]: 0 : << std::endl;
129 : 0 : return;
130 : : }
131 : :
132 : : // GetResults:
133 [ # # ][ # # ]: 0 : Simstr sModule = aModule.ModuleName();
134 : :
135 [ # # ]: 0 : List < const MultipleTextElement* > aImplServices;
136 [ # # ]: 0 : List < const MultipleTextElement* > aNeededServices;
137 : :
138 [ # # ]: 0 : aModule.Get_SupportedServices(aImplServices);
139 [ # # ]: 0 : aModule.Get_ServiceDependencies(aNeededServices);
140 : :
141 : 0 : unsigned nImplServicesSize = aImplServices.size();
142 : 0 : unsigned nNeededServicesSize = aNeededServices.size();
143 : :
144 [ # # ]: 0 : for ( unsigned i = 0; i < nImplServicesSize; ++i )
145 : : {
146 [ # # ]: 0 : const MultipleTextElement & rImpl = *aImplServices[i];
147 : :
148 [ # # ]: 0 : unsigned nImplDataSize = rImpl.Size();
149 [ # # ]: 0 : for ( unsigned di = 0; di < nImplDataSize; ++di )
150 : : {
151 [ # # ][ # # ]: 0 : Simstr sService = ShortName(rImpl.Data(di));
152 [ # # ]: 0 : Service * pService = aServices[sService];
153 [ # # ]: 0 : if (pService == 0)
154 : : {
155 [ # # ][ # # ]: 0 : pService = new Service(rImpl.Data(di));
[ # # ]
156 [ # # ]: 0 : aServices[sService] = pService;
157 : : }
158 [ # # ]: 0 : ServiceInfo & rSInfo = pService->AddImplementation(sModule);
159 : :
160 [ # # ]: 0 : for ( unsigned n = 0; n < nNeededServicesSize; ++n )
161 : : {
162 [ # # ][ # # ]: 0 : unsigned nNeededDataSize = aNeededServices[n]->Size();
163 [ # # ]: 0 : for ( unsigned dn = 0; dn < nNeededDataSize; ++dn )
164 : : {
165 [ # # ][ # # ]: 0 : if (! aNeededServices[n]->Data(dn).is_no_text())
[ # # ][ # # ]
166 [ # # ][ # # ]: 0 : rSInfo.AddDependency( ShortName(aNeededServices[n]->Data(dn)) );
[ # # ][ # # ]
[ # # ]
167 : : } // end for dn
168 : : } // end for n
169 [ # # ]: 0 : } // end for di
170 [ # # ][ # # ]: 0 : } // end for i
[ # # ][ # # ]
[ # # ]
171 : : }
172 : :
173 : : void
174 : 0 : DependencyFinder::Add2Result( const Service & i_rService )
175 : : {
176 : 0 : const ServiceInfo & rSInfo = i_rService.FirstImplementation();
177 : 0 : aResult_Libraries.insert(rSInfo.Library());
178 : :
179 : : const ServiceInfo::List_NeededServices & rNeededs
180 : 0 : = rSInfo.NeededServices();
181 [ # # ][ # # ]: 0 : for ( StringVector::const_iterator it = rNeededs.begin();
182 : 0 : it != rNeededs.end();
183 : : ++it )
184 : : {
185 : : std::pair< std::set< Simstr >::iterator, bool > aInsertResult
186 [ # # ]: 0 : = aResult_Services.insert(*it);
187 [ # # ]: 0 : if (aInsertResult.second)
188 : : { // Needed service not yet known
189 [ # # ]: 0 : Map_Services::const_iterator itFound = aServices.find(*it);
190 [ # # ]: 0 : if ( itFound == aServices.end() )
191 : : {
192 [ # # ]: 0 : std::cerr << "Needed service \""
193 [ # # ]: 0 : << (*it).str()
194 [ # # ]: 0 : << "\" not found,"
195 [ # # ]: 0 : << std::endl;
196 : : }
197 : : else
198 : : {
199 [ # # ]: 0 : Add2Result( *(*itFound).second );
200 : : }
201 : : } // endif (! aInsertResult.second)
202 : : } // end for (it)
203 : 0 : }
204 : :
205 : :
206 : :
207 : : Simstr
208 : 0 : ShortName(const Simstr & i_rService)
209 : : {
210 : 0 : const char * pStart = i_rService.str();
211 : 0 : const char * pEnd = strchr(pStart,' ');
212 [ # # ]: 0 : if (pEnd != 0)
213 : 0 : return Simstr(pStart, 0, int(pEnd-pStart));
214 : : else
215 : 0 : return i_rService;
216 [ + - ][ + - ]: 6 : }
217 : :
218 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|