VirtualBox

Changeset 17712 in vbox


Ignore:
Timestamp:
Mar 11, 2009 5:13:57 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
44224
Message:

Cbinding: Updated the VBoxXPCOMC.cpp so that only one function
namely VBoxGetXPCOMCFunctions(VBOX_XPCOMC_VERSION) is exported
and rest are accessed through a function table. Updated the
respective example as well.

Location:
trunk/src/VBox/Main/cbinding
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/cbinding/VBoxXPCOMC.cpp

    r17304 r17712  
    4040static nsIComponentManager *manager;
    4141
    42 VBOXXPCOMC_DECL(int)
     42void VBoxComUninitialize(void);
     43
     44int
    4345VBoxUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString)
    4446{
     
    4648}
    4749
    48 VBOXXPCOMC_DECL(int)
     50int
    4951VBoxUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString)
    5052{
     
    5254}
    5355
    54 VBOXXPCOMC_DECL(void)
     56void
    5557VBoxUtf16Free(PRUnichar *pwszString)
    5658{
     
    5860}
    5961
    60 VBOXXPCOMC_DECL(void)
     62void
    6163VBoxUtf8Free(char *pszString)
    6264{
     
    6466}
    6567
    66 VBOXXPCOMC_DECL(void)
     68void
    6769VBoxComUnallocMem(void *ptr)
    6870{
     
    7375}
    7476
    75 VBOXXPCOMC_DECL(int)
     77int
    7678VBoxSetEnv(const char *pszVar, const char *pszValue)
    7779{
     
    7981}
    8082
    81 VBOXXPCOMC_DECL(const char *)
     83const char *
    8284VBoxGetEnv(const char *pszVar)
    8385{
     
    8587}
    8688
    87 VBOXXPCOMC_DECL(void)
     89void
    8890VBoxComInitialize(IVirtualBox **virtualBox, ISession **session)
    8991{
     
    139141}
    140142
    141 VBOXXPCOMC_DECL(void)
     143void
    142144VBoxComUninitialize(void)
    143145{
  • trunk/src/VBox/Main/cbinding/tstLinuxC.c

    r17304 r17712  
    2727#include <sys/stat.h>
    2828#include "VirtualBox_CXPCOM.h"
     29
     30PCVBOXXPCOM g_pVBoxFuncs = NULL;
    2931
    3032static char *nsIDToString(nsID *guid);
     
    114116
    115117            machine->vtbl->GetName(machine, &machineNameUtf16);
    116             VBoxUtf16ToUtf8(machineNameUtf16,&machineName);
     118            g_pVBoxFuncs->pfnUtf16ToUtf8(machineNameUtf16,&machineName);
    117119            printf("\tName:        %s\n", machineName);
    118120
    119             VBoxUtf8Free(machineName);
    120             VBoxComUnallocMem(machineNameUtf16);
     121            g_pVBoxFuncs->pfnUtf8Free(machineName);
     122            g_pVBoxFuncs->pfnComUnallocMem(machineNameUtf16);
    121123        }
    122124        else
     
    135137
    136138            free(uuidString);
    137             VBoxComUnallocMem(iid);
     139            g_pVBoxFuncs->pfnComUnallocMem(iid);
    138140        }
    139141
     
    145147
    146148                machine->vtbl->GetSettingsFilePath(machine, &configFile);
    147                 VBoxUtf16ToUtf8(configFile, &configFile1);
     149                g_pVBoxFuncs->pfnUtf16ToUtf8(configFile, &configFile1);
    148150                printf("\tConfig file: %s\n", configFile1);
    149151
    150152                free(configFile1);
    151                 VBoxComUnallocMem(configFile);
     153                g_pVBoxFuncs->pfnComUnallocMem(configFile);
    152154            }
    153155
     
    168170                virtualBox->vtbl->GetGuestOSType(virtualBox, typeId, &osType);
    169171                osType->vtbl->GetDescription(osType, &osNameUtf16);
    170                 VBoxUtf16ToUtf8(osNameUtf16,&osName);
     172                g_pVBoxFuncs->pfnUtf16ToUtf8(osNameUtf16,&osName);
    171173                printf("\tGuest OS:    %s\n\n", osName);
    172174
    173175                osType->vtbl->nsisupports.Release((void *)osType);
    174                 VBoxUtf8Free(osName);
    175                 VBoxComUnallocMem(osNameUtf16);
    176                 VBoxComUnallocMem(typeId);
     176                g_pVBoxFuncs->pfnUtf8Free(osName);
     177                g_pVBoxFuncs->pfnComUnallocMem(osNameUtf16);
     178                g_pVBoxFuncs->pfnComUnallocMem(typeId);
    177179            }
    178180        }
     
    198200            startVM(virtualBox, session, iid);
    199201
    200             VBoxComUnallocMem(iid);
     202            g_pVBoxFuncs->pfnComUnallocMem(iid);
    201203        }
    202204    }
     
    240242    }
    241243
    242     VBoxUtf8ToUtf16("gui", &sessionType);
     244    g_pVBoxFuncs->pfnUtf8ToUtf16("gui", &sessionType);
    243245
    244246    rc = virtualBox->vtbl->OpenRemoteSession(
     
    251253    );
    252254
    253     VBoxUtf16Free(sessionType);
     255    g_pVBoxFuncs->pfnUtf16Free(sessionType);
    254256
    255257    if (NS_FAILED(rc))
     
    280282            progress->vtbl->GetErrorInfo(progress, &errorInfo);
    281283            errorInfo->vtbl->GetText(errorInfo, &textUtf16);
    282             VBoxUtf16ToUtf8(textUtf16, &text);
     284            g_pVBoxFuncs->pfnUtf16ToUtf8(textUtf16, &text);
    283285            printf("Error: %s\n", text);
    284286
    285             VBoxComUnallocMem(textUtf16);
    286             VBoxUtf8Free(text);
     287            g_pVBoxFuncs->pfnComUnallocMem(textUtf16);
     288            g_pVBoxFuncs->pfnUtf8Free(text);
    287289        }
    288290        else
     
    309311    nsresult    rc;     /* Result code of various function (method) calls. */
    310312
    311     /*
    312      * Guess where VirtualBox is installed not mentioned in the environment.
    313      * (This will be moved to VBoxComInitialize later.)
    314      */
    315 
    316     if (!VBoxGetEnv("VBOX_APP_HOME"))
     313    if (!getenv("VBOX_APP_HOME"))
    317314    {
    318315        if (stat("/opt/VirtualBox/VBoxXPCOMC.so", &stIgnored) == 0)
    319316        {
    320             VBoxSetEnv("VBOX_APP_HOME","/opt/VirtualBox/");
     317            setenv("VBOX_APP_HOME","/opt/VirtualBox/", 0 /* no need to overwrite */);
    321318        }
    322319        if (stat("/usr/lib/virtualbox/VBoxXPCOMC.so", &stIgnored) == 0)
    323320        {
    324             VBoxSetEnv("VBOX_APP_HOME","/usr/lib/virtualbox/");
     321            setenv("VBOX_APP_HOME","/usr/lib/virtualbox/", 0 /* no need to overwrite */);
    325322        }
    326323    }
     
    329326
    330327    /*
    331      * VBoxComInitialize does all the necessary startup action and
    332      * provides us with pointers to vbox and session handles.
    333      * It should be matched by a call to VBoxComUninitialize(vbox)
     328     * VBoxGetXPCOMCFunctions() is the only function exported by
     329     * VBoxXPCOMC.so. This functions gives you the pointer to the
     330     * function table (g_pVBoxFuncs).
     331     *
     332     * g_pVBoxFuncs->pfnComInitialize does all the necessary startup
     333     * action and provides us with pointers to vbox and session handles.
     334     * It should be matched by a call to g_pVBoxFuncs->pfnComUninitialize()
    334335     * when done.
    335336     */
    336337
    337     VBoxComInitialize(&vbox, &session);
     338    g_pVBoxFuncs = VBoxGetXPCOMCFunctions(VBOX_XPCOMC_VERSION);
     339    g_pVBoxFuncs->pfnComInitialize(&vbox, &session);
    338340
    339341    if (vbox == NULL)
     
    375377    {
    376378        char *version = NULL;
    377         VBoxUtf16ToUtf8(versionUtf16, &version);
     379        g_pVBoxFuncs->pfnUtf16ToUtf8(versionUtf16, &version);
    378380        printf("\tVersion: %s\n", version);
    379         VBoxUtf8Free(version);
    380         VBoxComUnallocMem(versionUtf16);
     381        g_pVBoxFuncs->pfnUtf8Free(version);
     382        g_pVBoxFuncs->pfnComUnallocMem(versionUtf16);
    381383    }
    382384    else
     
    392394    {
    393395        char *homefolder = NULL;
    394         VBoxUtf16ToUtf8(homefolderUtf16, &homefolder);
     396        g_pVBoxFuncs->pfnUtf16ToUtf8(homefolderUtf16, &homefolder);
    395397        printf("\tHomeFolder: %s\n", homefolder);
    396         VBoxUtf8Free(homefolder);
    397         VBoxComUnallocMem(homefolderUtf16);
     398        g_pVBoxFuncs->pfnUtf8Free(homefolder);
     399        g_pVBoxFuncs->pfnComUnallocMem(homefolderUtf16);
    398400    }
    399401    else
     
    412414     */
    413415
    414     VBoxComUninitialize();
     416    g_pVBoxFuncs->pfnComUninitialize();
    415417    printf("Finished Main\n");
    416418
  • trunk/src/VBox/Main/cbinding/xpcidl.xsl

    r17570 r17712  
    546546extern "C" {
    547547#endif
    548 
    549 /* Initialize/Uninitialize XPCOM. */
    550 VBOXXPCOMC_DECL(void) VBoxComInitialize(IVirtualBox **virtualBox, ISession **session);
    551 VBOXXPCOMC_DECL(void) VBoxComUninitialize(void);
    552 
    553 /* Deallocation functions. */
    554 VBOXXPCOMC_DECL(void) VBoxComUnallocMem(void *ptr);
    555 VBOXXPCOMC_DECL(void) VBoxUtf16Free(PRUnichar *pwszString);
    556 VBOXXPCOMC_DECL(void) VBoxUtf8Free(char *pszString);
    557 
    558 /* Converting to and from UTF-8 and UTF-16. */
    559 VBOXXPCOMC_DECL(int) VBoxUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString);
    560 VBOXXPCOMC_DECL(int) VBoxUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString);
    561 
    562 /* Getting and setting the environment variables. */
    563 VBOXXPCOMC_DECL(const char *) VBoxGetEnv(const char *pszVar);
    564 VBOXXPCOMC_DECL(int) VBoxSetEnv(const char *pszVar, const char *pszValue);
    565548
    566549
Note: See TracChangeset for help on using the changeset viewer.

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