[libcamera-devel,RFC,3/6] qcam: Remove using namespace in header files
diff mbox series

Message ID 20211005073114.3997303-4-hiroh@chromium.org
State Accepted
Headers show
Series
  • Remove using namespace in header files
Related show

Commit Message

Hirokazu Honda Oct. 5, 2021, 7:31 a.m. UTC
"using namespace" in a header file propagates the namespace to
the files including the header file. So it should be avoided.
This removes "using namespace" in header files in qcam.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/qcam/dng_writer.h  | 10 ++++------
 src/qcam/main.cpp      |  2 +-
 src/qcam/main_window.h | 40 ++++++++++++++++++++--------------------
 3 files changed, 25 insertions(+), 27 deletions(-)

Comments

Laurent Pinchart Oct. 5, 2021, 9:42 a.m. UTC | #1
Hi Hiro,

Thank you for the patch.

On Tue, Oct 05, 2021 at 04:31:11PM +0900, Hirokazu Honda wrote:
> "using namespace" in a header file propagates the namespace to
> the files including the header file. So it should be avoided.
> This removes "using namespace" in header files in qcam.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> ---
>  src/qcam/dng_writer.h  | 10 ++++------
>  src/qcam/main.cpp      |  2 +-
>  src/qcam/main_window.h | 40 ++++++++++++++++++++--------------------
>  3 files changed, 25 insertions(+), 27 deletions(-)
> 
> diff --git a/src/qcam/dng_writer.h b/src/qcam/dng_writer.h
> index 20905f37..e4486288 100644
> --- a/src/qcam/dng_writer.h
> +++ b/src/qcam/dng_writer.h
> @@ -15,15 +15,13 @@
>  #include <libcamera/framebuffer.h>
>  #include <libcamera/stream.h>
>  
> -using namespace libcamera;
> -
>  class DNGWriter
>  {
>  public:
> -	static int write(const char *filename, const Camera *camera,
> -			 const StreamConfiguration &config,
> -			 const ControlList &metadata,
> -			 const FrameBuffer *buffer, const void *data);
> +	static int write(const char *filename, const libcamera::Camera *camera,
> +			 const libcamera::StreamConfiguration &config,
> +			 const libcamera::ControlList &metadata,
> +			 const libcamera::FrameBuffer *buffer, const void *data);
>  };
>  
>  #endif /* HAVE_TIFF */
> diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
> index 5eff90a3..b5dbf81b 100644
> --- a/src/qcam/main.cpp
> +++ b/src/qcam/main.cpp
> @@ -66,7 +66,7 @@ int main(int argc, char **argv)
>  	sa.sa_handler = &signalHandler;
>  	sigaction(SIGINT, &sa, nullptr);
>  
> -	CameraManager *cm = new CameraManager();
> +	libcamera::CameraManager *cm = new libcamera::CameraManager();

I would have added a 'using namespace libcamera' in this file. It's not
a big deal as there's a single libcamera function being used here, but
it would be more consistent.

