[haiku-commits] haiku: hrev47080 - src/servers/media

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 31 Mar 2014 18:03:47 +0200 (CEST)

hrev47080 adds 1 changeset to branch 'master'
old head: d71e18fef493548d46c5ae6213daa023b691ff98
new head: 48058f7bc949deaa10683b79e3ac90909c79c0e3
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=48058f7+%5Ed71e18f

----------------------------------------------------------------------------

48058f7: Media_server: use find_paths_etc.
  
  * Replace code to find the plug-ins with the new APIs.
  * Prepare for hybrid-aware code (but we need to use the app
      architecture, not the media_server one)

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev47080
Commit:      48058f7bc949deaa10683b79e3ac90909c79c0e3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=48058f7
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Mon Mar 31 15:39:35 2014 UTC

----------------------------------------------------------------------------

1 file changed, 37 insertions(+), 26 deletions(-)
src/servers/media/AddOnManager.cpp | 63 ++++++++++++++++++++--------------

----------------------------------------------------------------------------

diff --git a/src/servers/media/AddOnManager.cpp 
b/src/servers/media/AddOnManager.cpp
index fa7333b..fafe84a 100644
--- a/src/servers/media/AddOnManager.cpp
+++ b/src/servers/media/AddOnManager.cpp
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <Architecture.h>
 #include <Autolock.h>
 #include <Directory.h>
 #include <Entry.h>
@@ -57,14 +58,6 @@ private:
 };
 
 
-static const directory_which sDirectories[] = {
-       B_USER_NONPACKAGED_ADDONS_DIRECTORY,
-       B_USER_ADDONS_DIRECTORY,
-       B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
-       B_SYSTEM_ADDONS_DIRECTORY
-};
-
-
 //     #pragma mark -
 
 
@@ -125,14 +118,19 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref* 
_decoderRef,
        // of system add-ons by user add-ons, in case they offer decoders
        // for the same format.
 
+       char** directories = NULL;
+       size_t directoryCount = 0;
+
+       if (find_paths_etc(get_architecture(), B_FIND_PATH_ADD_ONS_DIRECTORY,
+                       "media/plugins", B_FIND_PATH_EXISTING_ONLY, 
&directories,
+                       &directoryCount) != B_OK) {
+               printf("AddOnManager::GetDecoderForFormat: failed to locate 
plugins\n");
+               return B_ENTRY_NOT_FOUND;
+       }
+
        BPath path;
-       for (uint i = 0; i < sizeof(sDirectories) / sizeof(directory_which); 
i++) {
-               if (find_directory(sDirectories[i], &path) != B_OK
-                       || path.Append("media/plugins") != B_OK) {
-                       printf("AddOnManager::GetDecoderForFormat: failed to 
construct "
-                               "path for directory %u\n", i);
-                       continue;
-               }
+       for (uint i = 0; i < directoryCount; i++) {
+               path.SetTo(directories[i]);
                if (_FindDecoder(format, path, _decoderRef))
                        return B_OK;
        }
@@ -151,14 +149,19 @@ AddOnManager::GetReaders(xfer_entry_ref* outRefs, int32* 
outCount,
 
        // See GetDecoderForFormat() for why we need to scan the list by path.
 
+       char** directories = NULL;
+       size_t directoryCount = 0;
+
+       if (find_paths_etc(get_architecture(), B_FIND_PATH_ADD_ONS_DIRECTORY,
+                       "media/plugins", B_FIND_PATH_EXISTING_ONLY, 
&directories,
+                       &directoryCount) != B_OK) {
+               printf("AddOnManager::GetReaders: failed to locate plugins\n");
+               return B_ENTRY_NOT_FOUND;
+       }
+
        BPath path;
-       for (uint i = 0; i < sizeof(sDirectories) / sizeof(directory_which); 
i++) {
-               if (find_directory(sDirectories[i], &path) != B_OK
-                       || path.Append("media/plugins") != B_OK) {
-                       printf("AddOnManager::GetReaders: failed to construct "
-                               "path for directory %u\n", i);
-                       continue;
-               }
+       for (uint i = 0; i < directoryCount; i++) {
+               path.SetTo(directories[i]);
                _GetReaders(path, outRefs, outCount, maxCount);
        }
        
@@ -302,16 +305,24 @@ AddOnManager::_RegisterAddOns()
                        || !strcasecmp(buffer, "enabled")
                        || !strcmp(buffer, "1"));
 
+       char** directories = NULL;
+       size_t directoryCount = 0;
+
+       if (find_paths_etc(get_architecture(), B_FIND_PATH_ADD_ONS_DIRECTORY,
+                       "media/plugins", B_FIND_PATH_EXISTING_ONLY, 
&directories,
+                       &directoryCount) != B_OK) {
+               printf("AddOnManager::RegisterAddOns: failed to locate 
plugins\n");
+               return;
+       }
+
        node_ref nref;
        BDirectory directory;
        BPath path;
-       for (uint i = 0; i < sizeof(sDirectories) / sizeof(directory_which); 
i++) {
+       for (uint i = 0; i < directoryCount; i++) {
                if (disableUserAddOns && i <= 1)
                        continue;
 
-               if (find_directory(sDirectories[i], &path) == B_OK
-                       && path.Append("media/plugins") == B_OK
-                       && directory.SetTo(path.Path()) == B_OK
+               if (directory.SetTo(directories[i]) == B_OK
                        && directory.GetNodeRef(&nref) == B_OK) {
                        fAddOnMonitorHandler->AddDirectory(&nref);
                                // NOTE: This may already start registering 
add-ons in the


Other related posts: