[libcamera-devel,2/5] libcamera: ipa_manager: Split path handling

Message ID 20200205130420.8736-3-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • Support loading IPAs from the build tree
Related show

Commit Message

Kieran Bingham Feb. 5, 2020, 1:04 p.m. UTC
Move the iteration of a colon separated path to it's own function.
This prepares for parsing extra path variables.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/include/ipa_manager.h |  1 +
 src/libcamera/ipa_manager.cpp       | 52 +++++++++++++++++++----------
 2 files changed, 36 insertions(+), 17 deletions(-)

Comments

Laurent Pinchart Feb. 6, 2020, 7:23 p.m. UTC | #1
Hi Kieran,

Thank you for the path.

On Wed, Feb 05, 2020 at 01:04:17PM +0000, Kieran Bingham wrote:
> Move the iteration of a colon separated path to it's own function.

s/colon separated/colon-separated/
s/it's/its/

> This prepares for parsing extra path variables.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/libcamera/include/ipa_manager.h |  1 +
>  src/libcamera/ipa_manager.cpp       | 52 +++++++++++++++++++----------
>  2 files changed, 36 insertions(+), 17 deletions(-)
> 
> diff --git a/src/libcamera/include/ipa_manager.h b/src/libcamera/include/ipa_manager.h
> index 126f8babbc8f..94d35d9062e4 100644
> --- a/src/libcamera/include/ipa_manager.h
> +++ b/src/libcamera/include/ipa_manager.h
> @@ -33,6 +33,7 @@ private:
>  	~IPAManager();
>  
>  	int addDir(const char *libDir);
> +	int addPath(const char *path);

There's a mismatch between the parameter name here and below.

>  };
>  
>  } /* namespace libcamera */
> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
> index 92adc6c45015..048465c37772 100644
> --- a/src/libcamera/ipa_manager.cpp
> +++ b/src/libcamera/ipa_manager.cpp
> @@ -110,23 +110,7 @@ IPAManager::IPAManager()
>  		return;
>  	}
>  
> -	const char *paths = modulePaths;
> -	while (1) {
> -		const char *delim = strchrnul(paths, ':');
> -		size_t count = delim - paths;
> -
> -		if (count) {
> -			std::string path(paths, count);
> -			ret = addDir(path.c_str());
> -			if (ret > 0)
> -				ipaCount += ret;
> -		}
> -
> -		if (*delim == '\0')
> -			break;
> -
> -		paths += count + 1;
> -	}
> +	ipaCount += addPath(modulePaths);
>  
>  	if (!ipaCount)
>  		LOG(IPAManager, Warning)
> @@ -206,6 +190,40 @@ int IPAManager::addDir(const char *libDir)
>  	return count;
>  }
>  
> +/**
> + * \brief Load IPA modules from a colon separated PATH variable

s/colon separated/colon-separated/ ?

> + * \param[in] path string to split to search for IPA modules

s/string/String/

To be consistent with the way PATH is documented, we could replace the
brief with

 * \brief Load IPA modules from a search path

and document this parameter as

 * \param[in] path The colon-separated list of directories to load IPA modules from


> + *
> + * This method tries to create an IPAModule instance for every shared object
> + * found in the directories described by \a paths.

s/described by/listed in/ ?

> + *
> + * \return Number of modules loaded by this call, or a negative error code
> + * otherwise
> + */
> +int IPAManager::addPath(const char *paths)

Let's be consistent. addPath and path, or addPaths and paths ? I'd go
for the former, and rename the local path variable to dir below. The
\param[in] should also match.

> +{
> +	int ipaCount = 0;
> +
> +	while (1) {
> +		const char *delim = strchrnul(paths, ':');
> +		size_t count = delim - paths;
> +
> +		if (count) {
> +			std::string path(paths, count);
> +			int ret = addDir(path.c_str());
> +			if (ret > 0)
> +				ipaCount += ret;
> +		}
> +
> +		if (*delim == '\0')
> +			break;
> +
> +		paths += count + 1;
> +	}
> +
> +	return ipaCount;
> +}
> +
>  /**
>   * \brief Create an IPA interface that matches a given pipeline handler
>   * \param[in] pipe The pipeline handler that wants a matching IPA interface

Patch

diff --git a/src/libcamera/include/ipa_manager.h b/src/libcamera/include/ipa_manager.h
index 126f8babbc8f..94d35d9062e4 100644
--- a/src/libcamera/include/ipa_manager.h
+++ b/src/libcamera/include/ipa_manager.h
@@ -33,6 +33,7 @@  private:
 	~IPAManager();
 
 	int addDir(const char *libDir);
+	int addPath(const char *path);
 };
 
 } /* namespace libcamera */
diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
index 92adc6c45015..048465c37772 100644
--- a/src/libcamera/ipa_manager.cpp
+++ b/src/libcamera/ipa_manager.cpp
@@ -110,23 +110,7 @@  IPAManager::IPAManager()
 		return;
 	}
 
-	const char *paths = modulePaths;
-	while (1) {
-		const char *delim = strchrnul(paths, ':');
-		size_t count = delim - paths;
-
-		if (count) {
-			std::string path(paths, count);
-			ret = addDir(path.c_str());
-			if (ret > 0)
-				ipaCount += ret;
-		}
-
-		if (*delim == '\0')
-			break;
-
-		paths += count + 1;
-	}
+	ipaCount += addPath(modulePaths);
 
 	if (!ipaCount)
 		LOG(IPAManager, Warning)
@@ -206,6 +190,40 @@  int IPAManager::addDir(const char *libDir)
 	return count;
 }
 
+/**
+ * \brief Load IPA modules from a colon separated PATH variable
+ * \param[in] path string to split to search for IPA modules
+ *
+ * This method tries to create an IPAModule instance for every shared object
+ * found in the directories described by \a paths.
+ *
+ * \return Number of modules loaded by this call, or a negative error code
+ * otherwise
+ */
+int IPAManager::addPath(const char *paths)
+{
+	int ipaCount = 0;
+
+	while (1) {
+		const char *delim = strchrnul(paths, ':');
+		size_t count = delim - paths;
+
+		if (count) {
+			std::string path(paths, count);
+			int ret = addDir(path.c_str());
+			if (ret > 0)
+				ipaCount += ret;
+		}
+
+		if (*delim == '\0')
+			break;
+
+		paths += count + 1;
+	}
+
+	return ipaCount;
+}
+
 /**
  * \brief Create an IPA interface that matches a given pipeline handler
  * \param[in] pipe The pipeline handler that wants a matching IPA interface