Changeset 2976 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Jun 1, 2007 1:47:51 PM (18 years ago)
- Location:
- trunk/src/VBox/Main/glue
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/com.cpp
r2754 r2976 23 23 #include <objbase.h> 24 24 25 #else 25 #else /* !defined (VBOX_WITH_XPCOM) */ 26 26 27 27 #include <stdlib.h> 28 #include <VBox/err.h>29 #include <iprt/path.h>30 28 31 #include <nsXPCOMGlue.h>32 #include <nsIComponentRegistrar.h>33 #include <nsIServiceManager.h>34 29 #include <nsCOMPtr.h> 35 #include <ns EventQueueUtils.h>30 #include <nsIServiceManagerUtils.h> 36 31 37 32 #include <nsIInterfaceInfo.h> 38 33 #include <nsIInterfaceInfoManager.h> 39 34 40 #endif 35 #endif /* !defined (VBOX_WITH_XPCOM) */ 41 36 37 #include <iprt/param.h> 38 #include <iprt/path.h> 39 #include <iprt/dir.h> 40 #include <iprt/env.h> 42 41 #include <iprt/string.h> 42 43 43 #include <VBox/err.h> 44 44 45 45 #include "VBox/com/com.h" 46 46 #include "VBox/com/assert.h" 47 48 49 #ifdef __DARWIN__ 50 #define VBOX_USER_HOME_SUFFIX "Library/VirtualBox" 51 #else 52 #define VBOX_USER_HOME_SUFFIX ".VirtualBox" 53 #endif 54 47 55 48 56 namespace com … … 95 103 } 96 104 97 #else 105 #else /* !defined (VBOX_WITH_XPCOM) */ 98 106 99 107 nsresult rv; … … 122 130 } 123 131 124 #endif 132 #endif /* !defined (VBOX_WITH_XPCOM) */ 133 } 134 135 int GetVBoxUserHomeDirectory (Utf8Str &aDir) 136 { 137 /* start with null */ 138 aDir.setNull(); 139 140 const char *VBoxUserHome = RTEnvGet ("VBOX_USER_HOME"); 141 142 char path [RTPATH_MAX]; 143 int vrc = VINF_SUCCESS; 144 145 if (VBoxUserHome) 146 { 147 /* get the full path name */ 148 char *VBoxUserHomeUtf8 = NULL; 149 vrc = RTStrCurrentCPToUtf8 (&VBoxUserHomeUtf8, VBoxUserHome); 150 if (RT_SUCCESS (vrc)) 151 { 152 vrc = RTPathAbs (VBoxUserHomeUtf8, path, sizeof (path)); 153 if (RT_SUCCESS (vrc)) 154 aDir = path; 155 RTStrFree (VBoxUserHomeUtf8); 156 } 157 } 158 else 159 { 160 /* compose the config directory (full path) */ 161 vrc = RTPathUserHome (path, sizeof (path)); 162 aDir = Utf8StrFmt ("%s%c%s", path, RTPATH_DELIMITER, 163 VBOX_USER_HOME_SUFFIX); 164 } 165 166 /* ensure the home directory exists */ 167 if (RT_SUCCESS (vrc)) 168 if (!RTDirExists (aDir)) 169 vrc = RTDirCreateFullPath (aDir, 0777); 170 171 return vrc; 125 172 } 126 173 -
trunk/src/VBox/Main/glue/initterm.cpp
r2754 r2976 23 23 #include <objbase.h> 24 24 25 #else 25 #else /* !defined (VBOX_WITH_XPCOM) */ 26 26 27 27 #include <stdlib.h> 28 #include <VBox/err.h>29 #include <iprt/path.h>30 28 31 29 #include <nsXPCOMGlue.h> … … 34 32 #include <nsCOMPtr.h> 35 33 #include <nsEventQueueUtils.h> 36 37 #include <nsIInterfaceInfo.h> 38 #include <nsIInterfaceInfoManager.h> 39 40 #endif 41 34 #include <nsEmbedString.h> 35 36 #include <nsILocalFile.h> 37 #include <nsIDirectoryService.h> 38 #include <nsDirectoryServiceDefs.h> 39 40 #endif /* !defined (VBOX_WITH_XPCOM) */ 41 42 #include <iprt/param.h> 43 #include <iprt/path.h> 42 44 #include <iprt/string.h> 45 #include <iprt/env.h> 46 43 47 #include <VBox/err.h> 44 48 … … 46 50 #include "VBox/com/assert.h" 47 51 52 48 53 namespace com 49 54 { 55 56 #if defined (VBOX_WITH_XPCOM) 57 58 class DirectoryServiceProvider : public nsIDirectoryServiceProvider 59 { 60 public: 61 62 NS_DECL_ISUPPORTS 63 64 DirectoryServiceProvider() 65 : mCompRegLocation (NULL), mXPTIDatLocation (NULL) 66 {} 67 68 virtual ~DirectoryServiceProvider(); 69 70 HRESULT init (const char *aCompRegLocation, 71 const char *aXPTIDatLocation); 72 73 NS_DECL_NSIDIRECTORYSERVICEPROVIDER 74 75 private: 76 77 char *mCompRegLocation; 78 char *mXPTIDatLocation; 79 }; 80 81 NS_IMPL_ISUPPORTS1 (DirectoryServiceProvider, nsIDirectoryServiceProvider) 82 83 DirectoryServiceProvider::~DirectoryServiceProvider() 84 { 85 if (mCompRegLocation) 86 { 87 RTStrFree (mCompRegLocation); 88 mCompRegLocation = NULL; 89 } 90 if (mXPTIDatLocation) 91 { 92 RTStrFree (mXPTIDatLocation); 93 mXPTIDatLocation = NULL; 94 } 95 } 96 97 /** 98 * @param aCompRegLocation Path to compreg.dat, in Utf8. 99 * @param aXPTIDatLocation Path to xpti.data, in Utf8. 100 */ 101 HRESULT 102 DirectoryServiceProvider::init (const char *aCompRegLocation, 103 const char *aXPTIDatLocation) 104 { 105 AssertReturn (aCompRegLocation, NS_ERROR_INVALID_ARG); 106 AssertReturn (aXPTIDatLocation, NS_ERROR_INVALID_ARG); 107 108 int vrc = RTStrUtf8ToCurrentCP (&mCompRegLocation, aCompRegLocation); 109 if (RT_SUCCESS (vrc)) 110 vrc = RTStrUtf8ToCurrentCP (&mXPTIDatLocation, aXPTIDatLocation); 111 112 return RT_SUCCESS (vrc) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; 113 } 114 115 NS_IMETHODIMP 116 DirectoryServiceProvider::GetFile (const char *aProp, 117 PRBool *aPersistent, 118 nsIFile **aRetval) 119 { 120 nsCOMPtr <nsILocalFile> localFile; 121 nsresult rv = NS_ERROR_FAILURE; 122 123 *aRetval = nsnull; 124 *aPersistent = PR_TRUE; 125 126 const char *fileLocation = NULL; 127 128 if (strcmp (aProp, NS_XPCOM_COMPONENT_REGISTRY_FILE) == 0) 129 fileLocation = mCompRegLocation; 130 else if (strcmp (aProp, NS_XPCOM_XPTI_REGISTRY_FILE) == 0) 131 fileLocation = mXPTIDatLocation; 132 else 133 return NS_ERROR_FAILURE; 134 135 rv = NS_NewNativeLocalFile (nsEmbedCString (fileLocation), 136 PR_TRUE, getter_AddRefs (localFile)); 137 if (NS_FAILED(rv)) 138 return rv; 139 140 return localFile->QueryInterface (NS_GET_IID (nsIFile), 141 (void **) aRetval); 142 } 143 144 #endif /* defined (VBOX_WITH_XPCOM) */ 50 145 51 146 HRESULT Initialize() … … 59 154 COINIT_SPEED_OVER_MEMORY); 60 155 61 #else 156 #else /* !defined (VBOX_WITH_XPCOM) */ 62 157 63 158 /* Set VBOX_XPCOM_HOME if not present */ 64 if (! getenv("VBOX_XPCOM_HOME"))159 if (!RTEnvExist ("VBOX_XPCOM_HOME")) 65 160 { 66 161 /* get the executable path */ 67 char szPathProgram[1024]; 68 int rcVBox = RTPathProgram(szPathProgram, sizeof(szPathProgram)); 69 if (VBOX_SUCCESS(rcVBox)) 70 { 71 setenv("VBOX_XPCOM_HOME", szPathProgram, 1); 72 } 162 char pathProgram [RTPATH_MAX]; 163 int vrc = RTPathProgram (pathProgram, sizeof (pathProgram)); 164 if (RT_SUCCESS (vrc)) 165 { 166 char *pathProgramCP = NULL; 167 vrc = RTStrUtf8ToCurrentCP (&pathProgramCP, pathProgram); 168 if (RT_SUCCESS (vrc)) 169 { 170 vrc = RTEnvSet ("VBOX_XPCOM_HOME", pathProgramCP); 171 RTStrFree (pathProgramCP); 172 } 173 } 174 AssertRC (vrc); 73 175 } 74 176 … … 78 180 { 79 181 XPCOMGlueStartup (nsnull); 80 nsCOMPtr <nsIServiceManager> serviceManager; 81 rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager), nsnull, nsnull); 182 183 nsCOMPtr <DirectoryServiceProvider> dsProv; 184 185 /* prepare paths for registry files */ 186 Utf8Str homeDir; 187 int vrc = GetVBoxUserHomeDirectory (homeDir); 188 if (RT_SUCCESS (vrc)) 189 { 190 Utf8Str compReg = Utf8StrFmt ("%s%c%s", homeDir.raw(), 191 RTPATH_DELIMITER, "compreg.dat"); 192 Utf8Str xptiDat = Utf8StrFmt ("%s%c%s", homeDir.raw(), 193 RTPATH_DELIMITER, "xpti.dat"); 194 dsProv = new DirectoryServiceProvider(); 195 if (dsProv) 196 rc = dsProv->init (compReg, xptiDat); 197 else 198 rc = NS_ERROR_OUT_OF_MEMORY; 199 } 200 else 201 rc = NS_ERROR_FAILURE; 202 203 /* get the path to the executable */ 204 nsCOMPtr <nsIFile> appDir; 205 { 206 char path [RTPATH_MAX]; 207 char *appDirCP = NULL; 208 #if defined (DEBUG) 209 const char *env = RTEnvGet ("VIRTUALBOX_APP_HOME"); 210 if (env) 211 { 212 char *appDirUtf8 = NULL; 213 vrc = RTStrCurrentCPToUtf8 (&appDirUtf8, env); 214 if (RT_SUCCESS (vrc)) 215 { 216 vrc = RTPathReal (appDirUtf8, path, RTPATH_MAX); 217 if (RT_SUCCESS (vrc)) 218 vrc = RTStrUtf8ToCurrentCP (&appDirCP, appDirUtf8); 219 RTStrFree (appDirUtf8); 220 } 221 } 222 else 223 #endif 224 { 225 vrc = RTPathProgram (path, RTPATH_MAX); 226 if (RT_SUCCESS (vrc)) 227 vrc = RTStrUtf8ToCurrentCP (&appDirCP, path); 228 } 229 230 if (RT_SUCCESS (vrc)) 231 { 232 nsCOMPtr<nsILocalFile> file; 233 rc = NS_NewNativeLocalFile (nsEmbedCString (appDirCP), 234 PR_FALSE, getter_AddRefs (file)); 235 if (NS_SUCCEEDED (rc)) 236 appDir = do_QueryInterface (file, &rc); 237 238 RTStrFree (appDirCP); 239 } 240 else 241 rc = NS_ERROR_FAILURE; 242 } 243 244 /* Finally, initialize XPCOM */ 82 245 if (NS_SUCCEEDED (rc)) 83 246 { 84 nsCOMPtr <nsIComponentRegistrar> registrar = 85 do_QueryInterface (serviceManager, &rc); 247 nsCOMPtr <nsIServiceManager> serviceManager; 248 rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager), 249 appDir, dsProv); 250 86 251 if (NS_SUCCEEDED (rc)) 87 registrar->AutoRegister (nsnull); 88 } 89 } 90 91 #endif 252 { 253 nsCOMPtr <nsIComponentRegistrar> registrar = 254 do_QueryInterface (serviceManager, &rc); 255 if (NS_SUCCEEDED (rc)) 256 registrar->AutoRegister (nsnull); 257 } 258 } 259 } 260 261 #endif /* !defined (VBOX_WITH_XPCOM) */ 92 262 93 263 AssertComRC (rc); … … 96 266 } 97 267 98 void Shutdown() 99 { 268 HRESULT Shutdown() 269 { 270 HRESULT rc = S_OK; 271 100 272 #if !defined (VBOX_WITH_XPCOM) 101 273 102 274 CoUninitialize(); 103 275 104 #else 276 #else /* !defined (VBOX_WITH_XPCOM) */ 105 277 106 278 nsCOMPtr <nsIEventQueue> eventQ; 107 nsresult rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 108 if (NS_SUCCEEDED (rc)) 109 { 279 rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 280 281 if (NS_SUCCEEDED (rc) || rc == NS_ERROR_NOT_AVAILABLE) 282 { 283 /* NS_ERROR_NOT_AVAILABLE seems to mean that 284 * nsIEventQueue::StopAcceptingEvents() has been called (see 285 * nsEventQueueService.cpp). We hope that this error code always means 286 * just that in this case and assume that we're on the main thread 287 * (it's a kind of unexpected behavior if a non-main thread ever calls 288 * StopAcceptingEvents() on the main event queue). */ 289 110 290 BOOL isOnMainThread = FALSE; 111 eventQ->IsOnCurrentThread (&isOnMainThread); 112 eventQ = nsnull; /* early release */ 113 if (isOnMainThread) 291 if (NS_SUCCEEDED (rc)) 292 { 293 rc = eventQ->IsOnCurrentThread (&isOnMainThread); 294 eventQ = nsnull; /* early release */ 295 } 296 else 297 { 298 isOnMainThread = TRUE; 299 rc = NS_OK; 300 } 301 302 if (NS_SUCCEEDED (rc) && isOnMainThread) 114 303 { 115 304 /* only the main thread needs to uninitialize XPCOM */ 116 NS_ShutdownXPCOM (nsnull);305 rc = NS_ShutdownXPCOM (nsnull); 117 306 XPCOMGlueShutdown(); 118 307 } 119 308 } 120 309 121 #endif 310 #endif /* !defined (VBOX_WITH_XPCOM) */ 311 312 AssertComRC (rc); 313 314 return rc; 122 315 } 123 316
Note:
See TracChangeset
for help on using the changeset viewer.