You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celix.apache.org by "pnoltes (via GitHub)" <gi...@apache.org> on 2023/05/07 12:14:24 UTC

[PR] #551: Add 1st part of the requirement-capability-model lib (celix)

pnoltes opened a new pull request, #547:
URL: https://github.com/apache/celix/pull/547

   This pull request adds a basic implementation of the requirement-capability model in a static Celix::rcm library.
   
   This is the first task of https://github.com/apache/celix/issues/511. Future work on https://github.com/apache/celix/issues/511 will probably be done much later.
   
   Note that this pull request reuses the code introduced in #518 and that #518 will be rejected.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #551: Add 1st part of the requirement-capability-model lib (celix)

Posted by "PengZheng (via GitHub)" <gi...@apache.org>.
PengZheng commented on code in PR #547:
URL: https://github.com/apache/celix/pull/547#discussion_r1187351915


##########
libs/rcm/include/celix_capability.h:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_CAPABILITY_H
+#define CELIX_CELIX_CAPABILITY_H
+
+#include <stdbool.h>
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_capability.h
+* @brief The celix_capability_t is a struct which represents a capability.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new capability.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the capability. Can be NULL.
+ * @param[in] ns The namespace of the capability.
+ * @return The new capability.
+ * @retval NULL If an error occurred.
+ */
+celix_capability_t* celix_capability_create(
+        const celix_resource_t* resource,
+        const char* ns);
+
+/**
+ * @brief Destroys the capability.
+ * @param[in] capability The capability to destroy. Can be NULL.
+ */
+void celix_capability_destroy(celix_capability_t* capability);
+
+/**
+ * @brief Check if 2 capabilities are equal.
+ */
+bool celix_capability_equals(const celix_capability_t* cap1, const celix_capability_t* cap2);
+
+/**
+ * @brief Returns the hash code of the capability.
+ */
+unsigned int celix_capability_hashCode(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the resource which contains the capability.
+ * @param[in] cap The capability.
+ * @return The resource or NULL if no resource is set.
+ */
+const celix_resource_t* celix_capability_getResource(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the namespace of the capability.
+ * @param[in] cap The capability.
+ * @return The namespace of the capability.
+ */
+const char* celix_capability_getNamespace(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the attributes of the capability.
+ * @param[in] cap The capability.
+ * @return The attributes of the capability. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_capability_getAttributes(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the directives of the capability.
+ * @param[in] cap The capability.
+ * @return The directives of the capability. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_capability_getDirectives(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the value of the attribute with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_capability_getAttribute(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_capability_getDirective(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Add a new attribute to the capability.
+ *
+ * Note replaces an existing attribute is the key is already set.

Review Comment:
   ```suggestion
    * Note it replaces an exisiting attribute if the key is already set.
   ```



##########
libs/rcm/include/celix_capability.h:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_CAPABILITY_H
+#define CELIX_CELIX_CAPABILITY_H
+
+#include <stdbool.h>
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_capability.h
+* @brief The celix_capability_t is a struct which represents a capability.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new capability.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the capability. Can be NULL.
+ * @param[in] ns The namespace of the capability.
+ * @return The new capability.
+ * @retval NULL If an error occurred.
+ */
+celix_capability_t* celix_capability_create(
+        const celix_resource_t* resource,
+        const char* ns);
+
+/**
+ * @brief Destroys the capability.
+ * @param[in] capability The capability to destroy. Can be NULL.
+ */
+void celix_capability_destroy(celix_capability_t* capability);
+
+/**
+ * @brief Check if 2 capabilities are equal.
+ */
+bool celix_capability_equals(const celix_capability_t* cap1, const celix_capability_t* cap2);
+
+/**
+ * @brief Returns the hash code of the capability.
+ */
+unsigned int celix_capability_hashCode(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the resource which contains the capability.
+ * @param[in] cap The capability.
+ * @return The resource or NULL if no resource is set.
+ */
+const celix_resource_t* celix_capability_getResource(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the namespace of the capability.
+ * @param[in] cap The capability.
+ * @return The namespace of the capability.
+ */
+const char* celix_capability_getNamespace(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the attributes of the capability.
+ * @param[in] cap The capability.
+ * @return The attributes of the capability. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_capability_getAttributes(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the directives of the capability.
+ * @param[in] cap The capability.
+ * @return The directives of the capability. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_capability_getDirectives(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the value of the attribute with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_capability_getAttribute(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_capability_getDirective(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Add a new attribute to the capability.
+ *
+ * Note replaces an existing attribute is the key is already set.
+ *
+ * @param[in] cap The capability.
+ * @param[in] key The key of the attribute.
+ * @param[in] value The value of the attribute.
+ */
+void celix_capability_addAttribute(celix_capability_t* cap, const char* key, const char* value);
+
+/**
+ * @brief Add a new attributes to the capability.
+ *
+ * Note replaces existing attributes is some of the provided keys are already set.
+ *
+ * @param[in] cap The capability.
+ * @param[in] attributes The attributes to add.
+ *                       Note the attributes are copied, so the caller is still owner of the properties.
+ */
+void celix_capability_addAttributes(celix_capability_t* cap, const celix_properties_t* attributes);
+
+/**
+ * @brief Add a new directive to the capability.
+ *
+ * Note replaces an existing directive is the key is already set.
+ *
+ * @param[in] cap The capability.
+ * @param[in] key The key of the directive.
+ * @param[in] value The value of the directive.
+ */
+void celix_capability_addDirective(celix_capability_t* cap, const char* key, const char* value);
+
+/**
+ * @brief Add a new directives to the capability.
+ *
+ * Note replaces existing directives is some of the provided keys are already set.

Review Comment:
   ```suggestion
    * Note it replaces existing directives if some of the provided keys are already set.
   ```
   



##########
libs/rcm/include/celix_capability.h:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_CAPABILITY_H
+#define CELIX_CELIX_CAPABILITY_H
+
+#include <stdbool.h>
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_capability.h
+* @brief The celix_capability_t is a struct which represents a capability.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new capability.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the capability. Can be NULL.
+ * @param[in] ns The namespace of the capability.
+ * @return The new capability.
+ * @retval NULL If an error occurred.
+ */
+celix_capability_t* celix_capability_create(
+        const celix_resource_t* resource,
+        const char* ns);
+
+/**
+ * @brief Destroys the capability.
+ * @param[in] capability The capability to destroy. Can be NULL.
+ */
+void celix_capability_destroy(celix_capability_t* capability);
+
+/**
+ * @brief Check if 2 capabilities are equal.
+ */
+bool celix_capability_equals(const celix_capability_t* cap1, const celix_capability_t* cap2);
+
+/**
+ * @brief Returns the hash code of the capability.
+ */
+unsigned int celix_capability_hashCode(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the resource which contains the capability.
+ * @param[in] cap The capability.
+ * @return The resource or NULL if no resource is set.
+ */
+const celix_resource_t* celix_capability_getResource(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the namespace of the capability.
+ * @param[in] cap The capability.
+ * @return The namespace of the capability.
+ */
+const char* celix_capability_getNamespace(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the attributes of the capability.
+ * @param[in] cap The capability.
+ * @return The attributes of the capability. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_capability_getAttributes(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the directives of the capability.
+ * @param[in] cap The capability.
+ * @return The directives of the capability. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_capability_getDirectives(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the value of the attribute with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_capability_getAttribute(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_capability_getDirective(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Add a new attribute to the capability.
+ *
+ * Note replaces an existing attribute is the key is already set.
+ *
+ * @param[in] cap The capability.
+ * @param[in] key The key of the attribute.
+ * @param[in] value The value of the attribute.
+ */
+void celix_capability_addAttribute(celix_capability_t* cap, const char* key, const char* value);
+
+/**
+ * @brief Add a new attributes to the capability.
+ *
+ * Note replaces existing attributes is some of the provided keys are already set.

Review Comment:
   ```suggestion
    * Note it replaces existing attributes if some of the provided keys are already set.
   ```



##########
libs/rcm/include/celix_requirement.h:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_REQUIREMENT_H
+#define CELIX_CELIX_REQUIREMENT_H
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_requirement.h
+* @brief The celix_requirement_t is a requirement for a capability.
+*
+* A requirement is a requirement for a capability. A requirement has a namespace, a filter and a set of directives and attributes.
+* The namespace is used to identify the type of requirement. The filter is used to filter the capabilities.
+* The directives and attributes are used to configure the requirement.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new requirement.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the requirement. Can be NULL.
+ * @param[in] ns The namespace of the requirement.
+ * @param[in] filter The filter of the requirement. Can be NULL.
+ * @return The new requirement.
+ * @retval NULL If an error occurred.
+ */
+celix_requirement_t* celix_requirement_create(
+        celix_resource_t* resource,
+        const char* ns,
+        const char* filter);
+
+
+/**
+ * @brief Destroys the requirement.
+ * @param[in] requirement The requirement to destroy. Can be NULL.
+ */
+void celix_requirement_destroy(celix_requirement_t* requirement);
+
+/**
+ * @brief Check if 2 requirements are equal.
+ */
+bool celix_requirement_equals(const celix_requirement_t* req1, const celix_requirement_t* req2);
+
+/**
+ * @brief Returns the hash code of the requirement.
+ */
+unsigned int celix_requirement_hashCode(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the resource which contains the requirement.
+ * @param[in] req The requirement.
+ * @return The resource which contains the requirement or NULL if the requirement is not part of a resource.
+ */
+const celix_resource_t* celix_requirement_getResource(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the namespace of the requirement.
+ * @param[in] req The requirement.
+ * @return The namespace of the requirement.
+ */
+const char* celix_requirement_getNamespace(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the filter of the requirement.
+ * @param[in] req The requirement.
+ * @return The filter of the requirement.
+ */
+const char* celix_requirement_getFilter(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the directives of the requirement.
+ * @param[in] req The requirement.
+ * @return The directives of the requirement. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_requirement_getDirectives(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_requirement_getDirective(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Returns the attributes of the requirement.
+ * @param[in] req The requirement.
+ * @return The attributes of the requirement. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_requirement_getAttributes(const celix_requirement_t* req);
+
+/**
+ *  @brief Returns the value of the attribute with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_requirement_getAttribute(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Add a new directive to the requirement.
+ *
+ * Note replaces an existing directive is the key is already set.
+ *
+ * @param[in] req The requirement.
+ * @param[in] key The key of the directive.
+ * @param[in] value The value of the directive.
+ */
+void celix_requirement_addDirective(celix_requirement_t* req, const char* key, const char* value);
+
+/**
+ * @brief Add a new directives to the requirement.
+ *
+ * Note replaces existing directives is some of the provided keys are already set.
+ *
+ * @param[in] req The requirement.
+ * @param[in] directives The directives to add.
+ *                       Note the directives are copied, so the caller is still owner of the properties.
+ */
+void celix_requirement_addDirectives(celix_requirement_t* req, const celix_properties_t* directives);
+
+/**
+ * @brief Add a new attribute to the requirement.
+ *
+ * Note replaces an existing attribute is the key is already set.

Review Comment:
   ```suggestion
    * Note it replaces an existing attribute if the key is already set.
   ```



##########
libs/rcm/include/celix_capability.h:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_CAPABILITY_H
+#define CELIX_CELIX_CAPABILITY_H
+
+#include <stdbool.h>
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_capability.h
+* @brief The celix_capability_t is a struct which represents a capability.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new capability.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the capability. Can be NULL.
+ * @param[in] ns The namespace of the capability.
+ * @return The new capability.
+ * @retval NULL If an error occurred.
+ */
+celix_capability_t* celix_capability_create(
+        const celix_resource_t* resource,
+        const char* ns);
+
+/**
+ * @brief Destroys the capability.
+ * @param[in] capability The capability to destroy. Can be NULL.
+ */
+void celix_capability_destroy(celix_capability_t* capability);
+
+/**
+ * @brief Check if 2 capabilities are equal.
+ */
+bool celix_capability_equals(const celix_capability_t* cap1, const celix_capability_t* cap2);
+
+/**
+ * @brief Returns the hash code of the capability.
+ */
+unsigned int celix_capability_hashCode(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the resource which contains the capability.
+ * @param[in] cap The capability.
+ * @return The resource or NULL if no resource is set.
+ */
+const celix_resource_t* celix_capability_getResource(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the namespace of the capability.
+ * @param[in] cap The capability.
+ * @return The namespace of the capability.
+ */
+const char* celix_capability_getNamespace(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the attributes of the capability.
+ * @param[in] cap The capability.
+ * @return The attributes of the capability. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_capability_getAttributes(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the directives of the capability.
+ * @param[in] cap The capability.
+ * @return The directives of the capability. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_capability_getDirectives(const celix_capability_t* cap);
+
+/**
+ * @brief Returns the value of the attribute with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_capability_getAttribute(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] cap The capability.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_capability_getDirective(const celix_capability_t* cap, const char* key);
+
+/**
+ * @brief Add a new attribute to the capability.
+ *
+ * Note replaces an existing attribute is the key is already set.
+ *
+ * @param[in] cap The capability.
+ * @param[in] key The key of the attribute.
+ * @param[in] value The value of the attribute.
+ */
+void celix_capability_addAttribute(celix_capability_t* cap, const char* key, const char* value);
+
+/**
+ * @brief Add a new attributes to the capability.
+ *
+ * Note replaces existing attributes is some of the provided keys are already set.
+ *
+ * @param[in] cap The capability.
+ * @param[in] attributes The attributes to add.
+ *                       Note the attributes are copied, so the caller is still owner of the properties.
+ */
+void celix_capability_addAttributes(celix_capability_t* cap, const celix_properties_t* attributes);
+
+/**
+ * @brief Add a new directive to the capability.
+ *
+ * Note replaces an existing directive is the key is already set.

Review Comment:
   ```suggestion
    * Note it replaces an existing directive if the key is already set.
   ```



##########
libs/rcm/include/celix_requirement.h:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_REQUIREMENT_H
+#define CELIX_CELIX_REQUIREMENT_H
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_requirement.h
+* @brief The celix_requirement_t is a requirement for a capability.
+*
+* A requirement is a requirement for a capability. A requirement has a namespace, a filter and a set of directives and attributes.
+* The namespace is used to identify the type of requirement. The filter is used to filter the capabilities.
+* The directives and attributes are used to configure the requirement.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new requirement.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the requirement. Can be NULL.
+ * @param[in] ns The namespace of the requirement.
+ * @param[in] filter The filter of the requirement. Can be NULL.
+ * @return The new requirement.
+ * @retval NULL If an error occurred.
+ */
+celix_requirement_t* celix_requirement_create(
+        celix_resource_t* resource,
+        const char* ns,
+        const char* filter);
+
+
+/**
+ * @brief Destroys the requirement.
+ * @param[in] requirement The requirement to destroy. Can be NULL.
+ */
+void celix_requirement_destroy(celix_requirement_t* requirement);
+
+/**
+ * @brief Check if 2 requirements are equal.
+ */
+bool celix_requirement_equals(const celix_requirement_t* req1, const celix_requirement_t* req2);
+
+/**
+ * @brief Returns the hash code of the requirement.
+ */
+unsigned int celix_requirement_hashCode(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the resource which contains the requirement.
+ * @param[in] req The requirement.
+ * @return The resource which contains the requirement or NULL if the requirement is not part of a resource.
+ */
+const celix_resource_t* celix_requirement_getResource(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the namespace of the requirement.
+ * @param[in] req The requirement.
+ * @return The namespace of the requirement.
+ */
+const char* celix_requirement_getNamespace(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the filter of the requirement.
+ * @param[in] req The requirement.
+ * @return The filter of the requirement.
+ */
+const char* celix_requirement_getFilter(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the directives of the requirement.
+ * @param[in] req The requirement.
+ * @return The directives of the requirement. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_requirement_getDirectives(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_requirement_getDirective(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Returns the attributes of the requirement.
+ * @param[in] req The requirement.
+ * @return The attributes of the requirement. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_requirement_getAttributes(const celix_requirement_t* req);
+
+/**
+ *  @brief Returns the value of the attribute with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_requirement_getAttribute(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Add a new directive to the requirement.
+ *
+ * Note replaces an existing directive is the key is already set.

Review Comment:
   ```suggestion
    * Note it replaces an existing directive if the key is already set.
   ```



##########
libs/rcm/include/celix_resource.h:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_RESOURCE_H
+#define CELIX_CELIX_RESOURCE_H
+
+#include "celix_rcm_types.h"
+#include "celix_array_list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_resource.h
+* @brief The celix_resource_t is a resource in the RCM.
+*
+* A resource is a collection of capabilities and requirements.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new resource.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @return A new resource.
+ * @retval NULL If the resource could not be created.
+ */
+celix_resource_t* celix_resource_create();
+
+/**
+ * @brief Destroys the resource.
+ * @param[in] resource The resource to destroy. Can be NULL.
+ */
+void celix_resource_destroy(celix_resource_t* resource);
+
+/**
+ * @brief Returns the capabilities of the resource.
+ *
+ * Will return all resource capabilities if the provided namespace is NULL.
+ *
+ * @param[in] res The resource.
+ * @param[in] ns The namespace of the capabilities. Can be NULL.
+ * @return The capabilities of the resource. Will be an empty list if the resource has no capabilities or
+ *         has no capabilities with the provided namespace.
+ */
+const celix_array_list_t* celix_resource_getCapabilities(const celix_resource_t* res, const char* ns);
+
+/**
+ * @brief Returns the requirements of the resource for the provided namespace.
+ *
+ * Will return all resource requirements if the provided namespace is NULL.
+ *
+ * @param[in] res The resource.
+ * @param[in] ns The namespace of the requirements. Can be NULL.
+ * @return The requirements of the resource. Will be an empty list if the resource has no requirements or
+ *         has no requirements with the provided namespace.
+ */
+const celix_array_list_t* celix_resource_getRequirements(const celix_resource_t* res, const char* ns);
+
+/**
+ * @brief Adds a capability to the resource.
+ *
+ * The capability resource must be the same as this resource or a CELIX_ILLEGAL_ARGUMENT error is returned.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] res The resource.
+ * @param[in] cap The capability to add.
+ * @return CELIX_SUCCESS if the capability was added successfully.
+ * @retval CELIX_ILLEGAL_ARGUMENT If the capability resource is not the same as this resource.
+ * @retval ENOMEM If there is not enough memory to add the capability.
+ */
+celix_status_t celix_resource_addCapability(celix_resource_t* res, celix_capability_t* cap);
+
+/**
+ * @brief Adds a requirement to the resource.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] res The resource.
+ * @param[in] req The requirement to add.
+ * @return CELIX_SUCCESS if the requirement was added successfully.
+ * @retval CELIX_ILLEGAL_ARGUMENT If the requirement resource is not the same as this resource.
+ * @retval ENOMEM If there is not enough memory to add the requirement.
+ */
+celix_status_t celix_resource_addRequirement(celix_resource_t* res, celix_requirement_t* req);

Review Comment:
   It should be made clear that if `celix_resource_addRequirement` fails, the caller is still the owner of `req`, and thus is responsible for releasing it. The same remark also applies to `celix_resource_addCapability`.



##########
libs/rcm/include/celix_requirement.h:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_REQUIREMENT_H
+#define CELIX_CELIX_REQUIREMENT_H
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_requirement.h
+* @brief The celix_requirement_t is a requirement for a capability.
+*
+* A requirement is a requirement for a capability. A requirement has a namespace, a filter and a set of directives and attributes.
+* The namespace is used to identify the type of requirement. The filter is used to filter the capabilities.
+* The directives and attributes are used to configure the requirement.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new requirement.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the requirement. Can be NULL.
+ * @param[in] ns The namespace of the requirement.
+ * @param[in] filter The filter of the requirement. Can be NULL.
+ * @return The new requirement.
+ * @retval NULL If an error occurred.
+ */
+celix_requirement_t* celix_requirement_create(
+        celix_resource_t* resource,
+        const char* ns,
+        const char* filter);
+
+
+/**
+ * @brief Destroys the requirement.
+ * @param[in] requirement The requirement to destroy. Can be NULL.
+ */
+void celix_requirement_destroy(celix_requirement_t* requirement);
+
+/**
+ * @brief Check if 2 requirements are equal.
+ */
+bool celix_requirement_equals(const celix_requirement_t* req1, const celix_requirement_t* req2);
+
+/**
+ * @brief Returns the hash code of the requirement.
+ */
+unsigned int celix_requirement_hashCode(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the resource which contains the requirement.
+ * @param[in] req The requirement.
+ * @return The resource which contains the requirement or NULL if the requirement is not part of a resource.
+ */
+const celix_resource_t* celix_requirement_getResource(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the namespace of the requirement.
+ * @param[in] req The requirement.
+ * @return The namespace of the requirement.
+ */
+const char* celix_requirement_getNamespace(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the filter of the requirement.
+ * @param[in] req The requirement.
+ * @return The filter of the requirement.
+ */
+const char* celix_requirement_getFilter(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the directives of the requirement.
+ * @param[in] req The requirement.
+ * @return The directives of the requirement. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_requirement_getDirectives(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_requirement_getDirective(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Returns the attributes of the requirement.
+ * @param[in] req The requirement.
+ * @return The attributes of the requirement. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_requirement_getAttributes(const celix_requirement_t* req);
+
+/**
+ *  @brief Returns the value of the attribute with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_requirement_getAttribute(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Add a new directive to the requirement.
+ *
+ * Note replaces an existing directive is the key is already set.
+ *
+ * @param[in] req The requirement.
+ * @param[in] key The key of the directive.
+ * @param[in] value The value of the directive.
+ */
+void celix_requirement_addDirective(celix_requirement_t* req, const char* key, const char* value);
+
+/**
+ * @brief Add a new directives to the requirement.
+ *
+ * Note replaces existing directives is some of the provided keys are already set.

Review Comment:
   ```suggestion
    * Note it replaces existing directives if some of the provided keys are already set.
   ```



##########
libs/rcm/include/celix_requirement.h:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_REQUIREMENT_H
+#define CELIX_CELIX_REQUIREMENT_H
+
+#include "celix_rcm_types.h"
+#include "celix_properties.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_requirement.h
+* @brief The celix_requirement_t is a requirement for a capability.
+*
+* A requirement is a requirement for a capability. A requirement has a namespace, a filter and a set of directives and attributes.
+* The namespace is used to identify the type of requirement. The filter is used to filter the capabilities.
+* The directives and attributes are used to configure the requirement.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new requirement.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] resource The resource which contains the requirement. Can be NULL.
+ * @param[in] ns The namespace of the requirement.
+ * @param[in] filter The filter of the requirement. Can be NULL.
+ * @return The new requirement.
+ * @retval NULL If an error occurred.
+ */
+celix_requirement_t* celix_requirement_create(
+        celix_resource_t* resource,
+        const char* ns,
+        const char* filter);
+
+
+/**
+ * @brief Destroys the requirement.
+ * @param[in] requirement The requirement to destroy. Can be NULL.
+ */
+void celix_requirement_destroy(celix_requirement_t* requirement);
+
+/**
+ * @brief Check if 2 requirements are equal.
+ */
+bool celix_requirement_equals(const celix_requirement_t* req1, const celix_requirement_t* req2);
+
+/**
+ * @brief Returns the hash code of the requirement.
+ */
+unsigned int celix_requirement_hashCode(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the resource which contains the requirement.
+ * @param[in] req The requirement.
+ * @return The resource which contains the requirement or NULL if the requirement is not part of a resource.
+ */
+const celix_resource_t* celix_requirement_getResource(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the namespace of the requirement.
+ * @param[in] req The requirement.
+ * @return The namespace of the requirement.
+ */
+const char* celix_requirement_getNamespace(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the filter of the requirement.
+ * @param[in] req The requirement.
+ * @return The filter of the requirement.
+ */
+const char* celix_requirement_getFilter(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the directives of the requirement.
+ * @param[in] req The requirement.
+ * @return The directives of the requirement. Will be an empty properties if no directives are set.
+ */
+const celix_properties_t* celix_requirement_getDirectives(const celix_requirement_t* req);
+
+/**
+ * @brief Returns the value of the directive with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the directive.
+ * @return The value of the directive or NULL if the directive is not set.
+ */
+const char* celix_requirement_getDirective(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Returns the attributes of the requirement.
+ * @param[in] req The requirement.
+ * @return The attributes of the requirement. Will be an empty properties if no attributes are set.
+ */
+const celix_properties_t* celix_requirement_getAttributes(const celix_requirement_t* req);
+
+/**
+ *  @brief Returns the value of the attribute with the given key.
+ * @param[in] req The requirement.
+ * @param[in] key The key of the attribute.
+ * @return The value of the attribute or NULL if the attribute is not set.
+ */
+const char* celix_requirement_getAttribute(const celix_requirement_t* req, const char* key);
+
+/**
+ * @brief Add a new directive to the requirement.
+ *
+ * Note replaces an existing directive is the key is already set.
+ *
+ * @param[in] req The requirement.
+ * @param[in] key The key of the directive.
+ * @param[in] value The value of the directive.
+ */
+void celix_requirement_addDirective(celix_requirement_t* req, const char* key, const char* value);
+
+/**
+ * @brief Add a new directives to the requirement.
+ *
+ * Note replaces existing directives is some of the provided keys are already set.
+ *
+ * @param[in] req The requirement.
+ * @param[in] directives The directives to add.
+ *                       Note the directives are copied, so the caller is still owner of the properties.
+ */
+void celix_requirement_addDirectives(celix_requirement_t* req, const celix_properties_t* directives);
+
+/**
+ * @brief Add a new attribute to the requirement.
+ *
+ * Note replaces an existing attribute is the key is already set.
+ *
+ * @param[in] req The requirement.
+ * @param[in] key The key of the attribute.
+ * @param[in] value The value of the attribute.
+ */
+void celix_requirement_addAttribute(celix_requirement_t* req, const char* key, const char* value);
+
+/**
+ * @brief Add a new attributes to the requirement.
+ *
+ * Note replaces existing attributes is some of the provided keys are already set.

Review Comment:
   ```suggestion
    * Note it replaces existing attributes if some of the provided keys are already set.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #551: Add 1st part of the requirement-capability-model lib (celix)

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #547:
URL: https://github.com/apache/celix/pull/547#issuecomment-1537428479

   ## [Codecov](https://app.codecov.io/gh/apache/celix/pull/547?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#547](https://app.codecov.io/gh/apache/celix/pull/547?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6268ea7) into [master](https://app.codecov.io/gh/apache/celix/commit/63a008d8dc398cbcc6fa9e67e9aac7afb919b6bd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (63a008d) will **increase** coverage by `0.20%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #547      +/-   ##
   ==========================================
   + Coverage   77.45%   77.65%   +0.20%     
   ==========================================
     Files         226      229       +3     
     Lines       34642    34891     +249     
   ==========================================
   + Hits        26832    27096     +264     
   + Misses       7810     7795      -15     
   ```
   
   
   | [Impacted Files](https://app.codecov.io/gh/apache/celix/pull/547?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [libs/rcm/src/celix\_capability.c](https://app.codecov.io/gh/apache/celix/pull/547?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGlicy9yY20vc3JjL2NlbGl4X2NhcGFiaWxpdHkuYw==) | `100.00% <100.00%> (ø)` | |
   | [libs/rcm/src/celix\_requirement.c](https://app.codecov.io/gh/apache/celix/pull/547?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGlicy9yY20vc3JjL2NlbGl4X3JlcXVpcmVtZW50LmM=) | `100.00% <100.00%> (ø)` | |
   | [libs/rcm/src/celix\_resource.c](https://app.codecov.io/gh/apache/celix/pull/547?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGlicy9yY20vc3JjL2NlbGl4X3Jlc291cmNlLmM=) | `100.00% <100.00%> (ø)` | |
   
   ... and [5 files with indirect coverage changes](https://app.codecov.io/gh/apache/celix/pull/547/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #551: Add 1st part of the requirement-capability-model lib (celix)

Posted by "pnoltes (via GitHub)" <gi...@apache.org>.
pnoltes merged PR #547:
URL: https://github.com/apache/celix/pull/547


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #551: Add 1st part of the requirement-capability-model lib (celix)

Posted by "pnoltes (via GitHub)" <gi...@apache.org>.
pnoltes commented on code in PR #547:
URL: https://github.com/apache/celix/pull/547#discussion_r1187684461


##########
libs/rcm/include/celix_resource.h:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_RESOURCE_H
+#define CELIX_CELIX_RESOURCE_H
+
+#include "celix_rcm_types.h"
+#include "celix_array_list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_resource.h
+* @brief The celix_resource_t is a resource in the RCM.
+*
+* A resource is a collection of capabilities and requirements.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new resource.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @return A new resource.
+ * @retval NULL If the resource could not be created.
+ */
+celix_resource_t* celix_resource_create();
+
+/**
+ * @brief Destroys the resource.
+ * @param[in] resource The resource to destroy. Can be NULL.
+ */
+void celix_resource_destroy(celix_resource_t* resource);
+
+/**
+ * @brief Returns the capabilities of the resource.
+ *
+ * Will return all resource capabilities if the provided namespace is NULL.
+ *
+ * @param[in] res The resource.
+ * @param[in] ns The namespace of the capabilities. Can be NULL.
+ * @return The capabilities of the resource. Will be an empty list if the resource has no capabilities or
+ *         has no capabilities with the provided namespace.
+ */
+const celix_array_list_t* celix_resource_getCapabilities(const celix_resource_t* res, const char* ns);
+
+/**
+ * @brief Returns the requirements of the resource for the provided namespace.
+ *
+ * Will return all resource requirements if the provided namespace is NULL.
+ *
+ * @param[in] res The resource.
+ * @param[in] ns The namespace of the requirements. Can be NULL.
+ * @return The requirements of the resource. Will be an empty list if the resource has no requirements or
+ *         has no requirements with the provided namespace.
+ */
+const celix_array_list_t* celix_resource_getRequirements(const celix_resource_t* res, const char* ns);
+
+/**
+ * @brief Adds a capability to the resource.
+ *
+ * The capability resource must be the same as this resource or a CELIX_ILLEGAL_ARGUMENT error is returned.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] res The resource.
+ * @param[in] cap The capability to add.
+ * @return CELIX_SUCCESS if the capability was added successfully.
+ * @retval CELIX_ILLEGAL_ARGUMENT If the capability resource is not the same as this resource.
+ * @retval ENOMEM If there is not enough memory to add the capability.
+ */
+celix_status_t celix_resource_addCapability(celix_resource_t* res, celix_capability_t* cap);
+
+/**
+ * @brief Adds a requirement to the resource.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] res The resource.
+ * @param[in] req The requirement to add.
+ * @return CELIX_SUCCESS if the requirement was added successfully.
+ * @retval CELIX_ILLEGAL_ARGUMENT If the requirement resource is not the same as this resource.
+ * @retval ENOMEM If there is not enough memory to add the requirement.
+ */
+celix_status_t celix_resource_addRequirement(celix_resource_t* res, celix_requirement_t* req);

Review Comment:
   Given that `celix_resource_addRequirement` and `celix_resource_addCapability` I think it is better that the calls destroy the added object if an error occurs. This should make the error handling for users a bit easier. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #551: Add 1st part of the requirement-capability-model lib (celix)

Posted by "PengZheng (via GitHub)" <gi...@apache.org>.
PengZheng commented on code in PR #547:
URL: https://github.com/apache/celix/pull/547#discussion_r1188127839


##########
libs/rcm/include/celix_resource.h:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+#ifndef CELIX_CELIX_RESOURCE_H
+#define CELIX_CELIX_RESOURCE_H
+
+#include "celix_rcm_types.h"
+#include "celix_array_list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @file celix_resource.h
+* @brief The celix_resource_t is a resource in the RCM.
+*
+* A resource is a collection of capabilities and requirements.
+*
+* @thread_safety none
+*/
+
+/**
+ * @brief Creates a new resource.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @return A new resource.
+ * @retval NULL If the resource could not be created.
+ */
+celix_resource_t* celix_resource_create();
+
+/**
+ * @brief Destroys the resource.
+ * @param[in] resource The resource to destroy. Can be NULL.
+ */
+void celix_resource_destroy(celix_resource_t* resource);
+
+/**
+ * @brief Returns the capabilities of the resource.
+ *
+ * Will return all resource capabilities if the provided namespace is NULL.
+ *
+ * @param[in] res The resource.
+ * @param[in] ns The namespace of the capabilities. Can be NULL.
+ * @return The capabilities of the resource. Will be an empty list if the resource has no capabilities or
+ *         has no capabilities with the provided namespace.
+ */
+const celix_array_list_t* celix_resource_getCapabilities(const celix_resource_t* res, const char* ns);
+
+/**
+ * @brief Returns the requirements of the resource for the provided namespace.
+ *
+ * Will return all resource requirements if the provided namespace is NULL.
+ *
+ * @param[in] res The resource.
+ * @param[in] ns The namespace of the requirements. Can be NULL.
+ * @return The requirements of the resource. Will be an empty list if the resource has no requirements or
+ *         has no requirements with the provided namespace.
+ */
+const celix_array_list_t* celix_resource_getRequirements(const celix_resource_t* res, const char* ns);
+
+/**
+ * @brief Adds a capability to the resource.
+ *
+ * The capability resource must be the same as this resource or a CELIX_ILLEGAL_ARGUMENT error is returned.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] res The resource.
+ * @param[in] cap The capability to add.
+ * @return CELIX_SUCCESS if the capability was added successfully.
+ * @retval CELIX_ILLEGAL_ARGUMENT If the capability resource is not the same as this resource.
+ * @retval ENOMEM If there is not enough memory to add the capability.
+ */
+celix_status_t celix_resource_addCapability(celix_resource_t* res, celix_capability_t* cap);
+
+/**
+ * @brief Adds a requirement to the resource.
+ *
+ * In case of a error, an error message is added to celix_err.
+ *
+ * @param[in] res The resource.
+ * @param[in] req The requirement to add.
+ * @return CELIX_SUCCESS if the requirement was added successfully.
+ * @retval CELIX_ILLEGAL_ARGUMENT If the requirement resource is not the same as this resource.
+ * @retval ENOMEM If there is not enough memory to add the requirement.
+ */
+celix_status_t celix_resource_addRequirement(celix_resource_t* res, celix_requirement_t* req);

Review Comment:
   I agree if requirement/capability can not live without resource.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org