static HRESULT dumpIdl(const QString &input, const QString &idlfile, const QString &version) { HRESULT res = E_FAIL; if (input.endsWith(QLatin1String(".exe"))) { if (runWithQtInEnvironment(quotePath(input) + QLatin1String(" -dumpidl ") + idlfile + QLatin1String(" -version ") + version)) res = S_OK; } else { HMODULE hdll = LoadLibrary((const wchar_t *)input.utf16()); if (!hdll) { fprintf(stderr, "Couldn't load library file %s\n", (const char*)input.toLocal8Bit().data()); return 3; } typedef HRESULT(__stdcall* DumpIDLProc)(const QString&, const QString&); DumpIDLProc DumpIDL = (DumpIDLProc)GetProcAddress(hdll, "DumpIDL"); if (!DumpIDL) { fprintf(stderr, "Couldn't resolve 'DumpIDL' symbol in %s\n", (const char*)input.toLocal8Bit().data()); return 3; } res = DumpIDL(idlfile, version); FreeLibrary(hdll); } return res; }
static bool unregisterServer(const QString &input) { bool ok = false; if (input.endsWith(QLatin1String(".exe"))) { ok = runWithQtInEnvironment(quotePath(input) + QLatin1String(" -unregserver")); } else { HMODULE hdll = LoadLibrary((const wchar_t *)input.utf16()); if (!hdll) { fprintf(stderr, "Couldn't load library file %s\n", (const char*)input.toLocal8Bit().data()); return false; } typedef HRESULT(__stdcall* RegServerProc)(); RegServerProc DllUnregisterServer = (RegServerProc)GetProcAddress(hdll, "DllUnregisterServer"); if (!DllUnregisterServer) { fprintf(stderr, "Library file %s doesn't appear to be a COM library\n", (const char*)input.toLocal8Bit().data()); return false; } ok = DllUnregisterServer() == S_OK; } return ok; }
int runIdc(int argc, char **argv) { QString error; QString tlbfile; QString idlfile; QString input; QString version = QLatin1String("1.0"); int i = 1; while (i < argc) { QString p = QString::fromLocal8Bit(argv[i]).toLower(); if (p == QLatin1String("/idl") || p == QLatin1String("-idl")) { ++i; if (i > argc) { error = QLatin1String("Missing name for interface definition file!"); break; } idlfile = QLatin1String(argv[i]); idlfile = idlfile.trimmed().toLower(); } else if (p == QLatin1String("/version") || p == QLatin1String("-version")) { ++i; if (i > argc) version = QLatin1String("1.0"); else version = QLatin1String(argv[i]); } else if (p == QLatin1String("/tlb") || p == QLatin1String("-tlb")) { ++i; if (i > argc) { error = QLatin1String("Missing name for type library file!"); break; } tlbfile = QLatin1String(argv[i]); tlbfile = tlbfile.trimmed().toLower(); } else if (p == QLatin1String("/v") || p == QLatin1String("-v")) { fprintf(stdout, "Qt Interface Definition Compiler version 1.0\n"); return 0; } else if (p == QLatin1String("/regserver") || p == QLatin1String("-regserver")) { if (!registerServer(input)) { fprintf(stderr, "Failed to register server!\n"); return 1; } fprintf(stderr, "Server registered successfully!\n"); return 0; } else if (p == QLatin1String("/unregserver") || p == QLatin1String("-unregserver")) { if (!unregisterServer(input)) { fprintf(stderr, "Failed to unregister server!\n"); return 1; } fprintf(stderr, "Server unregistered successfully!\n"); return 0; } else if (p[0] == QLatin1Char('/') || p[0] == QLatin1Char('-')) { error = QLatin1String("Unknown option \"") + p + QLatin1Char('\"'); break; } else { input = QLatin1String(argv[i]); input = input.trimmed().toLower(); } i++; } if (!error.isEmpty()) { fprintf(stderr, "%s", error.toLatin1().data()); fprintf(stderr, "\n"); return 5; } if (input.isEmpty()) { fprintf(stderr, "No input file specified!\n"); return 1; } if (input.endsWith(QLatin1String(".exe")) && tlbfile.isEmpty() && idlfile.isEmpty()) { fprintf(stderr, "No type output file specified!\n"); return 2; } if (input.endsWith(QLatin1String(".dll")) && idlfile.isEmpty() && tlbfile.isEmpty()) { fprintf(stderr, "No interface definition file and no type library file specified!\n"); return 3; } slashify(input); if (!tlbfile.isEmpty()) { slashify(tlbfile); QFile file(tlbfile); if (!file.open(QIODevice::ReadOnly)) { fprintf(stderr, "Couldn't open %s for read\n", (const char*)tlbfile.toLocal8Bit().data()); return 4; } QByteArray data = file.readAll(); QString error; bool ok = attachTypeLibrary(input, 1, data, &error); fprintf(stderr, "%s", error.toLatin1().data()); fprintf(stderr, "\n"); return ok ? 0 : 4; } else if (!idlfile.isEmpty()) { slashify(idlfile); idlfile = quotePath(idlfile); fprintf(stderr, "\n\n%s\n\n", (const char*)idlfile.toLocal8Bit().data()); quotePath(input); HRESULT res = dumpIdl(input, idlfile, version); switch(res) { case S_OK: break; case E_FAIL: fprintf(stderr, "IDL generation failed trying to run program %s!\n", (const char*)input.toLocal8Bit().data()); return res; case -1: fprintf(stderr, "Couldn't open %s for writing!\n", (const char*)idlfile.toLocal8Bit().data()); return res; case 1: fprintf(stderr, "Malformed appID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 2: fprintf(stderr, "Malformed typeLibID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 3: fprintf(stderr, "Class has no metaobject information (error in %s)!\n", (const char*)input.toLocal8Bit().data()); return res; case 4: fprintf(stderr, "Malformed classID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 5: fprintf(stderr, "Malformed interfaceID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 6: fprintf(stderr, "Malformed eventsID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; default: fprintf(stderr, "Unknown error writing IDL from %s\n", (const char*)input.toLocal8Bit().data()); return 7; } } return 0; }
/* Main routine */ int main(int argc, char** argv) { const char* avdName = NULL; char* avdArch = NULL; char* emulatorPath; int force_32bit = 0; /* Define ANDROID_EMULATOR_DEBUG to 1 in your environment if you want to * see the debug messages from this launcher program. */ const char* debug = getenv("ANDROID_EMULATOR_DEBUG"); if (debug != NULL && *debug && *debug != '0') android_verbose = 1; /* Parse command-line and look for * 1) an avd name either in the form or '-avd <name>' or '@<name>' * 2) '-force-32bit' which always use 32-bit emulator on 64-bit platforms */ int nn; for (nn = 1; nn < argc; nn++) { const char* opt = argv[nn]; if (!strcmp(opt,"-qemu")) break; if (!strcmp(opt,"-force-32bit")) { force_32bit = 1; continue; } if (!avdName) { if (!strcmp(opt,"-avd") && nn+1 < argc) { avdName = argv[nn+1]; } else if (opt[0] == '@' && opt[1] != '\0') { avdName = opt+1; } } } /* If there is an AVD name, we're going to extract its target architecture * by looking at its config.ini */ if (avdName != NULL) { D("Found AVD name '%s'\n", avdName); avdArch = path_getAvdTargetArch(avdName); D("Found AVD target architecture: %s\n", avdArch); } else { /* Otherwise, using the ANDROID_PRODUCT_OUT directory */ const char* androidOut = getenv("ANDROID_PRODUCT_OUT"); if (androidOut != NULL && *androidOut != '\0') { D("Found ANDROID_PRODUCT_OUT: %s\n", androidOut); avdArch = path_getBuildTargetArch(androidOut); D("Found build target architecture: %s\n", avdArch); } } if (avdArch == NULL) { avdArch = "arm"; D("Can't determine target AVD architecture: defaulting to %s\n", avdArch); } /* Find the architecture-specific program in the same directory */ emulatorPath = getTargetEmulatorPath(argv[0], avdArch, force_32bit); D("Found target-specific emulator binary: %s\n", emulatorPath); /* Replace it in our command-line */ argv[0] = emulatorPath; #ifdef _WIN32 /* Looks like execv() in mingw (or is it MSVCRT.DLL?) doesn't * support a space in argv[0] unless we explicitely quote it. * IMPORTANT: do not quote the first argument to execv() or it will fail. * This was tested on a 32-bit Vista installation. */ if (strchr(emulatorPath, ' ')) { argv[0] = quotePath(emulatorPath); D("Quoted emulator binary path: %s\n", emulatorPath); } #endif /* We need to find the location of the GLES emulation shared libraries * and modify either LD_LIBRARY_PATH or PATH accordingly */ { char* sharedLibPath = getSharedLibraryPath(emulatorPath, GLES_EMULATION_LIB); if (sharedLibPath != NULL) { D("Found OpenGLES emulation libraries in %s\n", sharedLibPath); prependSharedLibraryPath(sharedLibPath); } else { D("Could not find OpenGLES emulation host libraries!\n"); } } /* Launch it with the same set of options ! */ safe_execv(emulatorPath, argv); /* We could not launch the program ! */ fprintf(stderr, "Could not launch '%s': %s\n", emulatorPath, strerror(errno)); return errno; }