Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path resolution based on OpenNI2.dll directory (plus xnOSGetDirName() fix) #7

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

tomoto
Copy link
Collaborator

@tomoto tomoto commented Jan 7, 2013

Hi OpenNI folks,

Here is a patch to address the issue I pointed out in the community at https://community.openni.org/openni/topics/search_path_for_redist_files. With this patch, the path for the drivers and OpenNI.ini will be resolved based on OpenNI2.dll's directory so that the users are no longer required to launch the application from the designated directory. It also allows them to use the shared driver repository just by setting PATH environment variable to its master OpenNI2.dll.

This patch includes three commits as follows. All the details are explained in their commit comments.

  • Commit 1: Fix of an issue of Windows version of xnOSGetDirName(). Even if you did not agree on the path resolution fix, I believe you would like to merge this bug fix.
  • Commit 2: Fix of the path resolution, which is the main part of this contribution. There are some features that I personally believe no longer needed (or possibly even confusing) but left untouched.
  • Commit 3: Patch to remove the features I personally believe no longer needed. You can exclude this commit if you do not agree on my suggestion explained in the commit comment.

I hope this patch to be reviewed (and accommodated if you agree) as early as possible since this is an external behavior change that may impact on the beta users although it is (I believe) a significant improvement.

Please get back to me if you have any questions.
Thank you very much,
Tomoto

Problem:
- Windows version of xnOSGetDirName() returns the directory name followed by a directory separator, which was (seemingly) different from Linux version's behavior. This difference could be a problem when you tried to write a portable code.

Solution:
- Windows version of xnOSGetDirName() now returns the directory name without the directory separator, which should be the same as Linux version.
- Another helper functions, xnOSStripDirSep() and xnOSIsDirSep(), are introduced to implement this in a clean and portable way.

Description of changes:
- XnWin32Files.cpp: Added a code to strip the directory separator in xnOSGetDirName().
- XnOS.h: Utility functions to handle the directory separators are added (xnOSStripDirSep, xnOSIsDirSep)
- XnLibWin32.h, XnOSLinux-x86.h: String constant XN_FILE_DIR_SEPS is added to support both "\" and "/" in Windows. This is helpful for the application programmers to write a portable code by consistently using "/" in any platforms.

Note for Linux: Tested on Windows only.
Fix 1: Drivers' path is now resolved based on OpenNI2.dll's directory.

Problem:
- The drivers' path ("OpenNI2/Drivers" by default) is resolved based on the current directory, which could be a problem because it would restrict the application to be runnable only in a specific directory. See the OpenNI community at https://community.openni.org/openni/topics/search_path_for_redist_files where I originally pointed out this issue.

Solution:
- Now the drivers' path is resolved based on OpenNI2.dll's directory. By default, <OpenNI2.dll's directory>/OpenNI2/Drivers is used. If the custom path is specified by OpenNI.ini (by Repository property in Drivers section), it will be resolved based on OpenNI2.dll's directory if it is relative, or used as it is when it is absolute.
- To specify the custom path, the application can use "/" as the separater even in Windows so that the application can use the same OpenNI.ini regardless of the platform.
- The path resolution by the environment variable (OPENNI2_DRIVERS_PATH) is kept untouched to preserve the current behavior, but I would suggest removing it because it could be no longer useful but might break the consistency between the DLL and the drivers.

Description of changes:
- OniContext.cpp: The drivers' path is resolved based on OpenNI2.dll's directory instead of using the string constant.
- XnOS.h, XnWin32SharedLibrary.cpp, XnLinuxSharedLibs.cpp: Function to get the DLL's path is added (xnOSGetModulePathForProcAddress). See "Note for Linux" also.
- XnOS.h, XnFiles.cpp, XnWin32Files.cpp, XnLinuxFiles.cpp: Utility functions to handle file paths are added (xnOSAppendFilePath, xnOSIsAbsoluteFilePath). See "Note for Linux" also.
- Config/OpenNI.ini: Comment is added to explain how to specify the drivers' path in detail.

Note for Linux:
- This fix has not been compiled or tested on Linux, but intended not to break anything existing at least.
- xnOSGetModulePathForProcAddress() in XnLinuxSharedLibs.cpp needs to be implemented. It should be easily done by using dladdr(). For now, it has the dummy implementation that should not break existing behavior.
- xnOSIsAbsoluteFilePath() in XnLinuxFiles.cpp is implemented but not tested.

Fix 2: OpenNI.ini is now read from OpenNI2.dll's directory.

