You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/05/07 14:53:00 UTC

[plc4x] branch feature/c-api updated: - Streamilned the order and naming of the functions defined in the API module

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/c-api
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/c-api by this push:
     new 8eb6d89  - Streamilned the order and naming of the functions defined in the API module
8eb6d89 is described below

commit 8eb6d8989cb226c967f9ec0cd892d998ccf266ea
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu May 7 16:52:52 2020 +0200

    - Streamilned the order and naming of the functions defined in the API module
---
 sandbox/plc4c/api/include/plc4c/connection.h       | 36 +++++++---------
 sandbox/plc4c/api/include/plc4c/data.h             |  2 +-
 sandbox/plc4c/api/include/plc4c/read.h             | 48 +++++++++++-----------
 sandbox/plc4c/api/include/plc4c/system.h           | 20 +++++----
 sandbox/plc4c/api/include/plc4c/write.h            | 38 ++++++++---------
 .../plc4c/drivers/simulated/src/driver_simulated.c |  8 ++--
 .../plc4c/examples/hello-world/src/hello_world.c   | 21 ++++++----
 sandbox/plc4c/spi/src/connection.c                 | 16 ++++----
 sandbox/plc4c/spi/src/data.c                       |  2 +-
 sandbox/plc4c/spi/src/read.c                       |  4 +-
 sandbox/plc4c/spi/src/write.c                      |  6 +--
 11 files changed, 100 insertions(+), 101 deletions(-)

