Changeset 5504 in vbox
- Timestamp:
- Oct 25, 2007 1:02:05 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 25696
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/server.cpp
r5101 r5504 21 21 #include <nsIComponentRegistrar.h> 22 22 23 #if defined(XPCOM_GLUE) 23 24 #include <nsXPCOMGlue.h> 25 #endif 26 24 27 #include <nsEventQueueUtils.h> 25 26 // for nsMyFactory 27 #include <nsIGenericFactory.h> 28 #include <nsIClassInfo.h> 28 #include <nsGenericFactory.h> 29 29 30 30 #include "linux/server.h" … … 570 570 /** 571 571 * Enhanced module component information structure. 572 * nsModuleComponentInfo lacks the factory construction callback, 573 * here we add it. This callback is called by NS_NewMyFactory() after 574 * a nsMyFactory instance is successfully created. 572 * 573 * nsModuleComponentInfo lacks the factory construction callback, here we add 574 * it. This callback is called by NS_NewGenericFactoryEx() after a 575 * nsGenericFactory instance is successfully created. 575 576 */ 576 struct nsM yModuleComponentInfo: nsModuleComponentInfo577 struct nsModuleComponentInfoEx : nsModuleComponentInfo 577 578 { 578 nsM yModuleComponentInfo() {}579 nsM yModuleComponentInfo(int) {}580 581 nsM yModuleComponentInfo(579 nsModuleComponentInfoEx () {} 580 nsModuleComponentInfoEx (int) {} 581 582 nsModuleComponentInfoEx ( 582 583 const char* aDescription, 583 584 const nsCID& aCID, … … 613 614 //////////////////////////////////////////////////////////////////////////////// 614 615 615 static const nsM yModuleComponentInfocomponents[] =616 static const nsModuleComponentInfoEx components[] = 616 617 { 617 nsM yModuleComponentInfo(618 nsModuleComponentInfoEx ( 618 619 "VirtualBox component", 619 620 (nsCID) NS_VIRTUALBOX_CID, … … 634 635 635 636 /** 636 * Generic component factory. 637 * 638 * The code below is stolen from nsGenericFactory.h / nsGenericFactory.cpp, 639 * because we get a segmentation fault for some unknown reason when VBoxSVC 640 * starts up (somewhere during the initialization of the libipcdc.so module) 641 * when we just reference XPCOM's NS_NewGenericFactory() from here (i.e. even 642 * before actually calling it) and run VBoxSVC using the debug XPCOM 643 * libraries. 644 * 645 * Actually, I know why, but I find it too stupid even to discuss. 646 */ 647 class nsMyFactory : public nsIGenericFactory, public nsIClassInfo { 648 public: 649 NS_DEFINE_STATIC_CID_ACCESSOR(NS_GENERICFACTORY_CID); 650 651 nsMyFactory(const nsModuleComponentInfo *info = NULL); 652 653 NS_DECL_ISUPPORTS 654 NS_DECL_NSICLASSINFO 655 656 /* nsIGenericFactory methods */ 657 NS_IMETHOD SetComponentInfo(const nsModuleComponentInfo *info); 658 NS_IMETHOD GetComponentInfo(const nsModuleComponentInfo **infop); 659 660 NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult); 661 662 NS_IMETHOD LockFactory(PRBool aLock); 663 664 static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); 665 private: 666 ~nsMyFactory(); 667 668 const nsModuleComponentInfo *mInfo; 669 }; 670 671 nsMyFactory::nsMyFactory(const nsModuleComponentInfo *info) 672 : mInfo(info) 673 { 674 if (mInfo && mInfo->mClassInfoGlobal) 675 *mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this); 676 } 677 678 nsMyFactory::~nsMyFactory() 679 { 680 if (mInfo) { 681 if (mInfo->mFactoryDestructor) 682 mInfo->mFactoryDestructor(); 683 if (mInfo->mClassInfoGlobal) 684 *mInfo->mClassInfoGlobal = 0; 685 } 686 } 687 688 NS_IMPL_THREADSAFE_ISUPPORTS3(nsMyFactory, 689 nsIGenericFactory, 690 nsIFactory, 691 nsIClassInfo) 692 693 NS_IMETHODIMP nsMyFactory::CreateInstance(nsISupports *aOuter, 694 REFNSIID aIID, void **aResult) 695 { 696 if (mInfo->mConstructor) 697 return mInfo->mConstructor(aOuter, aIID, aResult); 698 699 return NS_ERROR_FACTORY_NOT_REGISTERED; 700 } 701 702 NS_IMETHODIMP nsMyFactory::LockFactory(PRBool aLock) 703 { 704 // XXX do we care if (mInfo->mFlags & THREADSAFE)? 705 return NS_OK; 706 } 707 708 NS_IMETHODIMP nsMyFactory::GetInterfaces(PRUint32 *countp, 709 nsIID* **array) 710 { 711 if (!mInfo->mGetInterfacesProc) { 712 *countp = 0; 713 *array = nsnull; 714 return NS_OK; 715 } 716 return mInfo->mGetInterfacesProc(countp, array); 717 } 718 719 NS_IMETHODIMP nsMyFactory::GetHelperForLanguage(PRUint32 language, 720 nsISupports **helper) 721 { 722 if (mInfo->mGetLanguageHelperProc) 723 return mInfo->mGetLanguageHelperProc(language, helper); 724 *helper = nsnull; 725 return NS_OK; 726 } 727 728 NS_IMETHODIMP nsMyFactory::GetContractID(char **aContractID) 729 { 730 if (mInfo->mContractID) { 731 *aContractID = (char *)nsMemory::Alloc(strlen(mInfo->mContractID) + 1); 732 if (!*aContractID) 733 return NS_ERROR_OUT_OF_MEMORY; 734 strcpy(*aContractID, mInfo->mContractID); 735 } else { 736 *aContractID = nsnull; 737 } 738 return NS_OK; 739 } 740 741 NS_IMETHODIMP nsMyFactory::GetClassDescription(char * *aClassDescription) 742 { 743 if (mInfo->mDescription) { 744 *aClassDescription = (char *) 745 nsMemory::Alloc(strlen(mInfo->mDescription) + 1); 746 if (!*aClassDescription) 747 return NS_ERROR_OUT_OF_MEMORY; 748 strcpy(*aClassDescription, mInfo->mDescription); 749 } else { 750 *aClassDescription = nsnull; 751 } 752 return NS_OK; 753 } 754 755 NS_IMETHODIMP nsMyFactory::GetClassID(nsCID * *aClassID) 756 { 757 *aClassID = 758 NS_REINTERPRET_CAST(nsCID*, 759 nsMemory::Clone(&mInfo->mCID, sizeof mInfo->mCID)); 760 if (! *aClassID) 761 return NS_ERROR_OUT_OF_MEMORY; 762 return NS_OK; 763 } 764 765 NS_IMETHODIMP nsMyFactory::GetClassIDNoAlloc(nsCID *aClassID) 766 { 767 *aClassID = mInfo->mCID; 768 return NS_OK; 769 } 770 771 NS_IMETHODIMP nsMyFactory::GetImplementationLanguage(PRUint32 *langp) 772 { 773 *langp = nsIProgrammingLanguage::CPLUSPLUS; 774 return NS_OK; 775 } 776 777 NS_IMETHODIMP nsMyFactory::GetFlags(PRUint32 *flagsp) 778 { 779 *flagsp = mInfo->mFlags; 780 return NS_OK; 781 } 782 783 // nsIGenericFactory: component-info accessors 784 NS_IMETHODIMP nsMyFactory::SetComponentInfo(const nsModuleComponentInfo *info) 785 { 786 if (mInfo && mInfo->mClassInfoGlobal) 787 *mInfo->mClassInfoGlobal = 0; 788 mInfo = info; 789 if (mInfo && mInfo->mClassInfoGlobal) 790 *mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this); 791 return NS_OK; 792 } 793 794 NS_IMETHODIMP nsMyFactory::GetComponentInfo(const nsModuleComponentInfo **infop) 795 { 796 *infop = mInfo; 797 return NS_OK; 798 } 799 800 NS_METHOD nsMyFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) 801 { 802 // sorry, aggregation not spoken here. 803 nsresult res = NS_ERROR_NO_AGGREGATION; 804 if (outer == NULL) { 805 nsMyFactory* factory = new nsMyFactory; 806 if (factory != NULL) { 807 res = factory->QueryInterface(aIID, aInstancePtr); 808 if (res != NS_OK) 809 delete factory; 810 } else { 811 res = NS_ERROR_OUT_OF_MEMORY; 812 } 813 } 814 return res; 815 } 816 817 /** 818 * Instantiates a new factory and calls 819 * nsMyModuleComponentInfo::mFactoryConstructor. 637 * Extends NS_NewGenericFactory() by immediately calling 638 * nsModuleComponentInfoEx::mFactoryConstructor before returning to the 639 * caller. 820 640 */ 821 641 nsresult 822 NS_New MyFactory(nsIGenericFactory**result,823 const nsMyModuleComponentInfo*info)642 NS_NewGenericFactoryEx (nsIGenericFactory **result, 643 const nsModuleComponentInfoEx *info) 824 644 { 825 nsresult rv; 826 nsMyFactory* fact; 827 rv = nsMyFactory::Create(NULL, NS_GET_IID(nsIGenericFactory), (void**)&fact); 828 if (NS_FAILED(rv)) return rv; 829 rv = fact->SetComponentInfo(info); 830 if (NS_FAILED(rv)) goto error; 831 if (info && info->mFactoryConstructor) { 645 AssertReturn (result, NS_ERROR_INVALID_POINTER); 646 647 nsresult rv = NS_NewGenericFactory (result, info); 648 if (NS_SUCCEEDED (rv) && info && info->mFactoryConstructor) 649 { 832 650 rv = info->mFactoryConstructor(); 833 if (NS_FAILED(rv)) goto error; 834 } 835 *result = fact; 836 return rv; 837 838 error: 839 NS_RELEASE(fact); 651 if (NS_FAILED (rv)) 652 NS_RELEASE (*result); 653 } 654 840 655 return rv; 841 656 } … … 849 664 static nsresult 850 665 RegisterSelfComponents (nsIComponentRegistrar *registrar, 851 const nsM yModuleComponentInfo*components,666 const nsModuleComponentInfoEx *components, 852 667 PRUint32 count) 853 668 { 854 669 nsresult rc = NS_OK; 855 const nsM yModuleComponentInfo*info = components;670 const nsModuleComponentInfoEx *info = components; 856 671 for (PRUint32 i = 0; i < count && NS_SUCCEEDED (rc); i++, info++) 857 672 { … … 860 675 /* create a new generic factory for a component and register it */ 861 676 nsIGenericFactory *factory; 862 rc = NS_NewGenericFactory (&factory, info); 863 rc = NS_NewMyFactory (&factory, info); 677 rc = NS_NewGenericFactoryEx (&factory, info); 864 678 if (NS_SUCCEEDED (rc)) 865 679 {
Note:
See TracChangeset
for help on using the changeset viewer.