VirtualBox

Changeset 62258 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 14, 2016 3:22:54 PM (9 years ago)
Author:
vboxsync
Message:

Main/VirtualBoxClient: Turn into a proper COM/XPCOM singleton object. Destruction is currently pretty late and might be better handled differently, but it seems to work as intended.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxClientImpl.h

    r60765 r62258  
    3434{
    3535public:
    36     DECLARE_CLASSFACTORY()
     36    DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxClient)
    3737
    3838    // Do not use any ATL registry support.
  • trunk/src/VBox/Main/src-client/xpcom/module.cpp

    r56584 r62258  
    66
    77/*
    8  * Copyright (C) 2006-2015 Oracle Corporation
     8 * Copyright (C) 2006-2016 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6262 *  Suitable for IN-PROC components.
    6363 */
    64 class SessionClassFactory : public Session
     64class VirtualBoxClientClassFactory : public VirtualBoxClient
    6565{
    6666public:
    67     virtual ~SessionClassFactory() {
     67    virtual ~VirtualBoxClientClassFactory()
     68    {
    6869        FinalRelease();
    6970        instance = 0;
    7071    }
    71     static nsresult getInstance (Session **inst) {
     72    static nsresult GetInstance(VirtualBoxClient **inst)
     73    {
    7274        int rv = NS_OK;
    73         if (instance == 0) {
    74             instance = new SessionClassFactory();
     75        if (instance == 0)
     76        {
     77            instance = new VirtualBoxClientClassFactory();
    7578            if (instance) {
    7679                instance->AddRef(); // protect FinalConstruct()
     
    8992        return rv;
    9093    }
    91     static nsresult releaseInstance () {
     94    static nsresult FactoryDestructor()
     95    {
    9296        if (instance)
    9397            instance->Release();
     
    96100
    97101private:
    98     static Session *instance;
     102    static VirtualBoxClient *instance;
    99103};
    100104
    101 /** @note this is for singleton; disabled for now */
    102 //
    103 //Session *SessionClassFactory::instance = 0;
    104 //
    105 //NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC (
    106 //    Session, SessionClassFactory::getInstance
    107 //)
     105VirtualBoxClient *VirtualBoxClientClassFactory::instance = nsnull;
     106
    108107
    109108NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC(Session)
    110109
    111 NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC(VirtualBoxClient)
     110NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC(VirtualBoxClient, VirtualBoxClientClassFactory::GetInstance)
    112111
    113112/**
     
    123122        NULL, // registration function
    124123        NULL, // deregistration function
    125 /** @note this is for singleton; disabled for now */
    126 //        SessionClassFactory::releaseInstance,
    127124        NULL, // destructor function
    128125        NS_CI_INTERFACE_GETTER_NAME(SessionWrap), // interfaces function
     
    136133        NULL, // registration function
    137134        NULL, // deregistration function
    138         NULL, // destructor function
     135        VirtualBoxClientClassFactory::FactoryDestructor, // destructor function
    139136        NS_CI_INTERFACE_GETTER_NAME(VirtualBoxClientWrap), // interfaces function
    140137        NULL, // language helper
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette