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.
+ * 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;
-
- }
-
- static {
- try {
- System.loadLibrary("ResContainerLib");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * 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){
- unregisterResource(bundleResource);
- }
- }
-
- /**
- * 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.getURI(), resource.getResourceType(),
- 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);
-
- Vector<ResourceConfig> configs = new Vector<ResourceConfig>();
-
- for (int i = 0; i < configuredResources; i++) {
- String[] resourceParams = getConfiguredResourceParams(bundleId, i);
- ResourceConfig config = new ResourceConfig(resourceParams);
- configs.add(config);
-
- }
- return configs;
- }
-
- /**
- * Unregisters a resource from the resource container.
- */
- public void unregisterResource(BundleResource resource) {
- bundleResources.remove(resource);
- unregisterJavaResource(resource, resource.getURI());
- }
-
- /**
- * 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);
-
- /**
- * 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);
+ 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;
+ }
+
+ static {
+ try {
+ System.loadLibrary("rcs_container");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 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) {
+ unregisterResource(bundleResource);
+ }
+ }
+
+ /**
+ * 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.getURI(), resource.getResourceType(),
+ 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);
+
+ Vector<ResourceConfig> configs = new Vector<ResourceConfig>();
+
+ for (int i = 0; i < configuredResources; i++) {
+ String[] resourceParams = getConfiguredResourceParams(bundleId, i);
+ ResourceConfig config = new ResourceConfig(resourceParams);
+ configs.add(config);
+
+ }
+ return configs;
+ }
+
+ /**
+ * Unregisters a resource from the resource container.
+ */
+ public void unregisterResource(BundleResource resource) {
+ bundleResources.remove(resource);
+ unregisterJavaResource(resource, resource.getURI());
+ }
+
+ /**
+ * 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);
+
+ /**
+ * 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);
}
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.
+ * 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 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 Resource URI
- */
- 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 Resource address
- */
- public void setAddress(String address) {
- this.m_address = address;
- }
-
- /**
- * Returns the technology specific address information
- * @return Resource address
- */
- public String getAddress() {
- return m_address;
- }
-
- /**
- * Sets the name property of the resource
- * @param name Resource name
- */
- public void setName(String name) {
- this.m_name = name;
- }
-
- /**
- * Returns the name property of the resource
- * @return Resource name
- */
- public String getName() {
- return m_name;
- }
+ protected String m_name, m_uri, m_resourceType, m_address;
+
+ protected HashMap<String, String> m_attributes = new HashMap<String, String>();
+
+ /**
+ * 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
+ */
+ protected final void setAttribute(String key, String value) {
+ m_attributes.put(key, value);
+ }
+
+ /**
+ * 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 handleSetAttributeRequest(String key, String value);
+
+ /**
+ * Retrieve the attribute (only data)
+ *
+ * @param key
+ * name of the attribute to be read
+ * @return Value of the attribute
+ */
+ protected final String getAttribute(String key) {
+ return m_attributes.get(key);
+ }
+
+ /**
+ * Retrieve the attribute (map to read command)
+ *
+ * @param key
+ * name of the attribute to be set
+ * @param value
+ * new value of the attribute
+ */
+ public abstract String handleGetAttributeRequest(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 Resource URI
+ */
+ 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
+ * Resource address
+ */
+ public void setAddress(String address) {
+ this.m_address = address;
+ }
+
+ /**
+ * Returns the technology specific address information
+ *
+ * @return Resource address
+ */
+ public String getAddress() {
+ return m_address;
+ }
+
+ /**
+ * Sets the name property of the resource
+ *
+ * @param name
+ * Resource name
+ */
+ public void setName(String name) {
+ this.m_name = name;
+ }
+
+ /**
+ * Returns the name property of the resource
+ *
+ * @return Resource name
+ */
+ public String getName() {
+ return m_name;
+ }
}
getchar();
bundleParams["libraryPath"] = ".";
std::string activator = "org.iotivity.bundle.hue.HueBundleActivator";
- container->addBundle("oic.bundle.hueJavaSample", "/hueJava",
- "../../../../../../../../service/resource-encapsulation/src/resourceContainer/" \
- "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
- activator,
- bundleParams);
+ container->addBundle("oic.bundle.hueJavaSample2", "/hueJava",
+ "../../../../../../../../service/resource-encapsulation/src/resourceContainer/" \
+ "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
+ activator,
+ bundleParams);
bundles = container->listBundles();
cout << "\t>>> bundle list size : " << bundles.size() << endl;
cout << "\nPress enter to start java bundle " << endl;
getchar();
- container->startBundle("oic.bundle.hueJavaSample");
+ container->startBundle("oic.bundle.hueJavaSample2");
cout << "Press enter to stop java Bundle " << endl;
getchar();
- container->stopBundle("oic.bundle.hueJavaSample");
+ container->stopBundle("oic.bundle.hueJavaSample2");
cout << "Press enter to test remove java Bundle " << endl;
getchar();
- container->removeBundle("oic.bundle.hueJavaSample");
+ container->removeBundle("oic.bundle.hueJavaSample2");
bundles = container->listBundles();
cout << "\t>>> bundle list size : " << bundles.size() << endl;
import org.iotivity.resourcecontainer.bundle.api.ResourceConfig;
public class HueBundleActivator extends BaseActivator {
- private HueConnector connector;
-
- public HueBundleActivator(String bundleId) {
- super(bundleId);
- }
-
- public void activateBundle() {
- super.activateBundle();
- connector = new HueConnector();
- List<ResourceConfig> resourceConfig = getConfiguredBundleResources();
-
- for (ResourceConfig config : resourceConfig) {
-
- HueLightResource hueLightResource = new HueLightResource(connector,
- config.getName(), config.getURI(),
- config.getResourceType(), config.getAddress());
-
- System.out.println("Registration of HueLightresource");
- registerResource(hueLightResource);
- }
- }
-
- public void deactivateBundle() {
- System.out.println("Deactivate bundle called.");
- super.deactivateBundle();
- }
-
- // test call
- public static void main(String[] args) {
- HueBundleActivator activator = new HueBundleActivator("oic.hue.bundle");
- }
+ private HueConnector connector;
+
+ public HueBundleActivator(String bundleId) {
+ super(bundleId);
+ }
+
+ public void activateBundle() {
+ super.activateBundle();
+ connector = new HueConnector();
+ List<ResourceConfig> resourceConfig = getConfiguredBundleResources();
+
+ for (ResourceConfig config : resourceConfig) {
+
+ HueLightResource hueLightResource = new HueLightResource(connector,
+ config.getName(), config.getURI(),
+ config.getResourceType(), config.getAddress());
+
+ System.out.println("Registration of Hue light resource " + config);
+ registerResource(hueLightResource);
+ }
+ }
+
+ public void deactivateBundle() {
+ System.out.println("Deactivate bundle called.");
+ super.deactivateBundle();
+ }
+
+ // test call
+ public static void main(String[] args) {
+ HueBundleActivator activator = new HueBundleActivator("oic.hue.bundle");
+ }
}
* @author iotivity
*/
public class HueLightResource extends BundleResource {
- private HueConnector m_hueConnector;
+ private HueConnector m_hueConnector;
- public HueLightResource() {
- initAttributes();
- m_resourceType = "oic.light.control";
-
- }
+ public HueLightResource() {
+ initAttributes();
+ m_resourceType = "oic.r.light.control";
- public HueLightResource(HueConnector hueConnector, String name, String uri,
- String resourceType, String address) {
- this();
- this.m_hueConnector = hueConnector;
- m_name = name;
- m_uri = uri;
- m_resourceType = resourceType;
- m_address = address;
- }
+ }
- protected void initAttributes() {
- m_attributes = new HashMap<String, String>();
- m_attributes.put("on-off", "true");
- m_attributes.put("color", "0");
- m_attributes.put("dim", "0");
- }
+ public HueLightResource(HueConnector hueConnector, String name, String uri,
+ String resourceType, String address) {
+ this();
+ this.m_hueConnector = hueConnector;
+ m_name = name;
+ m_uri = uri;
+ m_resourceType = resourceType;
+ m_address = address;
+ }
- public void setAttribute(String key, String value) {
- System.out.println("Set attribute called - key: " + key + ", value: "
- + value + " transmitting now.");
+ protected void initAttributes() {
+ m_attributes.put("on-off", "true");
+ m_attributes.put("color", "0");
+ m_attributes.put("dim", "0");
+ }
- if ("on-off".equals(value)) {
- m_hueConnector.transmit(m_address + "/state", "{\"on\":" + value
- + "}");
- }
+ public void handleSetAttributeRequest(String key, String value) {
+ System.out.println("Set attribute called - key: " + key + ", value: "
+ + value + " transmitting now.");
- if ("dim".equals(value)) {
- m_hueConnector.transmit(m_address + "/state", "{\"bri\":" + value
- + "}");
- }
+ if ("on-off".equals(value)) {
+ m_hueConnector.transmit(m_address + "/state", "{\"on\":" + value
+ + "}");
+ }
- if ("color".equals(value)) {
- m_hueConnector.transmit(m_address + "/state", "{\"hue\":" + value
- + "}");
- }
- m_attributes.put(key, value);
- }
+ if ("dim".equals(value)) {
+ m_hueConnector.transmit(m_address + "/state", "{\"bri\":" + value
+ + "}");
+ }
- public String getAttribute(String key) {
-
- // map key to hue address
- // read from Hue gateway, parse resource representation and return
- // attribute
- //m_hueConnector.read(m_address);
- return m_attributes.get(key);
- }
+ if ("color".equals(value)) {
+ m_hueConnector.transmit(m_address + "/state", "{\"hue\":" + value
+ + "}");
+ }
+ this.setAttribute(key, value);
+ }
- @Override
- public String toString() {
- return "HueLightResource [m_hueConnector=" + m_hueConnector
- + ", m_name=" + m_name + ", m_uri=" + m_uri
- + ", m_resourceType=" + m_resourceType + ", m_address="
- + m_address + ", m_attributes=" + m_attributes + "]";
- }
+ public String handleGetAttributeRequest(String key) {
+ // map key to hue address
+ // read from Hue gateway, parse resource representation and return
+ // attribute
+ // m_hueConnector.read(m_address);
+ return this.getAttribute(key);
+ }
+
+ @Override
+ public String toString() {
+ return "HueLightResource [m_hueConnector=" + m_hueConnector
+ + ", m_name=" + m_name + ", m_uri=" + m_uri
+ + ", m_resourceType=" + m_resourceType + ", m_address="
+ + m_address + ", m_attributes=" + m_attributes + "]";
+ }
}
static int lightCount = 1;
BundleResource::Ptr hueLight = std::make_shared< HueLight >(m_connector, resourceInfo.address);
resourceInfo.uri = "/hue/light/" + std::to_string(lightCount++);
- std::cout << "Registering resource " << resourceInfo.uri << std::endl;
hueLight->m_bundleId = m_bundleId;
hueLight->m_uri = resourceInfo.uri;
hueLight->m_resourceType = resourceInfo.resourceType;
</resourceInfo>
</resources>
</bundle>
- <!--
+
<bundle>
<id>oic.bundle.hueJavaSample</id>
<path>../../../../../../../../service/resource-encapsulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar</path>
<resources>
<resourceInfo>
<name>light</name>
- <uri>light/1</uri>
+ <resourceUri>/hueJava/light/1</resourceUri>
<resourceType>oic.r.light</resourceType>
<address>http://192.168.0.2/api/newdeveloper/lights/1</address>
</resourceInfo>
</resources>
</bundle>
- -->
+
</container>
\ No newline at end of file
jobjectArray attributes);
virtual ~JavaBundleResource();
- virtual RCSResourceAttributes& getAttributes();
+ void handleSetAttributeRequest(const std::string& key,
+ RCSResourceAttributes::Value&&);
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value&&);
+ RCSResourceAttributes::Value handleGetAttributeRequest(const std::string& key);
+
+ virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
+
+ virtual RCSResourceAttributes& handleGetAttributesRequest();
- virtual RCSResourceAttributes::Value getAttribute(const std::string& key);
virtual void initAttributes();
private:
// needs to be a GlobalRef
- jobject bundleResource;
- jobjectArray attributes;
- jclass bundleResourceClass;
- jmethodID attributeSetter;
- jmethodID attributeGetter;
+ jobject m_bundleResource;
+ jobjectArray m_attributes;
+ jclass m_bundleResourceClass;
+ jmethodID m_attributeSetRequestHandler;
+ jmethodID m_attributeGetRequestHandler;
string m_bundleId;
};
}
#include <jni.h>
#include "org_iotivity_resourcecontainer_bundle_api_BaseActivator.h"
#include "JavaBundleResource.h"
-#include "ResourceContainerImpl.h"
using namespace OIC::Service;
-std::map< string, JavaBundleResource * > java_resources;
+std::map< string, BundleResource::Ptr > java_resources;
/*
* Class: org_iotivity_resourcecontainer_bundle_api_BaseActivator
const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
const char *str_res_name = env->GetStringUTFChars(res_name, 0);
- JavaBundleResource *javaBundleResource = new JavaBundleResource(env, obj, bundleResource,
- str_bundleId, attributes);
+ BundleResource::Ptr javaBundleResource = std::make_shared< JavaBundleResource >
+ (env, obj, bundleResource, str_bundleId, attributes);
ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
container->registerResource(javaBundleResource);
java_resources[str_uri] = javaBundleResource;
-
}
/*
m_bundleId = bundleId;
- this->bundleResource = env->NewGlobalRef(bundleResource);
+ this->m_bundleResource = env->NewGlobalRef(bundleResource);
- bundleResourceClass = env->GetObjectClass(bundleResource);
+ m_bundleResourceClass = env->GetObjectClass(bundleResource);
- attributeSetter = env->GetMethodID(bundleResourceClass, "setAttribute",
- "(Ljava/lang/String;Ljava/lang/String;)V");
+ m_attributeSetRequestHandler = env->GetMethodID(m_bundleResourceClass,
+ "handleSetAttributeRequest", "(Ljava/lang/String;Ljava/lang/String;)V");
- attributeGetter = env->GetMethodID(bundleResourceClass, "getAttribute",
- "(Ljava/lang/String;)Ljava/lang/String;");
+ m_attributeGetRequestHandler = env->GetMethodID(m_bundleResourceClass,
+ "handleGetAttributeRequest", "(Ljava/lang/String;)Ljava/lang/String;");
}
}
-RCSResourceAttributes &JavaBundleResource::getAttributes()
-{
- return BundleResource::getAttributes();
-}
-
-RCSResourceAttributes::Value JavaBundleResource::getAttribute(const std::string &attributeName)
+RCSResourceAttributes::Value JavaBundleResource::handleGetAttributeRequest(
+ const std::string &attributeName)
{
JavaVM *vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
{
if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::getAttribute] Failed to attach ");
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ "[JavaBundleResource::handleGetAttributeRequest] Failed to attach ");
}
}
else if (envStat == JNI_EVERSION)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::getAttribute] Env: version not supported");
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ "[JavaBundleResource::handleGetAttributeRequest] Env: version not supported");
}
jstring attrName = env->NewStringUTF(attributeName.c_str());
- jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
- attrName);
+ jstring returnString = (jstring) env->CallObjectMethod(m_bundleResource,
+ m_attributeGetRequestHandler, attrName);
const char *js = env->GetStringUTFChars(returnString, NULL);
std::string val(js);
return BundleResource::getAttribute(attributeName);
}
-void JavaBundleResource::setAttribute(std::string attributeName,
+void JavaBundleResource::handleSetAttributeRequest(const std::string &attributeName,
RCSResourceAttributes::Value &&value)
{
JavaVM *vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
{
if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::setAttribute] Failed to attach ");
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ "[JavaBundleResource::handleSetAttributeRequest] Failed to attach ");
}
}
else if (envStat == JNI_EVERSION)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::setAttribute] Env: version not supported ");
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ "[JavaBundleResource::handleSetAttributeRequest] Env: version not supported ");
}
jstring attrName = env->NewStringUTF(attributeName.c_str());
jstring val = env->NewStringUTF(value.toString().c_str());
- env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
+ env->CallObjectMethod(m_bundleResource, m_attributeSetRequestHandler, attrName, val);
BundleResource::setAttribute(attributeName, std::move(value));
}
+
+
+void JavaBundleResource::handleSetAttributesRequest(RCSResourceAttributes &attrs){
+ for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
+ {
+ handleSetAttributeRequest(it->key(),std::move(it->value()));
+ }
+}
+
+RCSResourceAttributes & JavaBundleResource::handleGetAttributesRequest(){
+ RCSResourceAttributes ret;
+ std::list<string> attrsNames = getAttributeNames();
+ for(std::list<string>::iterator iterator = attrsNames.begin();
+ iterator != attrsNames.end(); ++iterator ){
+ ret[*iterator] = handleGetAttributeRequest(*iterator);
+ }
+ return ret;
+}
#endif
bundles[i][BUNDLE_LIBRARY_PATH]);
}
- OC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)", std::string(bundles[i][BUNDLE_ID] + ";" +
- bundles[i][BUNDLE_PATH]).c_str());
+ OC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)",
+ std::string(bundles[i][BUNDLE_ID] + ";" +
+ bundles[i][BUNDLE_PATH]).c_str());
+
registerBundle(bundleInfo);
activateBundle(bundleInfo);
}
std::bind(&ResourceContainerImpl::setRequestHandler, this,
std::placeholders::_1, std::placeholders::_2));
- OC_LOG_V(INFO, CONTAINER_TAG, "Registration finished (%s)", std::string(strUri + ", " +
- strResourceType).c_str());
+ OC_LOG_V(INFO, CONTAINER_TAG, "Registration finished (%s)",
+ std::string(strUri + ", " +
+ strResourceType).c_str());
if (m_config->isHasInput(resource->m_bundleId))
{
void ResourceContainerImpl::onNotificationReceived(const std::string &strResourceUri)
{
- OC_LOG_V(INFO, CONTAINER_TAG, "notification from (%s)", std::string(strResourceUri + ".").c_str());
+ OC_LOG_V(INFO, CONTAINER_TAG,
+ "notification from (%s)", std::string(strResourceUri + ".").c_str());
if (m_mapServers.find(strResourceUri) != m_mapServers.end())
{
RCSResourceObject::Ptr ResourceContainerImpl::buildResourceObject(const std::string &strUri,
const std::string &strResourceType)
{
- return RCSResourceObject::Builder(strUri, strResourceType, "oic.if.baseline").setObservable(
+ return RCSResourceObject::Builder(strUri, strResourceType,
+ "oic.if.baseline").setObservable(
true).setDiscoverable(true).build();
}
((BundleInfoInternal *)bundleInfo)->setLibraryPath(params[BUNDLE_LIBRARY_PATH]);
}
- OC_LOG_V(INFO, CONTAINER_TAG, "Add Bundle: (%s)", std::string(bundleInfo->getID() + "; " +
- bundleInfo->getPath()).c_str());
+ OC_LOG_V(INFO, CONTAINER_TAG, "Add Bundle: (%s)",
+ std::string(bundleInfo->getID() + "; " +
+ bundleInfo->getPath()).c_str());
registerBundle(bundleInfo);
}
{
OC_LOG_V(INFO, CONTAINER_TAG, "Registering Java bundle (%s)",
std::string(bundleInfo->getID()).c_str());
-
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
{
fclose(file);
- OC_LOG_V(INFO, CONTAINER_TAG, "Resource bundle (%s)", std::string(bundleInfo->getPath() +
- " available.").c_str());
+ OC_LOG_V(INFO, CONTAINER_TAG, "Resource bundle (%s)",
+ std::string(bundleInfo->getPath() +
+ " available.").c_str());
}
else
{
strcpy(classpath, "-Djava.class.path=");
strcat(classpath, bundleInfo->getPath().c_str());
- OC_LOG(INFO, CONTAINER_TAG, std::string("Configured classpath: ").append(classpath).c_str());
+ OC_LOG(INFO, CONTAINER_TAG,
+ std::string("Configured classpath: ").append(classpath).c_str());
options[1].optionString = classpath;
strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
options[2].optionString = libraryPath;
- OC_LOG(INFO, CONTAINER_TAG, std::string("Configured library path: ").append(libraryPath).c_str());
+ OC_LOG(INFO, CONTAINER_TAG,
+ std::string("Configured library path: ").append(libraryPath).c_str());
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
OC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
std::string( bundleInfoInternal->getID()
+ " activate bundle method not found ").c_str());
-
return;
}
bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
OC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
std::string( bundleInfoInternal->getID()
+ " deactivate bundle method not found ").c_str());
-
return;
}
m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
+
OC_LOG(INFO, CONTAINER_TAG, "Bundle registered");
}