Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,7 @@ default Descriptor describe() {
descriptor.add(providers().describe());
return descriptor;
}

/** Registers an IO instance, bypassing create method. Used in testing */
void register(IO instance);
}
19 changes: 9 additions & 10 deletions pi4j-core/src/main/java/com/pi4j/context/impl/DefaultContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import com.pi4j.provider.Providers;
import com.pi4j.provider.impl.DefaultProviders;
import com.pi4j.registry.Registry;
import com.pi4j.registry.impl.DefaultRegistry;
import com.pi4j.runtime.Runtime;
import com.pi4j.runtime.impl.DefaultRuntime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -58,7 +56,6 @@ public class DefaultContext implements Context {
private Runtime runtime = null;
private ContextConfig config = null;
private Providers providers = null;
private Registry registry = null;
private BoardInfo boardInfo = null;

/**
Expand Down Expand Up @@ -87,10 +84,7 @@ protected DefaultContext(ContextConfig config) {
this.config = config;

// create internal runtime state instance (READ-ONLY ACCESS OBJECT)
this.runtime = DefaultRuntime.newInstance(this);

// create API accessible registry instance (READ-ONLY ACCESS OBJECT)
this.registry = DefaultRegistry.newInstance(this.runtime.registry());
this.runtime = Runtime.newInstance(this);

// create API accessible providers instance (READ-ONLY ACCESS OBJECT)
this.providers = DefaultProviders.newInstance(this.runtime.providers());
Expand All @@ -117,7 +111,7 @@ protected DefaultContext(ContextConfig config) {

/** {@inheritDoc} */
@Override
public Registry registry() { return this.registry; }
public Registry registry() { return this.runtime.registry(); }

/** {@inheritDoc} */
@Override
Expand All @@ -139,11 +133,11 @@ public Context shutdown() throws ShutdownException {

@Override
public <T extends IO> void shutdown(T instance) {
runtime.registry().remove(instance);
runtime.shutdown(instance);
}
@Override
public <T extends IO> T shutdown(String id) {
return runtime.registry().remove(id);
return runtime.shutdown(runtime.registry().get(id));
}

@Override
Expand Down Expand Up @@ -191,4 +185,9 @@ public Context removeListener(InitializedListener... listener) {
this.runtime.removeListener(listener);
return this;
}

@Override
public void register(IO instance) {
runtime.register(instance);
}
}
5 changes: 4 additions & 1 deletion pi4j-core/src/main/java/com/pi4j/io/i2c/I2CBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public boolean isOpen() {
*/
@Override
public void close() {
this.isOpen = false;
if (isOpen) {
this.isOpen = false;
context().shutdown(this);
}
}

/**
Expand Down
26 changes: 1 addition & 25 deletions pi4j-core/src/main/java/com/pi4j/registry/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
import com.pi4j.common.Descriptor;
import com.pi4j.io.IO;
import com.pi4j.io.IOType;
import com.pi4j.io.exception.IOAlreadyExistsException;
import com.pi4j.io.exception.IOInvalidIDException;
import com.pi4j.io.exception.IONotFoundException;
import com.pi4j.io.exception.IOShutdownException;
import com.pi4j.provider.Provider;

import java.util.Collections;
Expand All @@ -41,7 +39,7 @@
import java.util.stream.Collectors;

/**
* <p>Registry interface.</p>
* An immutable view of the registry that holds all registered I/O instances.
*
* @author Robert Savage (<a href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
* @version $Id: $Id
Expand Down Expand Up @@ -169,28 +167,6 @@ default <P extends Provider, T extends IO> Map<String, T> allByProvider(String p
return Collections.unmodifiableMap(result);
}

/**
* <p>add.</p>
*
* @param instance a {@link com.pi4j.io.IO} object.
* @return this
* @throws com.pi4j.io.exception.IOAlreadyExistsException if any.
* @throws com.pi4j.io.exception.IOInvalidIDException if any.
*/
Registry add(IO instance) throws IOAlreadyExistsException, IOInvalidIDException;

/**
* <p>remove.</p>
*
* @param id a {@link java.lang.String} object.
* @param <T> a T object.
* @return a T object.
* @throws com.pi4j.io.exception.IONotFoundException if any.
* @throws com.pi4j.io.exception.IOInvalidIDException if any.
* @throws com.pi4j.io.exception.IOShutdownException if any.
*/
<T extends IO> T remove(String id) throws IONotFoundException, IOInvalidIDException, IOShutdownException;

/**
* <p>describe.</p>
*
Expand Down
110 changes: 0 additions & 110 deletions pi4j-core/src/main/java/com/pi4j/registry/impl/DefaultRegistry.java

This file was deleted.

This file was deleted.

Loading
Loading