Skip to content

Commit

Permalink
config
Browse files Browse the repository at this point in the history
  • Loading branch information
spnettec committed Jan 26, 2025
1 parent d4d2570 commit e52085b
Showing 1 changed file with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.eclipse.kura.marshalling.Marshaller;
import org.eclipse.kura.marshalling.Unmarshaller;
import org.eclipse.kura.system.SystemService;
import org.eclipse.kura.util.service.ServiceUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
Expand Down Expand Up @@ -832,13 +831,13 @@ synchronized void registerSelfConfiguringComponent(final String pid, final Strin
}
logger.info("Registering SelfConfiguringComponent - {}....", pid);
if (!this.servicePidByPid.containsKey(pid)) {
// logger.error("servicePid:{} is not created by Factory,PID is:{}", servicePid, pid);
this.servicePidByPid.put(pid, servicePid);
}
if (this.allActivatedPids.contains(pid)) {
logger.error("pid:{} is already actived, servicePid is:{}", pid, servicePid);
} else {
this.allActivatedPids.add(pid);
}
this.allActivatedPids.add(pid);
if (this.activatedSelfConfigComponents.contains(pid)) {
logger.error("pid:{} is already in SelfConfigComponents, servicePid is:{}", pid, servicePid);
} else {
Expand Down Expand Up @@ -1316,26 +1315,49 @@ private ComponentConfiguration getConfigurableComponentConfiguration(String pid)

private ComponentConfiguration getSelfConfiguringComponentConfiguration(String pid) {
ComponentConfiguration cc = null;
final ServiceReference<?>[] refs = ServiceUtil.getServiceReferences(this.bundleContext,
SelfConfiguringComponent.class, null);

try {
for (ServiceReference<?> ref : refs) {
String ppid = (String) ref.getProperty(KURA_SERVICE_PID);
final SelfConfiguringComponent selfConfigComp = (SelfConfiguringComponent) this.bundleContext
.getService(ref);
if (pid.equals(ppid)) {

cc = selfConfigComp.getConfiguration();
if (!isValidSelfConfiguringComponent(pid, cc)) {
return null;
String filterExpression = "(" + KURA_SERVICE_PID + "=" + pid + ")";
ServiceReference<?>[] refs = this.ctx.getBundleContext().getServiceReferences((String) null,
filterExpression);
if (refs != null) {
for (ServiceReference<?> ref : refs) {
String ppid = (String) ref.getProperty(KURA_SERVICE_PID);
if (pid.equals(ppid)) {
Object obj = this.ctx.getBundleContext().getService(ref);
try {
if (obj instanceof SelfConfiguringComponent) {
SelfConfiguringComponent selfConfigComp = null;
selfConfigComp = (SelfConfiguringComponent) obj;
try {
cc = selfConfigComp.getConfiguration();
if (!isValidSelfConfiguringComponent(pid, cc)) {

return null;
}
} catch (KuraException e) {
logger.error(GETTING_CONFIGURATION_ERROR, pid, e);
}
} else {
if (obj == null) {
cc = getConfigurableComponentConfiguration(pid);
if (cc == null) {
logger.error("null ref object. properties:{}", ref.getProperties());
}
} else {
logger.error(
"Component {}, pid: {} is not a SelfConfiguringComponent. Ignoring it.",
obj, pid);
}
}

} finally {
this.ctx.getBundleContext().ungetService(ref);
}
}
}
}
} catch (KuraException e) {
} catch (InvalidSyntaxException e) {
logger.error(GETTING_CONFIGURATION_ERROR, pid, e);
} finally {
ServiceUtil.ungetServiceReferences(this.bundleContext, refs);
}

return cc;
Expand Down

0 comments on commit e52085b

Please sign in to comment.