diff --git a/sandbox/plc4c/api/include/plc4c/connection.h b/sandbox/plc4c/api/include/plc4c/connection.h
index 85a43c3..97a6b6b 100644
--- a/sandbox/plc4c/api/include/plc4c/connection.h
+++ b/sandbox/plc4c/api/include/plc4c/connection.h
@@ -34,6 +34,12 @@ extern "C" {
 void plc4c_connection_initialize(plc4c_connection *connection);
 
 /**
+ * Destroy a previously created connection.
+ * @param connection
+ */
+void plc4c_connection_destroy(plc4c_connection *connection);
+
+/**
  * Returns the connection string for a given connection
  * @param connection plc4c_connection
  * @return connection string
@@ -115,7 +121,7 @@ void plc4c_connection_set_parameters(plc4c_connection *connection,
  * @param connection the connection.
  * @return true if the connection is established.
  */
-bool plc4c_connection_is_connected(plc4c_connection *connection);
+bool plc4c_connection_get_connected(plc4c_connection *connection);
 
 /**
  * Sets the connected status of a given connection
@@ -130,14 +136,14 @@ void plc4c_connection_set_connected(plc4c_connection *connection,
  * @param connection plc4c_connection
  * @return if the flag is set
  */
-bool plc4c_connection_disconnect_is_set(plc4c_connection *connection);
+bool plc4c_connection_get_disconnect(plc4c_connection *connection);
 
 /**
  * Sets the status of the disconnect flag for a given connection
  * @param connection plc4c_connection
  * @param disconnect the new flag status
  */
-void plc4c_connection_disconnect_set(plc4c_connection *connection,
+void plc4c_connection_set_disconnect(plc4c_connection *connection,
                                      bool disconnect);
 
 /**
@@ -172,24 +178,12 @@ bool plc4c_connection_has_error(plc4c_connection *connection);
 plc4c_return_code plc4c_connection_disconnect(plc4c_connection *connection);
 
 /**
- * Destrop a previously created connection.
- *
- * @param connection
- */
-void plc4c_connection_destroy(plc4c_connection *connection);
-
-/**
- * Get the connection string from a given connection.
- */
-char *plc4c_connection_get_connection_string(plc4c_connection *connection);
-
-/**
  * Check if the current connection supports read operations.
  *
  * @param connection reference to the connection
  * @return true if the connection supports reading, false otherwise
  */
-bool plc4c_connection_supports_reading(plc4c_connection *connection);
+bool plc4c_connection_get_supports_reading(plc4c_connection *connection);
 
 /**
  * Initializes an empty read-request.
@@ -208,7 +202,7 @@ plc4c_return_code plc4c_connection_create_read_request(
  * Destroys a given read_response
  * @param read_response the read_response
  */
-void plc4c_connection_read_response_destroy(plc4c_read_response *read_response);
+void plc4c_connection_destroy_read_response(plc4c_read_response *read_response);
 
 /**
  * Check if the current connection supports write operations.
@@ -216,7 +210,7 @@ void plc4c_connection_read_response_destroy(plc4c_read_response *read_response);
  * @param connection reference to the connection
  * @return true if the connection supports writing, false otherwise
  */
-bool plc4c_connection_supports_writing(plc4c_connection *connection);
+bool plc4c_connection_get_supports_writing(plc4c_connection *connection);
 
 /**
  * Initializes an empty write-request.
@@ -236,7 +230,7 @@ plc4c_return_code plc4c_connection_create_write_request(
  * Destroys a given write_response
  * @param write_response the write_response
  */
-void plc4c_connection_write_response_destroy(
+void plc4c_connection_destroy_write_response(
     plc4c_write_response *write_response);
 
 /**
@@ -245,14 +239,14 @@ void plc4c_connection_write_response_destroy(
  * @param connection reference to the connection
  * @return true if the connection supports subscriptions, false otherwise
  */
-bool plc4c_connection_supports_subscriptions(plc4c_connection *connection);
+bool plc4c_connection_get_supports_subscriptions(plc4c_connection *connection);
 
 /**
  * Returns the current number of running tasks for this connection
  * @param connection plc4c_connection
  * @return the count of running tasks
  */
-int plc4c_connection_running_tasks_count(plc4c_connection *connection);
+int plc4c_connection_get_running_tasks_count(plc4c_connection *connection);
 
 /**
  *
diff --git a/sandbox/plc4c/api/include/plc4c/data.h b/sandbox/plc4c/api/include/plc4c/data.h
index 8b408d4..d35e77f 100644
--- a/sandbox/plc4c/api/include/plc4c/data.h
+++ b/sandbox/plc4c/api/include/plc4c/data.h
@@ -145,7 +145,7 @@ void plc4c_data_printf(plc4c_data *data);
  * will handle the destruction of the data.
  * @param data pointer to plc4c_data
  */
-void plc4c_data_delete(plc4c_data *data);
+void plc4c_data_destroy(plc4c_data *data);
 
 #ifdef __cplusplus
 }
diff --git a/sandbox/plc4c/api/include/plc4c/read.h b/sandbox/plc4c/api/include/plc4c/read.h
index ba6d015..2c5b1db 100644
--- a/sandbox/plc4c/api/include/plc4c/read.h
+++ b/sandbox/plc4c/api/include/plc4c/read.h
@@ -25,6 +25,13 @@ extern "C" {
 #include "plc4c/types.h"
 
 /**
+ * Destroys a given read-request.
+ *
+ * @param read_request the read-request.
+ */
+void plc4c_read_request_destroy(plc4c_read_request *read_request);
+
+/**
  * Returns the plc4c_connection for a give read request
  * @param read_request plc4c_read_request
  * @return plc4c_connection
@@ -41,6 +48,15 @@ void plc4c_read_request_set_connection(plc4c_read_request *read_request,
                                        plc4c_connection *connection);
 
 /**
+ * Retrieve the read-response from a given read-request execution.
+ *
+ * @param read_request_execution the read-request execution.
+ * @return the read-response.
+ */
+plc4c_read_response *plc4c_read_request_get_response(
+    plc4c_read_request_execution *read_request_execution);
+
+/**
  * Actually executes the read-request.
  * @param connection connection this read-request will be executed on.
  * @param read_request the read-request object.
@@ -53,45 +69,29 @@ plc4c_return_code plc4c_read_request_execute(
     plc4c_read_request_execution **read_request_execution);
 
 /**
- * Check if the read-request is completed successfully.
- *
- * @param read_request_execution the read-request execution.
- * @return true if the read-request is completed successfully.
- */
-bool plc4c_read_request_finished_successfully(
-    plc4c_read_request_execution *read_request_execution);
-
-/**
- * Check if the read-request is completed unsuccessfully.
+ * Destroys a given read-request execution.
  *
  * @param read_request_execution the read-request execution.
- * @return true if the read-request is completed with an error.
  */
-bool plc4c_read_request_has_error(
+void plc4c_read_request_execution_destroy(
     plc4c_read_request_execution *read_request_execution);
 
 /**
- * Retrieve the read-response from a given read-request execution.
+ * Check if the read-request is completed successfully.
  *
  * @param read_request_execution the read-request execution.
- * @return the read-response.
+ * @return true if the read-request is completed successfully.
  */
-plc4c_read_response *plc4c_read_request_get_response(
+bool plc4c_read_request_execution_check_finished_successfully(
     plc4c_read_request_execution *read_request_execution);
 
 /**
- * Destroys a given read-request.
- *
- * @param read_request the read-request.
- */
-void plc4c_read_request_destroy(plc4c_read_request *read_request);
-
-/**
- * Destroys a given read-request execution.
+ * Check if the read-request is completed unsuccessfully.
  *
  * @param read_request_execution the read-request execution.
+ * @return true if the read-request is completed with an error.
  */
-void plc4c_read_request_execution_destroy(
+bool plc4c_read_request_execution_check_finished_with_error(
     plc4c_read_request_execution *read_request_execution);
 
 #ifdef __cplusplus
diff --git a/sandbox/plc4c/api/include/plc4c/system.h b/sandbox/plc4c/api/include/plc4c/system.h
index 79a501e..bfcaaba 100644
--- a/sandbox/plc4c/api/include/plc4c/system.h
+++ b/sandbox/plc4c/api/include/plc4c/system.h
@@ -119,6 +119,15 @@ typedef void (*plc4c_system_on_loop_failure_callback)(
 plc4c_return_code plc4c_system_create(plc4c_system **system);
 
 /**
+ * Function to initialize the PLC4C system (Initialize the driver manager and
+ * the list of enabled drivers)
+ *
+ * @param system
+ * @return plc4c_return_code
+ */
+plc4c_return_code plc4c_system_init(plc4c_system *system);
+
+/**
  * Function to destroy a plc4c_system.
  * This will also destroy all connections associated with the system.
  *
@@ -128,6 +137,7 @@ void plc4c_system_destroy(plc4c_system *system);
 
 /**
  * Returns the plc4c_list for tasks for a given system
+ * TODO: Possilby this should be an SPI function
  * @param system plc4c_system
  * @return plc4c_list
  */
@@ -135,6 +145,7 @@ plc4c_list *plc4c_system_get_task_list(plc4c_system *system);
 
 /**
  * Sets the plc4c_list for tasks for a given system
+ * TODO: Possilby this should be an SPI function
  * @param system plc4c_system
  * @param task_list plc4c_list
  */
@@ -231,15 +242,6 @@ plc4c_return_code plc4c_system_add_transport(plc4c_system *system,
                                              plc4c_transport *transport);
 
 /**
- * Function to initialize the PLC4C system (Initialize the driver manager and
- * the list of enabled drivers)
- *
- * @param system
- * @return plc4c_return_code
- */
-plc4c_return_code plc4c_system_init(plc4c_system *system);
-
-/**
  * Function to clean up the PLC4C system (Free any still used resources,
  * terminate live connections, ...)
  *
diff --git a/sandbox/plc4c/api/include/plc4c/write.h b/sandbox/plc4c/api/include/plc4c/write.h
index 5d23155..05c388d 100644
--- a/sandbox/plc4c/api/include/plc4c/write.h
+++ b/sandbox/plc4c/api/include/plc4c/write.h
@@ -25,6 +25,13 @@ extern "C" {
 #include "plc4c/types.h"
 
 /**
+ * Destroys a given write-request.
+ *
+ * @param write_request the write-request.
+ */
+void plc4c_write_request_destroy(plc4c_write_request *write_request);
+
+/**
  * Returns the plc4c_connection for a give write request
  * @param write_request plc4c_write_request
  * @return plc4c_connection
@@ -49,49 +56,42 @@ void plc4c_write_request_set_connection(plc4c_write_request *write_request,
  * @return plc4c_return_code
  */
 plc4c_return_code plc4c_write_request_execute(
-    plc4c_write_request *write_reques,
+    plc4c_write_request *write_request,
     plc4c_write_request_execution **write_request_execution);
 
 /**
- * Check if the write-request is completed successfully.
+ * Destroys a given write-request execution.
  *
  * @param write_request_execution the write-request execution.
- * @return true if the write-request is completed successfully.
  */
-bool plc4c_write_request_finished_successfully(
+void plc4c_write_request_execution_destroy(
     plc4c_write_request_execution *write_request_execution);
 
 /**
- * Check if the write-request is completed unsuccessfully.
+ * Check if the write-request is completed successfully.
  *
  * @param write_request_execution the write-request execution.
- * @return true if the write-request is completed with an error.
+ * @return true if the write-request is completed successfully.
  */
-bool plc4c_write_request_has_error(
+bool plc4c_write_request_check_finished_successfully(
     plc4c_write_request_execution *write_request_execution);
 
 /**
- * Retrieve the write-response from a given write-request execution.
+ * Check if the write-request is completed unsuccessfully.
  *
  * @param write_request_execution the write-request execution.
- * @return the write-response.
+ * @return true if the write-request is completed with an error.
  */
-plc4c_write_response *plc4c_write_request_get_response(
+bool plc4c_write_request_execution_check_completed_with_error(
     plc4c_write_request_execution *write_request_execution);
 
 /**
- * Destroys a given write-request.
- *
- * @param write_request the write-request.
- */
-void plc4c_write_request_destroy(plc4c_write_request *write_request);
-
-/**
- * Destroys a given write-request execution.
+ * Retrieve the write-response from a given write-request execution.
  *
  * @param write_request_execution the write-request execution.
+ * @return the write-response.
  */
-void plc4c_write_request_execution_destroy(
+plc4c_write_response *plc4c_write_request_execution_get_response(
     plc4c_write_request_execution *write_request_execution);
 
 #ifdef __cplusplus
diff --git a/sandbox/plc4c/drivers/simulated/src/driver_simulated.c b/sandbox/plc4c/drivers/simulated/src/driver_simulated.c
index 1255295..cd95577 100644
--- a/sandbox/plc4c/drivers/simulated/src/driver_simulated.c
+++ b/sandbox/plc4c/drivers/simulated/src/driver_simulated.c
@@ -62,7 +62,7 @@ plc4c_return_code plc4c_driver_simulated_connect_machine_function(
   if (connection == NULL) {
     return INTERNAL_ERROR;
   }
-  if (plc4c_connection_is_connected(connection)) {
+  if (plc4c_connection_get_connected(connection)) {
     return INTERNAL_ERROR;
   }
   plc4c_connection_set_connected(connection, true);
@@ -79,13 +79,13 @@ plc4c_return_code plc4c_driver_simulated_disconnect_machine_function(
 
   switch (task->state_id) {
     case PLC4C_DRIVER_SIMULATED_DISCONNECT_INIT: {
-      plc4c_connection_disconnect_set(connection, true);
+      plc4c_connection_set_disconnect(connection, true);
       task->state_id = PLC4C_DRIVER_SIMULATED_DISCONNECT_WAIT_TASKS_FINISHED;
       break;
     }
     case PLC4C_DRIVER_SIMULATED_DISCONNECT_WAIT_TASKS_FINISHED: {
       // The disconnect system-task also counts.
-      if (plc4c_connection_running_tasks_count(connection) == 1) {
+      if (plc4c_connection_get_running_tasks_count(connection) == 1) {
         plc4c_connection_set_connected(connection, false);
         task->completed = true;
         task->state_id = PLC4C_DRIVER_SIMULATED_DISCONNECT_FINISHED;
@@ -372,7 +372,7 @@ plc4c_return_code plc4c_driver_simulated_write_function(
 void free_read_response_item(plc4c_list_element *read_item_element) {
   plc4c_response_value_item *value_item =
       (plc4c_response_value_item *)read_item_element->value;
-  plc4c_data_delete(value_item->value);
+  plc4c_data_destroy(value_item->value);
   value_item->value = NULL;
 }
 
diff --git a/sandbox/plc4c/examples/hello-world/src/hello_world.c b/sandbox/plc4c/examples/hello-world/src/hello_world.c
index 68df39e..6e4f1f4 100644
--- a/sandbox/plc4c/examples/hello-world/src/hello_world.c
+++ b/sandbox/plc4c/examples/hello-world/src/hello_world.c
@@ -150,7 +150,7 @@ int main() {
     switch (state) {
       case CONNECTING: {
         // Check if the connection is established:
-        if (plc4c_connection_is_connected(connection)) {
+        if (plc4c_connection_get_connected(connection)) {
           printf("SUCCESS\n");
           state = CONNECTED;
         } else if (plc4c_connection_has_error(connection)) {
@@ -195,10 +195,12 @@ int main() {
       }
         // Wait until the read-request execution is finished.
       case READ_REQUEST_SENT: {
-        if (plc4c_read_request_finished_successfully(read_request_execution)) {
+        if (plc4c_read_request_execution_check_finished_successfully(
+                read_request_execution)) {
           printf("SUCCESS\n");
           state = READ_RESPONSE_RECEIVED;
-        } else if (plc4c_read_request_has_error(read_request_execution)) {
+        } else if (plc4c_read_request_execution_check_finished_with_error(
+                       read_request_execution)) {
           printf("FAILED\n");
           return -1;
         }
@@ -228,7 +230,7 @@ int main() {
         }
 
         // Clean up.
-        plc4c_connection_read_response_destroy(read_response);
+        plc4c_connection_destroy_read_response(read_response);
         plc4c_read_request_execution_destroy(read_request_execution);
         plc4c_read_request_destroy(read_request);
 
@@ -274,11 +276,12 @@ int main() {
       }
         // Wait until the write-request execution is finished.
       case WRITE_REQUEST_SENT: {
-        if (plc4c_write_request_finished_successfully(
+        if (plc4c_write_request_check_finished_successfully(
                 write_request_execution)) {
           printf("SUCCESS\n");
           state = WRITE_RESPONSE_RECEIVED;
-        } else if (plc4c_write_request_has_error(write_request_execution)) {
+        } else if (plc4c_write_request_execution_check_completed_with_error(
+                       write_request_execution)) {
           printf("FAILED\n");
           return -1;
         }
@@ -286,7 +289,7 @@ int main() {
       }
       case WRITE_RESPONSE_RECEIVED: {
         plc4c_write_response *write_response =
-            plc4c_write_request_get_response(write_request_execution);
+            plc4c_write_request_execution_get_response(write_request_execution);
 
         // Iterate over the responses ...
         plc4c_list_element *cur_element =
@@ -299,7 +302,7 @@ int main() {
         }
 
         // Clean up.
-        plc4c_connection_write_response_destroy(write_response);
+        plc4c_connection_destroy_write_response(write_response);
         plc4c_write_request_execution_destroy(write_request_execution);
 
         // Disconnect.
@@ -314,7 +317,7 @@ int main() {
       }
         // Wait until the connection is disconnected
       case DISCONNECTING: {
-        if (!plc4c_connection_is_connected(connection)) {
+        if (!plc4c_connection_get_connected(connection)) {
           printf("SUCCESS\n");
           // we could let the system shut this down,
           // or do it ourselves
diff --git a/sandbox/plc4c/spi/src/connection.c b/sandbox/plc4c/spi/src/connection.c
index 6e9795c..b83a092 100644
--- a/sandbox/plc4c/spi/src/connection.c
+++ b/sandbox/plc4c/spi/src/connection.c
@@ -109,7 +109,7 @@ void plc4c_connection_set_parameters(plc4c_connection *connection,
   }
 }
 
-bool plc4c_connection_is_connected(plc4c_connection *connection) {
+bool plc4c_connection_get_connected(plc4c_connection *connection) {
   return connection->connected;
 }
 
@@ -118,11 +118,11 @@ void plc4c_connection_set_connected(plc4c_connection *connection,
   connection->connected = connected;
 }
 
-bool plc4c_connection_disconnect_is_set(plc4c_connection *connection) {
+bool plc4c_connection_get_disconnect(plc4c_connection *connection) {
   return connection->disconnect;
 }
 
-void plc4c_connection_disconnect_set(plc4c_connection *connection,
+void plc4c_connection_set_disconnect(plc4c_connection *connection,
                                      bool disconnect) {
   connection->disconnect = disconnect;
 }
@@ -181,7 +181,7 @@ char *plc4c_connection_get_connection_string(plc4c_connection *connection) {
   return connection->connection_string;
 }
 
-bool plc4c_connection_supports_reading(plc4c_connection *connection) {
+bool plc4c_connection_get_supports_reading(plc4c_connection *connection) {
   return connection->supports_reading;
 }
 
@@ -210,13 +210,13 @@ plc4c_return_code plc4c_connection_create_read_request(
   return OK;
 }
 
-void plc4c_connection_read_response_destroy(
+void plc4c_connection_destroy_read_response(
     plc4c_read_response *read_response) {
   read_response->read_request->connection->driver->free_read_response_function(
       read_response);
 }
 
-bool plc4c_connection_supports_writing(plc4c_connection *connection) {
+bool plc4c_connection_get_supports_writing(plc4c_connection *connection) {
   return connection->supports_writing;
 }
 
@@ -267,13 +267,13 @@ plc4c_return_code plc4c_connection_create_write_request(
   return OK;
 }
 
-void plc4c_connection_write_response_destroy(
+void plc4c_connection_destroy_write_response(
     plc4c_write_response *write_response) {
   write_response->write_request->connection->driver
       ->free_write_response_function(write_response);
 }
 
-int plc4c_connection_running_tasks_count(plc4c_connection *connection) {
+int plc4c_connection_get_running_tasks_count(plc4c_connection *connection) {
   return connection->num_running_system_tasks;
 }
 
diff --git a/sandbox/plc4c/spi/src/data.c b/sandbox/plc4c/spi/src/data.c
index 88345f2..29cf208 100644
--- a/sandbox/plc4c/spi/src/data.c
+++ b/sandbox/plc4c/spi/src/data.c
@@ -144,7 +144,7 @@ void plc4c_data_set_custom_printf(plc4c_data *data,
   data->custom_printf = data_custom_printf;
 }
 
-void plc4c_data_delete(plc4c_data *data) {
+void plc4c_data_destroy(plc4c_data *data) {
   assert(data != NULL);
   if (data->custom_destroy != NULL) {
     data->custom_destroy(data);
diff --git a/sandbox/plc4c/spi/src/read.c b/sandbox/plc4c/spi/src/read.c
index 254027c..60580a6 100644
--- a/sandbox/plc4c/spi/src/read.c
+++ b/sandbox/plc4c/spi/src/read.c
@@ -57,7 +57,7 @@ plc4c_return_code plc4c_read_request_execute(
   return OK;
 }
 
-bool plc4c_read_request_finished_successfully(
+bool plc4c_read_request_execution_check_finished_successfully(
     plc4c_read_request_execution *read_request_execution) {
   if (read_request_execution == NULL) {
     return true;
@@ -68,7 +68,7 @@ bool plc4c_read_request_finished_successfully(
   return read_request_execution->system_task->completed;
 }
 
-bool plc4c_read_request_has_error(
+bool plc4c_read_request_execution_check_finished_with_error(
     plc4c_read_request_execution *read_request_execution) {
   return false;
 }
diff --git a/sandbox/plc4c/spi/src/write.c b/sandbox/plc4c/spi/src/write.c
index 5916ed0..83ab548 100644
--- a/sandbox/plc4c/spi/src/write.c
+++ b/sandbox/plc4c/spi/src/write.c
@@ -57,7 +57,7 @@ plc4c_return_code plc4c_write_request_execute(
   return OK;
 }
 
-bool plc4c_write_request_finished_successfully(
+bool plc4c_write_request_check_finished_successfully(
     plc4c_write_request_execution *write_request_execution) {
   if (write_request_execution == NULL) {
     return true;
@@ -68,12 +68,12 @@ bool plc4c_write_request_finished_successfully(
   return write_request_execution->system_task->completed;
 }
 
-bool plc4c_write_request_has_error(
+bool plc4c_write_request_execution_check_completed_with_error(
     plc4c_write_request_execution *write_request_execution) {
   return false;
 }
 
-plc4c_write_response *plc4c_write_request_get_response(
+plc4c_write_response *plc4c_write_request_execution_get_response(
     plc4c_write_request_execution *write_request_execution) {
   if (write_request_execution == NULL) {
     return NULL;