You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2014/07/26 18:26:10 UTC
svn commit: r1613670 - in /celix/trunk/remote_services:
discovery_configured/ discovery_configured/private/include/
discovery_configured/private/src/ endpoint_listener/public/include/
remote_service_admin/private/src/ remote_service_admin/public/includ...
Author: abroekhuis
Date: Sat Jul 26 16:26:09 2014
New Revision: 1613670
URL: http://svn.apache.org/r1613670
Log:
CELIX-130: Implemented endpoint descriptor reader/writer
Added:
celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h
- copied, changed from r1613541, celix/trunk/remote_services/utils/public/include/remote_constants.h
celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_writer.h
- copied, changed from r1613541, celix/trunk/remote_services/utils/public/include/remote_constants.h
celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_reader.c
celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_writer.c
celix/trunk/remote_services/remote_service_admin/private/src/endpoint_description.c
celix/trunk/remote_services/remote_service_admin/public/include/endpoint_description.h
- copied, changed from r1613541, celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h
Removed:
celix/trunk/remote_services/discovery_configured/private/src/endpoint_description_reader.c
Modified:
celix/trunk/remote_services/discovery_configured/CMakeLists.txt
celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h
celix/trunk/remote_services/topology_manager/private/include/topology_manager.h
celix/trunk/remote_services/utils/public/include/remote_constants.h
Modified: celix/trunk/remote_services/discovery_configured/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/CMakeLists.txt?rev=1613670&r1=1613669&r2=1613670&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery_configured/CMakeLists.txt (original)
+++ celix/trunk/remote_services/discovery_configured/CMakeLists.txt Sat Jul 26 16:26:09 2014
@@ -45,7 +45,16 @@ install_bundle(discovery_configured)
target_link_libraries(discovery_configured celix_framework ${CURL_LIBRARIES} ${APRUTIL_LIBRARY})
-add_executable(descparser private/src/endpoint_description_reader.c)
+add_executable(descparser
+ private/src/endpoint_descriptor_reader.c
+ ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
-target_link_libraries(descparser ${LIBXML2_LIBRARIES} celix_utils)
+target_link_libraries(descparser ${LIBXML2_LIBRARIES} celix_framework celix_utils)
+
+
+add_executable(descwriter
+ private/src/endpoint_descriptor_writer.c
+ ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
+
+target_link_libraries(descwriter ${LIBXML2_LIBRARIES} celix_framework celix_utils)
Copied: celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h (from r1613541, celix/trunk/remote_services/utils/public/include/remote_constants.h)
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h?p2=celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h&p1=celix/trunk/remote_services/utils/public/include/remote_constants.h&r1=1613541&r2=1613670&rev=1613670&view=diff
==============================================================================
--- celix/trunk/remote_services/utils/public/include/remote_constants.h (original)
+++ celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h Sat Jul 26 16:26:09 2014
@@ -17,20 +17,23 @@
*under the License.
*/
/*
- * remote_constants.h
+ * endpoint_descriptor_reader.h
*
- * \date Sep 30, 2011
- * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \date 26 Jul 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
-#ifndef REMOTE_CONSTANTS_H_
-#define REMOTE_CONSTANTS_H_
+#ifndef ENDPOINT_DESCRIPTOR_READER_H_
+#define ENDPOINT_DESCRIPTOR_READER_H_
-static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
-static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
-static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
+#include "celix_errno.h"
+#include "array_list.h"
-static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
+typedef struct endpoint_descriptor_reader *endpoint_descriptor_reader_pt;
-#endif /* REMOTE_CONSTANTS_H_ */
+celix_status_t endpointDescriptorReader_create(endpoint_descriptor_reader_pt *reader);
+celix_status_t endpointDescriptorReader_parseDocument(endpoint_descriptor_reader_pt reader, char *document, array_list_pt *endpoints);
+
+
+#endif /* ENDPOINT_DESCRIPTOR_READER_H_ */
Copied: celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_writer.h (from r1613541, celix/trunk/remote_services/utils/public/include/remote_constants.h)
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_writer.h?p2=celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_writer.h&p1=celix/trunk/remote_services/utils/public/include/remote_constants.h&r1=1613541&r2=1613670&rev=1613670&view=diff
==============================================================================
--- celix/trunk/remote_services/utils/public/include/remote_constants.h (original)
+++ celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_writer.h Sat Jul 26 16:26:09 2014
@@ -17,20 +17,23 @@
*under the License.
*/
/*
- * remote_constants.h
+ * endpoint_descriptor_writer.h
*
- * \date Sep 30, 2011
- * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \date 26 Jul 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
-#ifndef REMOTE_CONSTANTS_H_
-#define REMOTE_CONSTANTS_H_
+#ifndef ENDPOINT_DESCRIPTOR_WRITER_H_
+#define ENDPOINT_DESCRIPTOR_WRITER_H_
-static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
-static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
-static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
+#include "celix_errno.h"
+#include "array_list.h"
-static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
+typedef struct endpoint_descriptor_writer *endpoint_descriptor_writer_pt;
-#endif /* REMOTE_CONSTANTS_H_ */
+celix_status_t endpointDescriptorWriter_create(endpoint_descriptor_writer_pt *writer);
+celix_status_t endpointDescriptorWriter_destroy(endpoint_descriptor_writer_pt writer);
+celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document);
+
+#endif /* ENDPOINT_DESCRIPTOR_WRITER_H_ */
Added: celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_reader.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_reader.c?rev=1613670&view=auto
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_reader.c (added)
+++ celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_reader.c Sat Jul 26 16:26:09 2014
@@ -0,0 +1,350 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you 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.
+ */
+/*
+ * endpoint_description_reader.c
+ *
+ * \date 24 Jul 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdbool.h>
+#include <libxml/xmlreader.h>
+#include <string.h>
+
+#include "endpoint_description.h"
+#include "endpoint_descriptor_reader.h"
+#include "properties.h"
+#include "utils.h"
+
+struct endpoint_descriptor_reader {
+ xmlTextReaderPtr reader;
+};
+
+typedef enum {
+ VALUE_TYPE_STRING,
+ VALUE_TYPE_LONG,
+ VALUE_TYPE_DOUBLE,
+ VALUE_TYPE_FLOAT,
+ VALUE_TYPE_INTEGER,
+ VALUE_TYPE_BYTE,
+ VALUE_TYPE_CHAR,
+ VALUE_TYPE_BOOLEAN,
+ VALUE_TYPE_SHORT,
+} valueType;
+
+
+static valueType getValueType(char *name);
+
+celix_status_t endpointDescriptorReader_create(endpoint_descriptor_reader_pt *reader) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *reader = malloc(sizeof(**reader));
+ if (!reader) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*reader)->reader = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t endpointDescriptorReader_destroy(endpoint_descriptor_reader_pt reader) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ free(reader);
+
+ return status;
+}
+
+celix_status_t endpointDescriptorReader_parseDocument(endpoint_descriptor_reader_pt reader, char *document, array_list_pt *endpoints) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ reader->reader = xmlReaderForMemory(document, strlen(document), NULL, "UTF-8", 0);
+ if (reader == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ bool inProperty = false;
+ bool inXml = false;
+ bool inArray = false;
+ bool inList = false;
+ bool inSet = false;
+ bool inValue = false;
+
+ const xmlChar *propertyName = NULL;
+ const xmlChar *propertyType = NULL;
+ const xmlChar *propertyValue = NULL;
+ const xmlChar *value = NULL;
+ xmlChar *valueBuffer = xmlMalloc(256);
+ valueBuffer[0] = '\0';
+ unsigned int currentSize = 255;
+
+// array_list_pt propertyValues = NULL;
+// arrayList_create(&propertyValues);
+
+ array_list_pt endpointDescriptions = NULL;
+ arrayList_create(&endpointDescriptions);
+
+ properties_pt endpointProperties = NULL;
+
+ int read = xmlTextReaderRead(reader->reader);
+ while (read == 1) {
+ int type = xmlTextReaderNodeType(reader->reader);
+
+ if (type == 1) {
+ const xmlChar *localname = xmlTextReaderConstLocalName(reader->reader);
+
+ if (inXml) {
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "<");
+ valueBuffer = xmlStrcat(valueBuffer, localname);
+
+ int i = xmlTextReaderMoveToFirstAttribute(reader->reader);
+ while (i == 1) {
+ const xmlChar *name = xmlTextReaderConstName(reader->reader);
+ const xmlChar *value = xmlTextReaderConstValue(reader->reader);
+
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST " ");
+ valueBuffer = xmlStrcat(valueBuffer, name);
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "=\"");
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST value);
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST "\"");
+
+ i = xmlTextReaderMoveToNextAttribute(reader->reader);
+ }
+
+ valueBuffer = xmlStrcat(valueBuffer, BAD_CAST ">");
+// read = xmlTextReaderRead(reader);
+// continue;
+ } else if (xmlStrcmp(localname, BAD_CAST "endpoint-description") == 0) {
+ endpointProperties = properties_create();
+ } else if (xmlStrcmp(localname, BAD_CAST "property") == 0) {
+ inProperty = true;
+ propertyName = xmlTextReaderGetAttribute(reader->reader, BAD_CAST "name");
+// propertyType = getValueType((const char *) xmlTextReaderGetAttribute(reader, "value-type"));
+// propertyType = xmlTextReaderGetAttribute(reader->reader, BAD_CAST "value-type");
+ propertyValue = xmlTextReaderGetAttribute(reader->reader, BAD_CAST "value");
+// arrayList_clear(propertyValues);
+
+ if (xmlTextReaderIsEmptyElement(reader->reader)) {
+ inProperty = false;
+
+ if (propertyValue != NULL) {
+ printf("Only string support\n");
+ // m_endpointProperties.put(m_propertyName, m_propertyType.parse(m_propertyValue));
+ properties_set(endpointProperties, (char *) propertyName, (char *) propertyValue);
+ }
+
+ free((void *) propertyName);
+ free((void *) propertyValue);
+ }
+
+ // read = xmlTextReaderRead(reader);
+// continue;
+ } else {
+ valueBuffer[0] = '\0';
+ value = NULL;
+ inArray |= inProperty && xmlStrcmp(localname, BAD_CAST "array") == 0;
+ inList |= inProperty && xmlStrcmp(localname, BAD_CAST "list") == 0;
+ inSet |= inProperty && xmlStrcmp(localname, BAD_CAST "set") == 0;
+ inXml |= inProperty && xmlStrcmp(localname, BAD_CAST "xml") == 0;
+ inValue |= inProperty && xmlStrcmp(localname, BAD_CAST "value") == 0;
+ }
+ }
+
+ if (type == 15) {
+ const xmlChar *localname = xmlTextReaderConstLocalName(reader->reader);
+
+ if (inXml) {
+ if (xmlStrcmp(localname, BAD_CAST "xml") != 0) {
+ xmlStrcmp(valueBuffer, BAD_CAST "</");
+ xmlStrcmp(valueBuffer, localname);
+ xmlStrcmp(valueBuffer, BAD_CAST ">");
+ }
+ else {
+ inXml = false;
+ }
+// read = xmlTextReaderRead(reader);
+// continue;
+ } else if (xmlStrcmp(localname, BAD_CAST "endpoint-description") == 0) {
+ endpoint_description_pt endpointDescription = NULL;
+ endpointDescription_create(endpointProperties, &endpointDescription);
+ arrayList_add(endpointDescriptions, endpointDescription);
+// endpointProperties = properties_create();
+// hashMap_clear(endpointProperties, false, false);
+// read = xmlTextReaderRead(reader);
+// continue;
+ } else if (xmlStrcmp(localname, BAD_CAST "property") == 0) {
+ inProperty = false;
+
+ if (inArray) {
+ printf("No array support\n");
+// m_endpointProperties.put(m_propertyName, getPropertyValuesArray());
+ }
+ else if (inList) {
+ printf("No list support\n");
+// m_endpointProperties.put(m_propertyName, getPropertyValuesList());
+ }
+ else if (inSet) {
+ printf("No set support\n");
+// m_endpointProperties.put(m_propertyName, getPropertyValuesSet());
+ }
+ else if (propertyValue != NULL) {
+ printf("Only string support\n");
+// m_endpointProperties.put(m_propertyName, m_propertyType.parse(m_propertyValue));
+ properties_set(endpointProperties, (char *) propertyName, (char *) propertyValue);
+
+ free((void *) propertyValue);
+ }
+ else {
+ properties_set(endpointProperties, (char *) propertyName, (char *) valueBuffer);
+ }
+
+ free((void *) propertyName);
+
+ inArray = false;
+ inList = false;
+ inSet = false;
+ inXml = false;
+// read = xmlTextReaderRead(reader);
+// continue;
+ } else if (xmlStrcmp(localname, BAD_CAST "value") == 0) {
+// m_propertyValues.add(m_propertyType.parse(m_valueBuffer.toString()));
+// arrayList_add(propertyValues, valueBuffer);
+ inValue = false;
+// read = xmlTextReaderRead(reader);
+// continue;
+ }
+ }
+
+ if (type == 3) {
+ if (inValue || inXml) {
+ const xmlChar *value = xmlTextReaderValue(reader->reader);
+ printf("Value: %s\n", value);
+ valueBuffer = xmlStrcat(valueBuffer, value);
+ xmlFree((void *)value);
+ }
+ }
+
+ read = xmlTextReaderRead(reader->reader);
+ }
+ *endpoints = endpointDescriptions;
+
+// arrayList_destroy(propertyValues);
+ free(valueBuffer);
+ xmlFreeTextReader(reader->reader);
+ }
+
+ return status;
+}
+
+//static valueType getValueType(char *name) {
+// if (name == NULL || strcmp(name, "") == 0) {
+// return VALUE_TYPE_STRING;
+// }
+// if (strcmp(name, "String") == 0) {
+// return VALUE_TYPE_STRING;
+// } else if (strcmp(name, "long") == 0 || strcmp(name, "Long") == 0) {
+// return VALUE_TYPE_LONG;
+// } else if (strcmp(name, "double") == 0 || strcmp(name, "Double") == 0) {
+// return VALUE_TYPE_DOUBLE;
+// } else if (strcmp(name, "float") == 0 || strcmp(name, "Float") == 0) {
+// return VALUE_TYPE_FLOAT;
+// } else if (strcmp(name, "integer") == 0 || strcmp(name, "Integer") == 0) {
+// return VALUE_TYPE_INTEGER;
+// } else if (strcmp(name, "short") == 0 || strcmp(name, "Short") == 0) {
+// return VALUE_TYPE_SHORT;
+// } else if (strcmp(name, "byte") == 0 || strcmp(name, "Byte") == 0) {
+// return VALUE_TYPE_BYTE;
+// } else if (strcmp(name, "char") == 0 || strcmp(name, "Character") == 0) {
+// return VALUE_TYPE_CHAR;
+// } else if (strcmp(name, "boolean") == 0 || strcmp(name, "Boolean") == 0) {
+// return VALUE_TYPE_BOOLEAN;
+// } else {
+// return VALUE_TYPE_STRING;
+// }
+//}
+
+int main() {
+ array_list_pt list = NULL;
+ endpoint_descriptor_reader_pt reader = NULL;
+ endpointDescriptorReader_create(&reader);
+
+ char *doc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<endpoint-descriptions xmlns=\"http://www.osgi.org/xmlns/rsa/v1.0.0\">"
+ "<endpoint-description>"
+ "<property name=\"service.intents\">"
+ "<list>"
+ "<value>SOAP</value>"
+ "<value>HTTP</value>"
+ "</list>"
+ "</property>"
+ "<property name=\"endpoint.id\" value=\"http://ws.acme.com:9000/hello\" />"
+ "<property name=\"objectClass\" value=\"com.acme.Foo\" />"
+ "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
+ "<property name=\"service.imported.configs\" value=\"com.acme\" />"
+ "<property name=\"com.acme.ws.xml\">"
+ "<xml>"
+ "<config xmlns=\"http://acme.com/defs\">"
+ "<port>1029</port>"
+ "<host>www.acme.com</host>"
+ "</config>"
+ "</xml>"
+ "</property>"
+ "</endpoint-description>"
+ "<endpoint-description>"
+ "<property name=\"service.intents\">"
+ "<list>"
+ "<value>SOAP</value>"
+ "<value>HTTP</value>"
+ "</list>"
+ "</property>"
+ "<property name=\"endpoint.id\" value=\"http://ws.acme.com:9000/goodbye\" />"
+ "<property name=\"objectClass\" value=\"com.acme.Doo\" />"
+ "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\" />"
+ "<property name=\"service.imported.configs\" value=\"com.acme\" />"
+ "<property name=\"com.acme.ws.xml\">"
+ "<xml>"
+ "<config xmlns=\"http://acme.com/defs\">"
+ "<port>1029</port>"
+ "<host>www.acme.com</host>"
+ "</config>"
+ "</xml>"
+ "</property>"
+ "</endpoint-description>"
+"</endpoint-descriptions>";
+
+ endpointDescriptorReader_parseDocument(reader, doc, &list);
+
+ int i;
+ for (i = 0; i < arrayList_size(list); i++) {
+ endpoint_description_pt edp = arrayList_get(list, i);
+ printf("Service: %s\n", edp->service);
+ printf("Id: %s\n", edp->id);
+
+ endpointDescription_destroy(edp);
+ }
+
+ if (list != NULL) {
+ arrayList_destroy(list);
+ }
+
+ endpointDescriptorReader_destroy(reader);
+
+ return 0;
+}
Added: celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_writer.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_writer.c?rev=1613670&view=auto
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_writer.c (added)
+++ celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_writer.c Sat Jul 26 16:26:09 2014
@@ -0,0 +1,156 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you 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.
+ */
+/*
+ * endpoint_description_writer.c
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <libxml/xmlwriter.h>
+
+#include "endpoint_description.h"
+#include "endpoint_descriptor_writer.h"
+
+struct endpoint_descriptor_writer {
+ xmlBufferPtr buffer;
+ xmlTextWriterPtr writer;
+};
+
+static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor_writer_pt writer, endpoint_description_pt endpoint);
+
+celix_status_t endpointDescriptorWriter_create(endpoint_descriptor_writer_pt *writer) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *writer = malloc(sizeof(**writer));
+ if (!writer) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*writer)->buffer = xmlBufferCreate();
+ if ((*writer)->buffer == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ (*writer)->writer = xmlNewTextWriterMemory((*writer)->buffer, 0);
+ if ((*writer)->writer == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t endpointDescriptorWriter_destroy(endpoint_descriptor_writer_pt writer) {
+ xmlFreeTextWriter(writer->writer);
+ xmlBufferFree(writer->buffer);
+ free(writer);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document) {
+ celix_status_t status = CELIX_SUCCESS;
+ int rc;
+
+ rc = xmlTextWriterStartDocument(writer->writer, NULL, "UTF-8", NULL);
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ rc = xmlTextWriterStartElementNS(writer->writer, NULL, BAD_CAST "endpoint-descriptions", BAD_CAST "http://www.osgi.org/xmlns/rsa/v1.0.0");
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ int i;
+ for (i = 0; i < arrayList_size(endpoints); i++) {
+ endpoint_description_pt endpoint = arrayList_get(endpoints, i);
+ status = endpointDescriptorWriter_writeEndpoint(writer, endpoint);
+ }
+ if (status == CELIX_SUCCESS) {
+ rc = xmlTextWriterEndElement(writer->writer);
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ rc = xmlTextWriterEndDocument(writer->writer);
+ if (rc < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ *document = (char *) writer->buffer->content;
+ }
+ }
+ }
+ }
+ }
+
+ return status;
+}
+
+static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor_writer_pt writer, endpoint_description_pt endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (endpoint == NULL || writer == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ } else {
+ xmlTextWriterStartElement(writer->writer, BAD_CAST "endpoint-description");
+
+ hash_map_iterator_pt iter = hashMapIterator_create(endpoint->properties);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ xmlTextWriterStartElement(writer->writer, BAD_CAST "property");
+ xmlTextWriterWriteAttribute(writer->writer, BAD_CAST "name", hashMapEntry_getKey(entry));
+ xmlTextWriterWriteAttribute(writer->writer, BAD_CAST "value", hashMapEntry_getValue(entry));
+ xmlTextWriterEndElement(writer->writer);
+ }
+ hashMapIterator_destroy(iter);
+
+ xmlTextWriterEndElement(writer->writer);
+ }
+
+ return status;
+}
+
+
+int main() {
+ endpoint_descriptor_writer_pt writer = NULL;
+ endpointDescriptorWriter_create(&writer);
+ array_list_pt list = NULL;
+ arrayList_create(&list);
+
+ properties_pt props = properties_create();
+ properties_set(props, "a", "b");
+ endpoint_description_pt epd = NULL;
+ endpointDescription_create(props, &epd);
+ arrayList_add(list, epd);
+
+ properties_pt props2 = properties_create();
+ properties_set(props2, "a", "b");
+ endpoint_description_pt epd2 = NULL;
+ endpointDescription_create(props2, &epd2);
+ arrayList_add(list, epd2);
+
+ char *buffer = NULL;
+ endpointDescriptorWriter_writeDocument(writer, list, &buffer);
+
+ arrayList_destroy(list);
+ endpointDescription_destroy(epd);
+ endpointDescription_destroy(epd2);
+ endpointDescriptorWriter_destroy(writer);
+
+ printf("%s\n", buffer);
+}
Modified: celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h?rev=1613670&r1=1613669&r2=1613670&view=diff
==============================================================================
--- celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h (original)
+++ celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h Sat Jul 26 16:26:09 2014
@@ -30,18 +30,7 @@
#include "array_list.h"
#include "properties.h"
-struct endpoint_description {
- array_list_pt configurationTypes;
- char *frameworkUUID;
- char *id;
- // array_list_pt intents;
- char *service;
- // HASH_MAP packageVersions;
- properties_pt properties;
- long serviceId;
-};
-
-typedef struct endpoint_description *endpoint_description_pt;
+#include "endpoint_description.h"
static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
Added: celix/trunk/remote_services/remote_service_admin/private/src/endpoint_description.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin/private/src/endpoint_description.c?rev=1613670&view=auto
==============================================================================
--- celix/trunk/remote_services/remote_service_admin/private/src/endpoint_description.c (added)
+++ celix/trunk/remote_services/remote_service_admin/private/src/endpoint_description.c Sat Jul 26 16:26:09 2014
@@ -0,0 +1,68 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you 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.
+ */
+/*
+ * endpoint_description.c
+ *
+ * \date 25 Jul 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "celix_errno.h"
+
+#include "endpoint_description.h"
+#include "remote_constants.h"
+#include "constants.h"
+
+static celix_status_t endpointDescription_verifyLongProperty(endpoint_description_pt description, char *propertyName, long *longProperty);
+
+celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription) {
+
+ *endpointDescription = malloc(sizeof(**endpointDescription));
+
+ (*endpointDescription)->properties = properties;
+
+ (*endpointDescription)->frameworkUUID = NULL;
+ endpointDescription_verifyLongProperty(*endpointDescription, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID, &(*endpointDescription)->serviceId);
+ (*endpointDescription)->id = properties_get(properties, (char *) OSGI_RSA_ENDPOINT_ID);
+ (*endpointDescription)->service = properties_get(properties, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
+
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t endpointDescription_destroy(endpoint_description_pt description) {
+ properties_destroy(description->properties);
+ free(description);
+ return CELIX_SUCCESS;
+}
+
+static celix_status_t endpointDescription_verifyLongProperty(endpoint_description_pt description, char *propertyName, long *longProperty) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ char *value = properties_get(description->properties, propertyName);
+ if (value == NULL) {
+ *longProperty = 0l;
+ } else {
+ *longProperty = atol(value);
+ }
+
+ return status;
+}
Copied: celix/trunk/remote_services/remote_service_admin/public/include/endpoint_description.h (from r1613541, celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h)
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin/public/include/endpoint_description.h?p2=celix/trunk/remote_services/remote_service_admin/public/include/endpoint_description.h&p1=celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h&r1=1613541&r2=1613670&rev=1613670&view=diff
==============================================================================
--- celix/trunk/remote_services/endpoint_listener/public/include/endpoint_listener.h (original)
+++ celix/trunk/remote_services/remote_service_admin/public/include/endpoint_description.h Sat Jul 26 16:26:09 2014
@@ -17,43 +17,34 @@
*under the License.
*/
/*
- * endpoint_listener.h
+ * endpoint_description.h
*
- * \date Sep 29, 2011
- * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \date 25 Jul 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
-#ifndef ENDPOINT_LISTENER_H_
-#define ENDPOINT_LISTENER_H_
+#ifndef ENDPOINT_DESCRIPTION_H_
+#define ENDPOINT_DESCRIPTION_H_
-#include "array_list.h"
#include "properties.h"
+#include "array_list.h"
struct endpoint_description {
- array_list_pt configurationTypes;
- char *frameworkUUID;
- char *id;
- // array_list_pt intents;
- char *service;
- // HASH_MAP packageVersions;
- properties_pt properties;
- long serviceId;
+ array_list_pt configurationTypes;
+ char *frameworkUUID;
+ char *id;
+ // array_list_pt intents;
+ char *service;
+ // HASH_MAP packageVersions;
+ properties_pt properties;
+ long serviceId;
};
typedef struct endpoint_description *endpoint_description_pt;
-static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
-
-static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope";
-
-struct endpoint_listener {
- void *handle;
- celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
- celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
-};
-
-typedef struct endpoint_listener *endpoint_listener_pt;
+celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt *endpointDescription);
+celix_status_t endpointDescription_destroy(endpoint_description_pt description);
-#endif /* ENDPOINT_LISTENER_H_ */
+#endif /* ENDPOINT_DESCRIPTION_H_ */
Modified: celix/trunk/remote_services/topology_manager/private/include/topology_manager.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/topology_manager/private/include/topology_manager.h?rev=1613670&r1=1613669&r2=1613670&view=diff
==============================================================================
--- celix/trunk/remote_services/topology_manager/private/include/topology_manager.h (original)
+++ celix/trunk/remote_services/topology_manager/private/include/topology_manager.h Sat Jul 26 16:26:09 2014
@@ -34,6 +34,7 @@
typedef struct topology_manager *topology_manager_pt;
celix_status_t topologyManager_create(bundle_context_pt context, apr_pool_t *pool, topology_manager_pt *manager);
+celix_status_t topologyManager_destroy(topology_manager_pt manager);
celix_status_t topologyManager_rsaAdding(void *handle, service_reference_pt reference, void **service);
celix_status_t topologyManager_rsaAdded(void *handle, service_reference_pt reference, void *service);
Modified: celix/trunk/remote_services/utils/public/include/remote_constants.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/utils/public/include/remote_constants.h?rev=1613670&r1=1613669&r2=1613670&view=diff
==============================================================================
--- celix/trunk/remote_services/utils/public/include/remote_constants.h (original)
+++ celix/trunk/remote_services/utils/public/include/remote_constants.h Sat Jul 26 16:26:09 2014
@@ -30,6 +30,7 @@
static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
+static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";