I can fix this when applying if desired.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  	ret = cm->start();
>  	if (ret) {
> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
> index a16bea09..4d8e806b 100644
> --- a/src/qcam/main_window.h
> +++ b/src/qcam/main_window.h
> @@ -29,8 +29,6 @@
>  #include "../cam/stream_options.h"
>  #include "viewfinder.h"
>  
> -using namespace libcamera;
> -
>  class QAction;
>  class QComboBox;
>  
> @@ -50,7 +48,8 @@ class MainWindow : public QMainWindow
>  	Q_OBJECT
>  
>  public:
> -	MainWindow(CameraManager *cm, const OptionsParser::Options &options);
> +	MainWindow(libcamera::CameraManager *cm,
> +		   const OptionsParser::Options &options);
>  	~MainWindow();
>  
>  	bool event(QEvent *e) override;
> @@ -64,9 +63,10 @@ private Q_SLOTS:
>  
>  	void saveImageAs();
>  	void captureRaw();
> -	void processRaw(FrameBuffer *buffer, const ControlList &metadata);
> +	void processRaw(libcamera::FrameBuffer *buffer,
> +			const libcamera::ControlList &metadata);
>  
> -	void queueRequest(FrameBuffer *buffer);
> +	void queueRequest(libcamera::FrameBuffer *buffer);
>  
>  private:
>  	int createToolbars();
> @@ -77,13 +77,13 @@ private:
>  	int startCapture();
>  	void stopCapture();
>  
> -	void addCamera(std::shared_ptr<Camera> camera);
> -	void removeCamera(std::shared_ptr<Camera> camera);
> +	void addCamera(std::shared_ptr<libcamera::Camera> camera);
> +	void removeCamera(std::shared_ptr<libcamera::Camera> camera);
>  
> -	void requestComplete(Request *request);
> +	void requestComplete(libcamera::Request *request);
>  	void processCapture();
>  	void processHotplug(HotplugEvent *e);
> -	void processViewfinder(FrameBuffer *buffer);
> +	void processViewfinder(libcamera::FrameBuffer *buffer);
>  
>  	/* UI elements */
>  	QToolBar *toolbar_;
> @@ -102,21 +102,21 @@ private:
>  	const OptionsParser::Options &options_;
>  
>  	/* Camera manager, camera, configuration and buffers */
> -	CameraManager *cm_;
> -	std::shared_ptr<Camera> camera_;
> -	FrameBufferAllocator *allocator_;
> +	libcamera::CameraManager *cm_;
> +	std::shared_ptr<libcamera::Camera> camera_;
> +	libcamera::FrameBufferAllocator *allocator_;
>  
> -	std::unique_ptr<CameraConfiguration> config_;
> -	std::map<FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;
> +	std::unique_ptr<libcamera::CameraConfiguration> config_;
> +	std::map<libcamera::FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;
>  
>  	/* Capture state, buffers queue and statistics */
>  	bool isCapturing_;
>  	bool captureRaw_;
> -	Stream *vfStream_;
> -	Stream *rawStream_;
> -	std::map<const Stream *, QQueue<FrameBuffer *>> freeBuffers_;
> -	QQueue<Request *> doneQueue_;
> -	QQueue<Request *> freeQueue_;
> +	libcamera::Stream *vfStream_;
> +	libcamera::Stream *rawStream_;
> +	std::map<const libcamera::Stream *, QQueue<libcamera::FrameBuffer *>> freeBuffers_;
> +	QQueue<libcamera::Request *> doneQueue_;
> +	QQueue<libcamera::Request *> freeQueue_;
>  	QMutex mutex_; /* Protects freeBuffers_, doneQueue_, and freeQueue_ */
>  
>  	uint64_t lastBufferTime_;
> @@ -124,7 +124,7 @@ private:
>  	uint32_t previousFrames_;
>  	uint32_t framesCaptured_;
>  
> -	std::vector<std::unique_ptr<Request>> requests_;
> +	std::vector<std::unique_ptr<libcamera::Request>> requests_;
>  };
>  
>  #endif /* __QCAM_MAIN_WINDOW__ */
Hirokazu Honda Oct. 5, 2021, 10:25 a.m. UTC | #2
Hi Laurent,

On Tue, Oct 5, 2021 at 6:42 PM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Hiro,
>
> Thank you for the patch.
>
> On Tue, Oct 05, 2021 at 04:31:11PM +0900, Hirokazu Honda wrote:
> > "using namespace" in a header file propagates the namespace to
> > the files including the header file. So it should be avoided.
> > This removes "using namespace" in header files in qcam.
> >
> > Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> > ---
> >  src/qcam/dng_writer.h  | 10 ++++------
> >  src/qcam/main.cpp      |  2 +-
> >  src/qcam/main_window.h | 40 ++++++++++++++++++++--------------------
> >  3 files changed, 25 insertions(+), 27 deletions(-)
> >
> > diff --git a/src/qcam/dng_writer.h b/src/qcam/dng_writer.h
> > index 20905f37..e4486288 100644
> > --- a/src/qcam/dng_writer.h
> > +++ b/src/qcam/dng_writer.h
> > @@ -15,15 +15,13 @@
> >  #include <libcamera/framebuffer.h>
> >  #include <libcamera/stream.h>
> >
> > -using namespace libcamera;
> > -
> >  class DNGWriter
> >  {
> >  public:
> > -     static int write(const char *filename, const Camera *camera,
> > -                      const StreamConfiguration &config,
> > -                      const ControlList &metadata,
> > -                      const FrameBuffer *buffer, const void *data);
> > +     static int write(const char *filename, const libcamera::Camera *camera,
> > +                      const libcamera::StreamConfiguration &config,
> > +                      const libcamera::ControlList &metadata,
> > +                      const libcamera::FrameBuffer *buffer, const void *data);
> >  };
> >
> >  #endif /* HAVE_TIFF */
> > diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
> > index 5eff90a3..b5dbf81b 100644
> > --- a/src/qcam/main.cpp
> > +++ b/src/qcam/main.cpp
> > @@ -66,7 +66,7 @@ int main(int argc, char **argv)
> >       sa.sa_handler = &signalHandler;
> >       sigaction(SIGINT, &sa, nullptr);
> >
> > -     CameraManager *cm = new CameraManager();
> > +     libcamera::CameraManager *cm = new libcamera::CameraManager();
>
> I would have added a 'using namespace libcamera' in this file. It's not
> a big deal as there's a single libcamera function being used here, but
> it would be more consistent.
>
> I can fix this when applying if desired.
>

