+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
package org.iotivity.resourcecontainer.bundle.api;
import java.util.List;
import java.util.Vector;
+/**
+ * The BaseActivator implements the native interface to the resource container.
+ * It loads the resource container library and provies native methods
+ * that can be used to register and unregister resources.
+ */
public class BaseActivator implements BundleActivator {
private String bundleId;
private Vector<BundleResource> bundleResources = new Vector<BundleResource>();
+ /**
+ * Creates an instance of the BaseActivator
+ * @param bundleId unique bundle identifier (e.g., oic.bundle.hue)
+ */
public BaseActivator(String bundleId) {
this.bundleId = bundleId;
}
}
+ /**
+ * Bundle activation needs to be provided by the subclass.
+ */
public void activateBundle() {
}
+ /**
+ * Deactivates the bundle and unregisters its resources.
+ */
public void deactivateBundle() {
System.out.println("Deactivating bundle (Base Activator).");
for(BundleResource bundleResource : bundleResources){
}
}
+ /**
+ * Registers a bundle resource at the resource container.
+ * @param resource bundle resource instance that should be made available as OIC resource
+ */
public void registerResource(BundleResource resource) {
bundleResources.add(resource);
registerJavaResource(resource, resource.getAttributeKeys(), bundleId,
resource.getName());
}
+ /**
+ * Wrapper to retrieve the resource configuration of the bundle resources.
+ * @return List of resource configurations.
+ */
public List<ResourceConfig> getConfiguredBundleResources() {
int configuredResources = getNumberOfConfiguredResources(bundleId);
return configs;
}
+ /**
+ * Unregisters a resource from the resource container.
+ */
public void unregisterResource(BundleResource resource) {
- System.out.println("Making native call.");
unregisterJavaResource(resource, resource.getURI());
}
- public native void registerJavaResource(BundleResource resource,
+ /**
+ * Native method that calls to the resource container.
+ * @param attributes String array of attribute names
+ * @param bundleId unique bundle identifier
+ * @param uri Uri that should be used to register the resource
+ */
+ private native void registerJavaResource(BundleResource resource,
String[] attributes, String bundleId, String uri,
String resourceType, String name);
- public native void unregisterJavaResource(BundleResource resource, String uri);
-
- public native int getNumberOfConfiguredResources(String bundleId);
-
- public native String[] getConfiguredResourceParams(String bundleId,
+ /**
+ * Native method that calls to the resource container.
+ * @param resource
+ * @param uri
+ */
+ private native void unregisterJavaResource(BundleResource resource, String uri);
+
+ /**
+ * Native method to retrieve the number of configured resources.
+ * @param bundleId unique bundle identifier
+ */
+ private native int getNumberOfConfiguredResources(String bundleId);
+
+ /**
+ * Native method to retrieve the configured resource parameters.
+ * @param bundleId unique bundle identifier
+ * @param resId get the resource params for a certain resource
+ */
+ private native String[] getConfiguredResourceParams(String bundleId,
int resId);
}
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
package org.iotivity.resourcecontainer.bundle.api;
import java.util.List;
+/**
+ * The BundleActivator interface needs to be implemented. A bundle provider
+ * can directly extend fromt the BaseActivator.
+ */
public interface BundleActivator {
+ /**
+ * Activates the bundle and creates all resources.
+ */
public void activateBundle();
+ /**
+ * Deactivates the bundle and destroys all resources.
+ */
public void deactivateBundle();
+ /**
+ * Registers a single resource instance at the resource container
+ * @param resource Instance of a BundleResource
+ */
public void registerResource(BundleResource resource);
+ /**
+ * Unregisters a single resource instance at the resource container
+ * @param resource Instance of a BundleResource
+ */
public void unregisterResource(BundleResource resource);
+ /**
+ * List the configuration of the bundle resources.
+ * @return List of configuration for each resource
+ */
public List<ResourceConfig> getConfiguredBundleResources();
}
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
package org.iotivity.resourcecontainer.bundle.api;
import java.util.HashMap;
import java.util.Set;
+/**
+ * Basic BundleResource that should be used as a base class
+ * by a bundle resources. A concrete technology has
+ * to override the setAttribute and getAttribute method
+ * and map the according reads and writes to the technology specific
+ * messages.
+ */
public abstract class BundleResource {
- protected String m_name, m_uri, m_resourceType, m_address;
+ protected String m_name, m_uri, m_resourceType, m_address;
protected HashMap<String, String> m_attributes;
+ /**
+ * Initialize the internal attribute structure.
+ */
protected abstract void initAttributes();
+ /**
+ * Set the attribute (map to a send command for the according protocol)
+ * @param key name of the attribute to be set
+ * @param value new value of the attribute
+ */
public abstract void setAttribute(String key, String value);
+ /**
+ * Retrieve the attribute (map to read command for the according protocol)
+ * @param key name of the attribute to be read
+ * @return Value of the attribute
+ */
public abstract String getAttribute(String key);
+ /**
+ * Attribute keys provided through by the bundle resource.
+ * @return Name of attribute keys as string array
+ */
public String[] getAttributeKeys() {
Set<String> keys = m_attributes.keySet();
return keys.toArray(new String[keys.size()]);
}
+ /**
+ * Setter for the uri property
+ * @param uri URI of the resource
+ */
public void setURI(String uri) {
this.m_uri = uri;
}
+ /**
+ * Returns the URI of the resource
+ * @return
+ */
public String getURI() {
return m_uri;
}
+ /**
+ * Sets the resource type property
+ * @param resourceType OIC resource type
+ */
public void setResourceType(String resourceType) {
this.m_resourceType = resourceType;
}
+ /**
+ * Getter for the resource type
+ * @return OIC resource type
+ */
public String getResourceType() {
return m_resourceType;
}
+ /**
+ * Sets the technology specific address information (e.g., ZigBee short or long identifier)
+ * @param address
+ */
public void setAddress(String address) {
this.m_address = address;
}
+ /**
+ * Returns the technology specific address information
+ * @return
+ */
public String getAddress() {
return m_address;
}
+ /**
+ * Sets the name property of the resource
+ * @param name
+ */
public void setName(String name) {
this.m_name = name;
}
+ /**
+ * Returns the name property of the resource
+ * @return
+ */
public String getName() {
return m_name;
}
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
package org.iotivity.resourcecontainer.bundle.api;
+/**
+ * The ProtocolBridgeConnector interface should be implemented
+ * by a bundle provider and it should be called
+ * at bundle activation and deactivation.
+ */
public interface ProtocolBridgeConnector {
+ /**
+ * Connects to a specific protocol (e.g, establishes a communication session)
+ */
public void connect();
+ /**
+ * Disconnects from a specific protocol
+ */
public void disconnect();
}
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
package org.iotivity.resourcecontainer.bundle.api;
+/**
+ * This class holds the configuration parameters for a single resource instance provided
+ * by the resource bundle.
+ */
public class ResourceConfig {
private String m_name, m_uri, m_resourceType, m_address;
+ /**
+ * Empty constructor for resoure config.
+ */
public ResourceConfig() {
}
+ /**
+ * Creates a new resource config instance.
+ * @param params Resource parameters as array. 1. Name, 2. URI, 3. Resource Type, 4. Address
+ */
public ResourceConfig(String[] params) {
m_name = params[0];
m_uri = params[1];
m_address = params[3];
}
- public String getM_name() {
+ /**
+ * Returns the configured name
+ * @return name property
+ */
+ public String getName() {
return m_name;
}
- public void setM_name(String m_name) {
+ /**
+ * Sets the name
+ * @param m_name
+ */
+ public void setName(String m_name) {
this.m_name = m_name;
}
- public String getM_uri() {
+ /**
+ * Returns the configured URI
+ * @return Configured URI
+ */
+ public String getURI() {
return m_uri;
}
- public void setM_uri(String m_uri) {
+ /**
+ * Sets the configured URI
+ * @param m_uri Configuration URI
+ */
+ public void setURI(String m_uri) {
this.m_uri = m_uri;
}
- public String getM_resourceType() {
+ /**
+ * Returns the configured resource type
+ * @param m_uri configured resource type
+ */
+ public String getResourceType() {
return m_resourceType;
}
- public void setM_resourceType(String m_resourceType) {
+ /**
+ * Sets the configured resource type
+ * @param m_resourceType updates the configured resource type
+ */
+ public void setResourceType(String m_resourceType) {
this.m_resourceType = m_resourceType;
}
- public String getM_address() {
+ /**
+ * Returns the configured address
+ * @return Configured address
+ */
+ public String getAddress() {
return m_address;
}
- public void setM_address(String m_address) {
+ /**
+ * Sets the configured address
+ * @param m_address Configured address
+ */
+ public void setAddress(String m_address) {
this.m_address = m_address;
}