summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2018-05-01 21:08:51 -0500
committerYifan Hong2018-05-02 16:31:45 -0500
commit5541069e3c155797649e3eb568349d8cb7f119d6 (patch)
tree713c6292fd703048736706ce86c8b6fa2b094e1c /ManifestHal.cpp
parent7030c38ce61f520b32ab3f7761289a5d7534a74d (diff)
downloadplatform-system-libvintf-5541069e3c155797649e3eb568349d8cb7f119d6.tar.gz
platform-system-libvintf-5541069e3c155797649e3eb568349d8cb7f119d6.tar.xz
platform-system-libvintf-5541069e3c155797649e3eb568349d8cb7f119d6.zip
Add ManifestHal::insertInstance
... that allows to add <fqname> to ManifestHal object from code. This helps, for example, lshal. Bug: 74247301 Test: pass Change-Id: I28b5bb1240e24f1762d2df4cb1ded242fabea99e
Diffstat (limited to 'ManifestHal.cpp')
-rw-r--r--ManifestHal.cpp75
1 files changed, 47 insertions, 28 deletions
diff --git a/ManifestHal.cpp b/ManifestHal.cpp
index 2d0e246..a80d064 100644
--- a/ManifestHal.cpp
+++ b/ManifestHal.cpp
@@ -96,47 +96,66 @@ void ManifestHal::appendAllVersions(std::set<Version>* ret) const {
96 }); 96 });
97} 97}
98 98
99static bool verifyInstances(const std::set<FqInstance>& fqInstances, std::string* error) { 99bool ManifestHal::verifyInstance(const FqInstance& fqInstance, std::string* error) const {
100 for (const FqInstance& fqInstance : fqInstances) { 100 if (fqInstance.hasPackage() && fqInstance.getPackage() != this->getName()) {
101 if (fqInstance.hasPackage()) { 101 if (error) {
102 if (error) *error = "Should not specify package: \"" + fqInstance.string() + "\""; 102 *error = "Should not add \"" + fqInstance.string() + "\" to a HAL with name " +
103 return false; 103 this->getName();
104 }
105 if (!fqInstance.hasVersion()) {
106 if (error) *error = "Should specify version: \"" + fqInstance.string() + "\"";
107 return false;
108 } 104 }
109 if (!fqInstance.hasInterface()) { 105 return false;
110 if (error) *error = "Should specify interface: \"" + fqInstance.string() + "\""; 106 }
111 return false; 107 if (!fqInstance.hasVersion()) {
112 } 108 if (error) *error = "Should specify version: \"" + fqInstance.string() + "\"";
113 if (!fqInstance.hasInstance()) { 109 return false;
114 if (error) *error = "Should specify instance: \"" + fqInstance.string() + "\""; 110 }
111 if (!fqInstance.hasInterface()) {
112 if (error) *error = "Should specify interface: \"" + fqInstance.string() + "\"";
113 return false;
114 }
115 if (!fqInstance.hasInstance()) {
116 if (error) *error = "Should specify instance: \"" + fqInstance.string() + "\"";
117 return false;
118 }
119 return true;
120}
121
122bool ManifestHal::insertInstances(const std::set<FqInstance>& fqInstances, std::string* error) {
123 for (const FqInstance& e : fqInstances) {
124 if (!insertInstance(e, error)) {
115 return false; 125 return false;
116 } 126 }
117 } 127 }
118 return true; 128 return true;
119} 129}
120 130
121bool ManifestHal::insertInstances(const std::set<FqInstance>& fqInstances, std::string* error) { 131bool ManifestHal::insertInstance(const FqInstance& e, std::string* error) {
122 if (!verifyInstances(fqInstances, error)) { 132 if (!verifyInstance(e, error)) {
123 return false; 133 return false;
124 } 134 }
125 135
126 for (const FqInstance& e : fqInstances) { 136 size_t minorVer = e.getMinorVersion();
127 FqInstance withPackage; 137 for (auto it = mAdditionalInstances.begin(); it != mAdditionalInstances.end();) {
128 if (!withPackage.setTo(this->getName(), e.getMajorVersion(), e.getMinorVersion(), 138 if (it->version().majorVer == e.getMajorVersion() && it->interface() == e.getInterface() &&
129 e.getInterface(), e.getInstance())) { 139 it->instance() == e.getInstance()) {
130 if (error) { 140 minorVer = std::max(minorVer, it->version().minorVer);
131 *error = "Cannot create FqInstance with package='" + this->getName() + 141 it = mAdditionalInstances.erase(it);
132 "', version='" + to_string(Version(e.getVersion())) + "', interface='" + 142 } else {
133 e.getInterface() + "', instance='" + e.getInstance() + "'"; 143 ++it;
134 } 144 }
135 return false; 145 }
146
147 FqInstance toAdd;
148 if (!toAdd.setTo(this->getName(), e.getMajorVersion(), minorVer, e.getInterface(),
149 e.getInstance())) {
150 if (error) {
151 *error = "Cannot create FqInstance with package='" + this->getName() + "', version='" +
152 to_string(Version(e.getMajorVersion(), minorVer)) + "', interface='" +
153 e.getInterface() + "', instance='" + e.getInstance() + "'";
136 } 154 }
137 mAdditionalInstances.emplace(std::move(withPackage), this->transportArch, this->format); 155 return false;
138 } 156 }
139 157
158 mAdditionalInstances.emplace(std::move(toAdd), this->transportArch, this->format);
140 return true; 159 return true;
141} 160}
142 161