I am fine with it. Please feel free to do so if you prefer that.

-Hiro

> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> >
> >       ret = cm->start();
> >       if (ret) {
> > diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
> > index a16bea09..4d8e806b 100644
> > --- a/src/qcam/main_window.h
> > +++ b/src/qcam/main_window.h
> > @@ -29,8 +29,6 @@
> >  #include "../cam/stream_options.h"
> >  #include "viewfinder.h"
> >
> > -using namespace libcamera;
> > -
> >  class QAction;
> >  class QComboBox;
> >
> > @@ -50,7 +48,8 @@ class MainWindow : public QMainWindow
> >       Q_OBJECT
> >
> >  public:
> > -     MainWindow(CameraManager *cm, const OptionsParser::Options &options);
> > +     MainWindow(libcamera::CameraManager *cm,
> > +                const OptionsParser::Options &options);
> >       ~MainWindow();
> >
> >       bool event(QEvent *e) override;
> > @@ -64,9 +63,10 @@ private Q_SLOTS:
> >
> >       void saveImageAs();
> >       void captureRaw();
> > -     void processRaw(FrameBuffer *buffer, const ControlList &metadata);
> > +     void processRaw(libcamera::FrameBuffer *buffer,
> > +                     const libcamera::ControlList &metadata);
> >
> > -     void queueRequest(FrameBuffer *buffer);
> > +     void queueRequest(libcamera::FrameBuffer *buffer);
> >
> >  private:
> >       int createToolbars();
> > @@ -77,13 +77,13 @@ private:
> >       int startCapture();
> >       void stopCapture();
> >
> > -     void addCamera(std::shared_ptr<Camera> camera);
> > -     void removeCamera(std::shared_ptr<Camera> camera);
> > +     void addCamera(std::shared_ptr<libcamera::Camera> camera);
> > +     void removeCamera(std::shared_ptr<libcamera::Camera> camera);
> >
> > -     void requestComplete(Request *request);
> > +     void requestComplete(libcamera::Request *request);
> >       void processCapture();
> >       void processHotplug(HotplugEvent *e);
> > -     void processViewfinder(FrameBuffer *buffer);
> > +     void processViewfinder(libcamera::FrameBuffer *buffer);
> >
> >       /* UI elements */
> >       QToolBar *toolbar_;
> > @@ -102,21 +102,21 @@ private:
> >       const OptionsParser::Options &options_;
> >
> >       /* Camera manager, camera, configuration and buffers */
> > -     CameraManager *cm_;
> > -     std::shared_ptr<Camera> camera_;
> > -     FrameBufferAllocator *allocator_;
> > +     libcamera::CameraManager *cm_;
> > +     std::shared_ptr<libcamera::Camera> camera_;
> > +     libcamera::FrameBufferAllocator *allocator_;
> >
> > -     std::unique_ptr<CameraConfiguration> config_;
> > -     std::map<FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;
> > +     std::unique_ptr<libcamera::CameraConfiguration> config_;
> > +     std::map<libcamera::FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;
> >
> >       /* Capture state, buffers queue and statistics */
> >       bool isCapturing_;
> >       bool captureRaw_;
> > -     Stream *vfStream_;
> > -     Stream *rawStream_;
> > -     std::map<const Stream *, QQueue<FrameBuffer *>> freeBuffers_;
> > -     QQueue<Request *> doneQueue_;
> > -     QQueue<Request *> freeQueue_;
> > +     libcamera::Stream *vfStream_;
> > +     libcamera::Stream *rawStream_;
> > +     std::map<const libcamera::Stream *, QQueue<libcamera::FrameBuffer *>> freeBuffers_;
> > +     QQueue<libcamera::Request *> doneQueue_;
> > +     QQueue<libcamera::Request *> freeQueue_;
> >       QMutex mutex_; /* Protects freeBuffers_, doneQueue_, and freeQueue_ */
> >
> >       uint64_t lastBufferTime_;
> > @@ -124,7 +124,7 @@ private:
> >       uint32_t previousFrames_;
> >       uint32_t framesCaptured_;
> >
> > -     std::vector<std::unique_ptr<Request>> requests_;
> > +     std::vector<std::unique_ptr<libcamera::Request>> requests_;
> >  };
> >
> >  #endif /* __QCAM_MAIN_WINDOW__ */
>
> --
> Regards,
>
> Laurent Pinchart

Patch
diff mbox series

diff --git a/src/qcam/dng_writer.h b/src/qcam/dng_writer.h
index 20905f37..e4486288 100644
--- a/src/qcam/dng_writer.h
+++ b/src/qcam/dng_writer.h
@@ -15,15 +15,13 @@ 
 #include <libcamera/framebuffer.h>
 #include <libcamera/stream.h>
 