Problem:
- OpenNI.ini is read from the current directory, which could be a problem by the same reason as Fix 1.

Solution:
- Now OpenNI.ini is read from the same directory as OpenNI2.dll.
- If there is OpenNI.ini in the current directory, it overrides OpenNI.ini in OpenNI2.dll's directory. This feature is kept to preserve the current behavior, but I would suggest removing it because the application's behavior should be independent from the current directory unless the application itself was so designed.

Description of changes:
- OniContext.cpp: OpenNI.ini's path is resolved based on OpenNI2.dll's directory instead of using the string constant.

Fix 3: Improvement of the log configuration timing.

Problem:
- Some logs are not outputted because the log configuration in OpenNI.ini is read too late.

Solution:
- Complete log configuration before any log outputs as long as possible.

Description of changes:
- OniContext.cpp: The order of log configuration and log output was slightly exchanged.
As described in the previous commit, resolving the driver path based on environment variable (OPENNI2_DRIVERS_PATH) and reading OpenNI.ini from the current directory could be only confusing if we started to resolve it based on OpenNI2.dll's directory. If you agree, please use this commit to remove these features. It will make the behavior and the code much simpler and more explainable.
@tomoto
Copy link
Collaborator Author

tomoto commented Jan 7, 2013

I may add another commit if I can apply the same method for PS1080.ini. Thanks.

Problem:
- PS1080.ini is read from the current directory, which could be a problem because (1) it would restrict the application to be runnable only in a designated directory and (2) the current directory would be messed up by these driver dependent files. See the OpenNI community at https://community.openni.org/openni/topics/search_path_for_redist_files where I originally pointed out this issue.

Solution:
- Now PS1080.ini is read from the same location as PS1080.dll.

Description of changes:
- XnSensor.cpp:  ResolveGlobalConfigFileName() is modified to resolve the config file's path based on the DLL's directory when the strConfigDir is specified as NULL, and now XnSensor's constructor uses it to initialize m_strGlobalConfigFile.
- XnSensor.h: Comment is added for ResolveGlobalConfigFileName().
- Config/PS1080.ini: Moved to Config/OpenNI2/Drivers/PS1080.ini.

Note:
- Please test the installer (Redist.py) if it deploys PS1080.ini as intended, i.e. along with PS1080.dll.
@tomoto
Copy link
Collaborator Author

tomoto commented Jan 7, 2013

I have done the work for PS1080.ini and committed. Thanks.

@tomoto tomoto mentioned this pull request Jan 7, 2013
@tomoto
Copy link
Collaborator Author

tomoto commented Jan 8, 2013

Benn (piedar) found my code did not compile with gcc (on Linux). We are working on it at tomoto#1.

- OniContext.cpp, XnSensor.cpp: Cast is applied to function pointer to avoid gcc compilation errors. (Thanks to Benn for contribution)
- XnLinuxSharedLibs.cpp: xnOSGetModulePathForProcAddress() is implemented. xnOSLoadLibrary() is also fixed to let dladdr() return the desired information.
@tomoto
Copy link
Collaborator Author

tomoto commented Jan 8, 2013

I decided to build my own Linux environment to investigate the problems reported by Benn, and eventually completed the working implementation! My quick testing confirmed the paths were resolved based on the lib*.so's. Please see the commit 86efc7a.

@piedar
Copy link

piedar commented Jan 8, 2013

This path resolution branch is working nicely for me on Gentoo Linux x86_64.

@tomoto
Copy link
Collaborator Author

tomoto commented Jan 8, 2013

Hi Benn,

Thank you very much for your contribution to find the issue and validate the fix! I really appreciate it!

Tomoto

@ghost ghost assigned tomoto Jan 15, 2013
tomoto added a commit that referenced this pull request Jan 15, 2013
@tomoto
Copy link
Collaborator Author

tomoto commented Jan 15, 2013

I merged this pull request into the develop branch after the peer review by Eddie.

@kubat
Copy link

kubat commented Mar 23, 2013

This was merged in, but then immediately overwritten by the following commit. Was this intentional or an accident?

@piedar
Copy link

piedar commented Apr 4, 2013

When I asked the same thing, I was told it was an accident. But I think this ended up getting stranded in the develop branch. I wonder what the plan is for merging from there to master...

@tomoto
Copy link
Collaborator Author

tomoto commented Apr 5, 2013

I think piedar is right. The patch 4eec88b was immediately overwritten by b8aae20 by mistake, and then recovered by 743fbda but it is still only in the development branch. I hope it will be merged into the master in the merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants