this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreServices: Implement some missing Component APIs

+109 -21
+72 -19
src/frameworks/CoreServices/ComponentManager.cpp
··· 88 88 89 89 void ComponentManager::analyzeComponent(CFBundleRef bundle) 90 90 { 91 + ResFileRefNum resFile = resFileForBundle(bundle); 92 + analyzeComponent(bundle, resFile); 93 + CloseResFile(resFile); 94 + } 95 + 96 + OSStatus ComponentManager::resFileForComponent(Component c, ResFileRefNum* resFile) 97 + { 98 + std::unique_lock<std::recursive_mutex> l(m_componentsMutex); 99 + 100 + *resFile = kResFileNotOpened; 101 + 102 + auto itMap = m_componentsMap.find(c); 103 + if (itMap == m_componentsMap.end()) 104 + return invalidComponentID; 105 + 106 + ComponentData* cd = itMap->second; 107 + if (cd->bundlePath.empty()) 108 + return resFNotFound; // This is a dynamically registered component 109 + 110 + CFBundleRef bundle = bundleFromPath(cd->bundlePath.c_str()); 111 + if (!bundle) 112 + return resFNotFound; 113 + 114 + *resFile = resFileForBundle(bundle); 115 + CFRelease(bundle); 116 + 117 + if (*resFile == kResFileNotOpened) 118 + return resFNotFound; 119 + 120 + return noErr; 121 + } 122 + 123 + ResFileRefNum ComponentManager::resFileForBundle(CFBundleRef bundle) 124 + { 91 125 OSStatus status; 92 126 FSRef fsref; 93 - bool analyzed = false; 94 127 95 128 CFURLRef url = CFBundleCopyExecutableURL(bundle); 96 129 if (url != nullptr) ··· 111 144 112 145 if (status == noErr) 113 146 { 114 - analyzeComponent(bundle, resFile); 115 - CloseResFile(resFile); 116 - analyzed = true; 147 + CFRelease(filePath); 148 + CFRelease(url); 149 + return resFile; 117 150 } 118 151 } 119 152 120 153 CFRelease(filePath); 121 154 CFRelease(url); 122 155 } 123 - 124 - if (analyzed) 125 - return; 126 156 127 157 CFURLRef bundleUrl = CFBundleCopyBundleURL(bundle); 128 158 CFURLRef bundleUrlNoExt = CFURLCreateCopyDeletingPathExtension(nullptr, bundleUrl); ··· 152 182 153 183 if (status == noErr) 154 184 { 155 - analyzeComponent(bundle, resFile); 156 - CloseResFile(resFile); 185 + return resFile; 157 186 } 158 187 } 159 188 160 189 CFRelease(filePath); 161 190 CFRelease(url); 162 191 } 192 + 193 + return kResFileNotOpened; 163 194 } 164 195 165 196 #pragma pack(push, 1) ··· 444 475 #endif 445 476 } 446 477 478 + CFBundleRef ComponentManager::bundleFromPath(const char* path) 479 + { 480 + CFStringRef cfpath = CFStringCreateWithCString(nullptr, path, kCFStringEncodingUTF8); 481 + 482 + CFURLRef url = CFURLCreateWithFileSystemPath(nullptr, cfpath, kCFURLPOSIXPathStyle, true); 483 + CFRelease(cfpath); 484 + 485 + CFBundleRef bundle = CFBundleCreate(nullptr, url); 486 + CFRelease(url); 487 + 488 + return bundle; 489 + } 490 + 447 491 OSStatus ComponentManager::instantiate(Component c, ComponentInstance* out) 448 492 { 449 493 std::unique_lock<std::recursive_mutex> l(m_componentsMutex); ··· 458 502 459 503 if (!cd->entryPoint) 460 504 { 461 - CFStringRef cfpath = CFStringCreateWithCString(nullptr, cd->bundlePath.c_str(), kCFStringEncodingUTF8); 462 - 463 - CFURLRef url = CFURLCreateWithFileSystemPath(nullptr, cfpath, kCFURLPOSIXPathStyle, true); 464 - CFRelease(cfpath); 465 - 466 - CFBundleRef bundle = CFBundleCreate(nullptr, url); 467 - CFRelease(url); 505 + CFBundleRef bundle = bundleFromPath(cd->bundlePath.c_str()); 468 506 469 507 if (!bundle) 470 508 return invalidComponentID; ··· 514 552 515 553 OSStatus ComponentManager::dispose(ComponentInstance c) 516 554 { 517 - std::unique_lock<std::recursive_mutex> l(m_componentsMutex); 555 + std::unique_lock<std::recursive_mutex> l(m_componentInstancesMutex); 518 556 519 557 auto it = m_componentInstances.find(c); 520 558 if (it == m_componentInstances.end()) ··· 562 600 563 601 Handle ComponentManager::getStorage(ComponentInstance ci) 564 602 { 565 - std::unique_lock<std::recursive_mutex> l(m_componentsMutex); 603 + std::unique_lock<std::recursive_mutex> l(m_componentInstancesMutex); 566 604 567 605 auto it = m_componentInstances.find(ci); 568 606 if (it == m_componentInstances.end()) ··· 573 611 574 612 void ComponentManager::setStorage(ComponentInstance ci, Handle storage) 575 613 { 576 - std::unique_lock<std::recursive_mutex> l(m_componentsMutex); 614 + std::unique_lock<std::recursive_mutex> l(m_componentInstancesMutex); 577 615 578 616 auto it = m_componentInstances.find(ci); 579 617 if (it == m_componentInstances.end()) ··· 581 619 582 620 it->second.storage = storage; 583 621 } 622 + 623 + OSStatus ComponentManager::componentData(Component c, ComponentData* out) 624 + { 625 + std::unique_lock<std::recursive_mutex> l(m_componentsMutex); 626 + 627 + auto itMap = m_componentsMap.find(c); 628 + if (itMap == m_componentsMap.end()) 629 + return invalidComponentID; 630 + 631 + ComponentData* cd = itMap->second; 632 + 633 + *out = *cd; 634 + 635 + return noErr; 636 + }
+7 -1
src/frameworks/CoreServices/ComponentManager.h
··· 41 41 void discoverComponents(const char* dir); 42 42 void analyzeComponent(CFBundleRef bundle); 43 43 void analyzeComponent(CFBundleRef bundle, ResFileRefNum resFile); 44 + ResFileRefNum resFileForBundle(CFBundleRef bundle); 44 45 public: 45 46 static ComponentManager* instance(); 46 47 ··· 69 70 70 71 Handle getStorage(ComponentInstance ci); 71 72 void setStorage(ComponentInstance ci, Handle storage); 72 - private: 73 + 74 + static CFBundleRef bundleFromPath(const char* path); 75 + OSStatus resFileForComponent(Component c, ResFileRefNum* resFile); 76 + 73 77 struct ComponentData 74 78 { 75 79 Component component; ··· 84 88 uint32_t instances; 85 89 }; 86 90 91 + OSStatus componentData(Component c, ComponentData* out); 92 + private: 87 93 struct ComponentInstanceData 88 94 { 89 95 // instance of
+29 -1
src/frameworks/CoreServices/Components.cpp
··· 19 19 20 20 #include "Components.h" 21 21 #include <CoreServices/MacErrors.h> 22 + #include <CoreServices/MacMemory.h> 22 23 #include "ComponentManager.h" 23 24 24 25 Component FindNextComponent(Component prev, ComponentDescription* desc) ··· 94 95 95 96 OSErr OpenAComponentResFile(Component aComponent, ResFileRefNum* resRef) 96 97 { 97 - return kResFileNotOpened; 98 + return ComponentManager::instance()->resFileForComponent(aComponent, resRef); 99 + } 100 + 101 + static void stringToHandle(const std::string& str, Handle h) 102 + { 103 + SetHandleSize(h, str.length() + 1); 104 + Ptr p = *h; 105 + 106 + p[0] = str.length(); 107 + memcpy(p+1, str.c_str(), str.length()); 108 + } 109 + 110 + OSErr GetComponentInfo(Component aComponent, ComponentDescription *cd, 111 + Handle componentName, Handle componentInfo, Handle componentIcon) 112 + { 113 + ComponentManager::ComponentData cmd; 114 + OSStatus status; 115 + 116 + status = ComponentManager::instance()->componentData(aComponent, &cmd); 117 + if (status != noErr) 118 + return status; 119 + 120 + *cd = cmd.cd; 121 + stringToHandle(cmd.name, componentName); 122 + stringToHandle(cmd.info, componentInfo); 123 + EmptyHandle(componentIcon); 124 + 125 + return noErr; 98 126 }
+1
src/frameworks/CoreServices/include/CoreServices/Components.h
··· 151 151 void SetComponentInstanceStorage(ComponentInstance aComponentInstance, Handle theStorage); 152 152 153 153 OSErr OpenAComponentResFile(Component aComponent, ResFileRefNum* resRef); 154 + OSErr GetComponentInfo(Component aComponent, ComponentDescription *cd, Handle componentName, Handle componentInfo, Handle componentIcon); 154 155 155 156 #ifdef __cplusplus 156 157 }