-using namespace libcamera;
-
 class DNGWriter
 {
 public:
-	static int write(const char *filename, const Camera *camera,
-			 const StreamConfiguration &config,
-			 const ControlList &metadata,
-			 const FrameBuffer *buffer, const void *data);
+	static int write(const char *filename, const libcamera::Camera *camera,
+			 const libcamera::StreamConfiguration &config,
+			 const libcamera::ControlList &metadata,
+			 const libcamera::FrameBuffer *buffer, const void *data);
 };
 
 #endif /* HAVE_TIFF */
diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
index 5eff90a3..b5dbf81b 100644
--- a/src/qcam/main.cpp
+++ b/src/qcam/main.cpp
@@ -66,7 +66,7 @@  int main(int argc, char **argv)
 	sa.sa_handler = &signalHandler;
 	sigaction(SIGINT, &sa, nullptr);
 
-	CameraManager *cm = new CameraManager();
+	libcamera::CameraManager *cm = new libcamera::CameraManager();
 
 	ret = cm->start();
 	if (ret) {
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index a16bea09..4d8e806b 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -29,8 +29,6 @@ 
 #include "../cam/stream_options.h"
 #include "viewfinder.h"
 
-using namespace libcamera;
-
 class QAction;
 class QComboBox;
 
@@ -50,7 +48,8 @@  class MainWindow : public QMainWindow
 	Q_OBJECT
 
 public:
-	MainWindow(CameraManager *cm, const OptionsParser::Options &options);
+	MainWindow(libcamera::CameraManager *cm,
+		   const OptionsParser::Options &options);
 	~MainWindow();
 
 	bool event(QEvent *e) override;
@@ -64,9 +63,10 @@  private Q_SLOTS:
 
 	void saveImageAs();
 	void captureRaw();
-	void processRaw(FrameBuffer *buffer, const ControlList &metadata);
+	void processRaw(libcamera::FrameBuffer *buffer,
+			const libcamera::ControlList &metadata);
 
-	void queueRequest(FrameBuffer *buffer);
+	void queueRequest(libcamera::FrameBuffer *buffer);
 
 private:
 	int createToolbars();
@@ -77,13 +77,13 @@  private:
 	int startCapture();
 	void stopCapture();
 
-	void addCamera(std::shared_ptr<Camera> camera);
-	void removeCamera(std::shared_ptr<Camera> camera);
+	void addCamera(std::shared_ptr<libcamera::Camera> camera);
+	void removeCamera(std::shared_ptr<libcamera::Camera> camera);
 
-	void requestComplete(Request *request);
+	void requestComplete(libcamera::Request *request);
 	void processCapture();
 	void processHotplug(HotplugEvent *e);
-	void processViewfinder(FrameBuffer *buffer);
+	void processViewfinder(libcamera::FrameBuffer *buffer);
 
 	/* UI elements */
 	QToolBar *toolbar_;
@@ -102,21 +102,21 @@  private:
 	const OptionsParser::Options &options_;
 
 	/* Camera manager, camera, configuration and buffers */
-	CameraManager *cm_;
-	std::shared_ptr<Camera> camera_;
-	FrameBufferAllocator *allocator_;
+	libcamera::CameraManager *cm_;
+	std::shared_ptr<libcamera::Camera> camera_;
+	libcamera::FrameBufferAllocator *allocator_;
 
-	std::unique_ptr<CameraConfiguration> config_;
-	std::map<FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;
+	std::unique_ptr<libcamera::CameraConfiguration> config_;
+	std::map<libcamera::FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;
 
 	/* Capture state, buffers queue and statistics */
 	bool isCapturing_;
 	bool captureRaw_;
-	Stream *vfStream_;
-	Stream *rawStream_;
-	std::map<const Stream *, QQueue<FrameBuffer *>> freeBuffers_;
-	QQueue<Request *> doneQueue_;
-	QQueue<Request *> freeQueue_;
+	libcamera::Stream *vfStream_;
+	libcamera::Stream *rawStream_;
+	std::map<const libcamera::Stream *, QQueue<libcamera::FrameBuffer *>> freeBuffers_;
+	QQueue<libcamera::Request *> doneQueue_;
+	QQueue<libcamera::Request *> freeQueue_;
 	QMutex mutex_; /* Protects freeBuffers_, doneQueue_, and freeQueue_ */
 
 	uint64_t lastBufferTime_;
@@ -124,7 +124,7 @@  private:
 	uint32_t previousFrames_;
 	uint32_t framesCaptured_;
 
-	std::vector<std::unique_ptr<Request>> requests_;
+	std::vector<std::unique_ptr<libcamera::Request>> requests_;
 };
 
 #endif /* __QCAM_MAIN_WINDOW__ */