QString Screen::typeString() const { DisplayType dt = displayType(); int index = metaObject()->indexOfEnumerator("DisplayType"); Q_ASSERT(index != -1); QMetaEnum enumerator = metaObject()->enumerator(index); return QLatin1String(enumerator.valueToKey(dt)); }
std::string displayType() const { return displayType(m_type); }
int main(int argc, char *argv[]) { char *firmwareFileName; FILE *fpFirmwareFile; int inquiryType; int firstRecordType; int result; int fileSize; int isSpkg = 0; struct stat statBuf; IcsImageHeader_Record_t recordBuffer; uint8_t cssBuf[CSS_HEADER_SIZE + 10]; struct option longopts[] = { { "showVersion", no_argument, &inquiryType, SHOWVERSION }, { "showType", no_argument, &inquiryType, SHOWTYPE }, { "help", no_argument, &inquiryType, HELP }, { 0, 0, 0 , 0 } }; /* parse options for inquiry type */ if ((result = getopt_long(argc, argv, "", longopts, NULL))) // assignment, not == Usage(); if (inquiryType == HELP) Usage_full(); if (argc != 3) Usage(); /* set up endian-ness */ initializeState(); /* stat file to get size and allocate buffers */ firmwareFileName = argv[2]; if (stat(firmwareFileName, &statBuf) < 0) { fprintf(stderr, "Error taking stat of file {%s}: %s\n", firmwareFileName, strerror(errno)); exit(1); } fileSize = (int)statBuf.st_size; bufSize = fileSize + 1024; /* pad by 1K to be safe */ if ((cmpBuffer = malloc(bufSize)) == NULL) { fprintf(stderr, "Error allocating memory for firmware buffer\n"); goto fail; } if ((appBuffer = malloc(bufSize * 3)) == NULL) { fprintf(stderr, "Error allocating memory for inflated firmware buffer\n"); goto fail; } memset(cmpBuffer, 0, bufSize); memset(appBuffer, 0, bufSize * 3); /* open file */ if ((fpFirmwareFile = fopen(firmwareFileName, "rb")) == NULL) { fprintf(stderr, "Error opening file {%s} for input: %s\n", firmwareFileName, strerror(errno)); goto fail; } if (0 == fread(&cssBuf, CSS_HEADER_SIZE, 1, fpFirmwareFile)) { fprintf(stderr, "Error reading file {%s}: %s\n", firmwareFileName, strerror(errno)); goto fail; } isSpkg = checkCssHeader(cssBuf); /* get first record, check if ICS image file */ fseek(fpFirmwareFile, isSpkg ? CSS_HEADER_SIZE : 0, SEEK_SET); if (0 == fread(&firstRecordType, 4, 1, fpFirmwareFile)) { fprintf(stderr, "Error reading file {%s}: %s\n", firmwareFileName, strerror(errno)); goto fail; } fseek(fpFirmwareFile, isSpkg ? CSS_HEADER_SIZE : 0, SEEK_SET); if (ICS_IMAGE_HEADER_RECORD_TYPE_INFO != toHostEndian32(firstRecordType)) { fprintf(stderr, "This is not a valid firmware image file\n"); goto fail; } /* read in header, display what is asked for */ if (ERR_OK != getRecord(fpFirmwareFile, &recordBuffer)) goto fail; switch (inquiryType) { case SHOWVERSION: displayVersion(recordBuffer.payload.info.version); break; case SHOWTYPE: /* * For the type, we really want to look for the embedded strings first. * Call removeHeader, which will remove the ICS header from the package * file and place it in the compressed buffer. Then call * displayEmbeddedProdAndBsp which inflates and then searches. If the search * fails, it is a pre-3.1.0.1 release, so feed the codes from the ICS header * to displayType. */ result = removeHeader(argv[2], cmpBuffer); if (!displayEmbeddedProdAndBsp()) /* if this fails, try old way */ displayType(toHostEndian32(recordBuffer.payload.info.productCode), toHostEndian32(recordBuffer.payload.info.bspCode)); break; default: fprintf(stderr, "Unknown inquiry type\n"); goto fail; } fclose(fpFirmwareFile); fail: if (cmpBuffer != NULL) free(cmpBuffer); if (appBuffer != NULL) free(appBuffer); exit(0); }