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 :
10 : #include "sal/config.h"
11 :
12 : #include <set>
13 : #include <vector>
14 :
15 : #include "osl/file.h"
16 : #include "osl/file.hxx"
17 : #include "osl/mutex.hxx"
18 : #include "rtl/ref.hxx"
19 : #include "rtl/ustring.hxx"
20 : #include "unoidl/unoidl.hxx"
21 :
22 : #include "legacyprovider.hxx"
23 : #include "sourcefileprovider.hxx"
24 : #include "sourcetreeprovider.hxx"
25 : #include "unoidlprovider.hxx"
26 :
27 : namespace unoidl {
28 :
29 : namespace {
30 :
31 : class AggregatingModule: public ModuleEntity {
32 : public:
33 618 : AggregatingModule(
34 : std::vector< rtl::Reference< Provider > > const & providers,
35 : OUString const & name):
36 618 : providers_(providers), name_(name)
37 618 : {}
38 :
39 : private:
40 1236 : virtual ~AggregatingModule() throw () {}
41 :
42 : virtual std::vector< OUString > getMemberNames() const SAL_OVERRIDE;
43 :
44 : virtual rtl::Reference< MapCursor > createCursor() const SAL_OVERRIDE;
45 :
46 : std::vector< rtl::Reference< Provider > > providers_;
47 : OUString name_;
48 : };
49 :
50 0 : std::vector< OUString > AggregatingModule::getMemberNames() const {
51 0 : std::set< OUString > names;
52 0 : for (std::vector< rtl::Reference< Provider > >::const_iterator i(
53 0 : providers_.begin());
54 0 : i != providers_.end(); ++i)
55 : {
56 0 : rtl::Reference< Entity > ent((*i)->findEntity(name_));
57 0 : if (ent.is() && ent->getSort() == Entity::SORT_MODULE) {
58 : std::vector< OUString > ns(
59 0 : static_cast< ModuleEntity * >(ent.get())->getMemberNames());
60 0 : names.insert(ns.begin(), ns.end());
61 : }
62 0 : }
63 0 : return std::vector< OUString >(names.begin(), names.end());
64 : }
65 :
66 : class AggregatingCursor: public MapCursor {
67 : public:
68 489 : AggregatingCursor(
69 : std::vector< rtl::Reference< Provider > > const & providers,
70 : OUString const & name):
71 489 : providers_(providers), name_(name), iterator_(providers_.begin())
72 489 : { findCursor(); }
73 :
74 : private:
75 978 : virtual ~AggregatingCursor() throw () {}
76 :
77 : virtual rtl::Reference< Entity > getNext(OUString * name) SAL_OVERRIDE;
78 :
79 : void findCursor();
80 :
81 : std::vector< rtl::Reference< Provider > > providers_;
82 : OUString name_;
83 : std::vector< rtl::Reference< Provider > >::iterator iterator_;
84 : rtl::Reference< MapCursor > cursor_;
85 : std::set< OUString > seen_;
86 : };
87 :
88 18394 : rtl::Reference< Entity > AggregatingCursor::getNext(OUString * name) {
89 37554 : while (cursor_.is()) {
90 18671 : OUString n;
91 19437 : rtl::Reference< Entity > ent(cursor_->getNext(&n));
92 18671 : if (ent.is()) {
93 18118 : if (seen_.insert(n).second) {
94 17905 : if (name != 0) {
95 17905 : *name = n;
96 : }
97 17905 : return ent->getSort() == Entity::SORT_MODULE
98 : ? new AggregatingModule(
99 19734 : providers_, (name_.isEmpty() ? name_ : name_ + ".") + n)
100 36453 : : ent;
101 : }
102 : } else {
103 553 : cursor_.clear();
104 553 : findCursor();
105 : }
106 766 : }
107 489 : return rtl::Reference< Entity >();
108 : }
109 :
110 1042 : void AggregatingCursor::findCursor() {
111 2207 : for (; !cursor_.is() && iterator_ != providers_.end(); ++iterator_) {
112 1165 : if (name_.isEmpty()) {
113 31 : cursor_ = (*iterator_)->createRootCursor();
114 : } else {
115 1134 : rtl::Reference< Entity > ent((*iterator_)->findEntity(name_));
116 1134 : if (ent.is() && ent->getSort() == Entity::SORT_MODULE) {
117 1566 : cursor_ = static_cast< ModuleEntity * >(ent.get())->
118 1044 : createCursor();
119 1134 : }
120 : }
121 : }
122 1042 : }
123 :
124 18 : rtl::Reference< MapCursor > AggregatingModule::createCursor() const {
125 18 : return new AggregatingCursor(providers_, name_);
126 : }
127 :
128 : }
129 :
130 0 : NoSuchFileException::~NoSuchFileException() throw () {}
131 :
132 0 : FileFormatException::~FileFormatException() throw () {}
133 :
134 650604 : Entity::~Entity() throw () {}
135 :
136 1370 : MapCursor::~MapCursor() throw () {}
137 :
138 3159 : ModuleEntity::~ModuleEntity() throw () {}
139 :
140 647445 : PublishableEntity::~PublishableEntity() throw () {}
141 :
142 27326 : EnumTypeEntity::~EnumTypeEntity() throw () {}
143 :
144 87586 : PlainStructTypeEntity::~PlainStructTypeEntity() throw () {}
145 :
146 2328 : PolymorphicStructTypeTemplateEntity::~PolymorphicStructTypeTemplateEntity()
147 1164 : throw ()
148 2328 : {}
149 :
150 121340 : ExceptionTypeEntity::~ExceptionTypeEntity() throw () {}
151 :
152 987726 : InterfaceTypeEntity::~InterfaceTypeEntity() throw () {}
153 :
154 6834 : TypedefEntity::~TypedefEntity() throw () {}
155 :
156 25246 : ConstantGroupEntity::~ConstantGroupEntity() throw () {}
157 :
158 11116 : SingleInterfaceBasedServiceEntity::~SingleInterfaceBasedServiceEntity() throw ()
159 11116 : {}
160 :
161 23166 : AccumulationBasedServiceEntity::~AccumulationBasedServiceEntity() throw () {}
162 :
163 2214 : InterfaceBasedSingletonEntity::~InterfaceBasedSingletonEntity() throw () {}
164 :
165 8 : ServiceBasedSingletonEntity::~ServiceBasedSingletonEntity() throw () {}
166 :
167 628 : Provider::~Provider() throw () {}
168 :
169 1415 : rtl::Reference< Provider > loadProvider(
170 : rtl::Reference< Manager > const & manager, OUString const & uri)
171 : {
172 1415 : osl::DirectoryItem item;
173 1415 : if (osl::DirectoryItem::get(uri, item) == osl::FileBase::E_None) {
174 1415 : osl::FileStatus status(osl_FileStatus_Mask_Type);
175 2830 : if (item.getFileStatus(status) == osl::FileBase::E_None
176 1415 : && status.getFileType() == osl::FileStatus::Directory)
177 : {
178 334 : return new detail::SourceTreeProvider(manager, uri);
179 1081 : }
180 : }
181 1081 : if (uri.endsWith(".idl")) {
182 521 : return new detail::SourceFileProvider(manager, uri);
183 : }
184 : try {
185 745 : return new detail::UnoidlProvider(uri);
186 0 : } catch (FileFormatException & e) {
187 : SAL_INFO(
188 : "unoidl",
189 : "FileFormatException \"" << e.getDetail() << "\", retrying <" << uri
190 : << "> as legacy format");
191 0 : return new detail::LegacyProvider(manager, uri);
192 1415 : }
193 : }
194 :
195 1230 : void Manager::addProvider(rtl::Reference< Provider > const & provider) {
196 : assert(provider.is());
197 1230 : osl::MutexGuard g(mutex_);
198 1230 : providers_.push_back(provider);
199 1230 : }
200 :
201 659827 : rtl::Reference< Entity > Manager::findEntity(rtl::OUString const & name) const {
202 : //TODO: caching? (here or in cppuhelper::TypeManager?)
203 659827 : osl::MutexGuard g(mutex_);
204 3206654 : for (std::vector< rtl::Reference< Provider > >::const_iterator i(
205 659827 : providers_.begin());
206 2577654 : i != providers_.end(); ++i)
207 : {
208 1250708 : rtl::Reference< Entity > ent((*i)->findEntity(name));
209 1250708 : if (ent.is()) {
210 621708 : return ent;
211 : }
212 629000 : }
213 38119 : return rtl::Reference< Entity >();
214 : }
215 :
216 471 : rtl::Reference< MapCursor > Manager::createCursor(rtl::OUString const & name)
217 : const
218 : {
219 471 : return new AggregatingCursor(providers_, name);
220 : }
221 :
222 362 : Manager::~Manager() throw () {}
223 :
224 : }
225 :
226 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|