void DeviceInfoTest::DidAppear() { String platform = DeviceInfo::GetPlatformString(); String version = DeviceInfo::GetVersion(); String manufacturer = DeviceInfo::GetManufacturer(); String model = DeviceInfo::GetModel(); String locale = DeviceInfo::GetLocale(); String region = DeviceInfo::GetRegion(); String timezone = DeviceInfo::GetTimeZone(); String udid = DeviceInfo::GetUDID(); WideString name = DeviceInfo::GetName(); List<DeviceInfo::StorageInfo> storages = DeviceInfo::GetStoragesList(); String deviceInfoString; deviceInfoString += Format("Platform: %s\n", platform.c_str()); deviceInfoString += Format("OS version: %s\n", version.c_str()); deviceInfoString += Format("Manufacturer: %s\n", manufacturer.c_str()); deviceInfoString += Format("Model: %s\n", model.c_str()); deviceInfoString += Format("Locale: %s\n", locale.c_str()); deviceInfoString += Format("Region: %s\n", region.c_str()); deviceInfoString += Format("Time zone: %s\n", timezone.c_str()); deviceInfoString += Format("UDID: %s\n", udid.c_str()); deviceInfoString += Format("Name: %s\n", WStringToString(name).c_str()); deviceInfoString += Format("ZBufferSize: %d\n", DeviceInfo::GetZBufferSize()); deviceInfoString += Format("CPU count: %d\n", DeviceInfo::GetCpuCount()); const eGPUFamily gpu = DeviceInfo::GetGPUFamily(); if(gpu == GPU_INVALID) { deviceInfoString += "GPU family: INVALID\n"; } else { deviceInfoString += Format("GPU family: %s\n", GPUFamilyDescriptor::GetGPUName(gpu).c_str()); } deviceInfoString += Format("Network connection type: %s\n", GetNetworkTypeString().c_str()); deviceInfoString += Format("Network signal strength: %i%%\n", DeviceInfo::GetNetworkInfo().signalStrength); List<DeviceInfo::StorageInfo>::const_iterator iter = storages.begin(); for (;iter != storages.end(); ++iter) { String storageName; switch(iter->type) { case DeviceInfo::STORAGE_TYPE_INTERNAL: storageName = "Internal storage"; break; case DeviceInfo::STORAGE_TYPE_PRIMARY_EXTERNAL: storageName = "Primary external storage"; break; case DeviceInfo::STORAGE_TYPE_SECONDARY_EXTERNAL: storageName = "Secondary external storage"; break; default: storageName = "Unknown storage"; break; } String str; if (iter->emulated) { str += "; emulated"; } if (iter->readOnly) { str += "; read only"; } deviceInfoString += Format("%s: path: %s; capacity: %s; free: %s%s\n", storageName.c_str(), iter->path.GetAbsolutePathname().c_str(), FormatStorageSize(iter->totalSpace).c_str(), FormatStorageSize(iter->freeSpace).c_str(), str.c_str()); } deviceInfoText->SetText(StringToWString(deviceInfoString)); Logger::Debug("********** Device info **********"); Logger::Debug(deviceInfoString.c_str()); Logger::Debug("********** Device info **********"); }
unsigned __stdcall PacketThreadProc(void* lpParameter) { PTHREAD_PARAM threadParam = (PTHREAD_PARAM) lpParameter; char message[BUFSIZE] = {0,}; char headerBuf[HEADER_LENGTH]; Packet * packet = NULL; int len; // return value placeholder of recv() function int packetLength; // length of (SIGNATURE + HEADER + dummyData) int dummyDataSize; // only dummyData length SYSTEMTIME lt; char filename[MAX_PATH]; std::map<unsigned int, double> packets; GetLocalTime(<); sprintf(filename, "packetlog-%02d%02d%02d.txt", lt.wHour, lt.wMinute, lt.wSecond); FILE *fp = fopen (filename, "w+"); if (!fp) printf ("** fopen error!!\n"); if(threadParam->hClientSock==INVALID_SOCKET) { printf("accept() Error!!"); goto error; } printf ("** accepted(%s).\n", inet_ntoa ( (struct in_addr)threadParam->clntAddr.sin_addr )); while( true ) { // STEP 1. peeking packet header with SIGNATURE (32bytes) if ( (len = recv(threadParam->hClientSock, headerBuf, HEADER_LENGTH, MSG_PEEK)) >= HEADER_LENGTH ) { int signatureTemp; memcpy(&signatureTemp, headerBuf, SIGNATURE_LENGTH); // printf(">>> Received signature -- 0x%X \n", signatureTemp); if ( SIGNATURE != signatureTemp ) { // if signature doesn't match, discard first 4 bytes from the socket buffer. // And try to read again printf(">>> Wrong singnature. Move 1 byte forward and read again... \n"); recv(threadParam->hClientSock, headerBuf, 1, 0); continue; } } else if ( len <= 0 ) { // recv() failed or connection closed printf(">>> recv() fail. len=%d (%d) \n", len, WSAGetLastError()); break; } else { // if peeked data size is less than FULL_HEADER_LENGTH, read more socket buffer. continue; } // STEP 2. read dummyDataSize and prepare buffer. memcpy(&dummyDataSize, headerBuf+28, sizeof(unsigned int)); packetLength = HEADER_LENGTH + dummyDataSize; packet = (Packet*)malloc(packetLength); // STEP 3. read the full packet from the socket int receivedBytes = 0; // received bytes counter SHOULD be reset at this point. while ( receivedBytes < packetLength ) { // read along the buffer (shifted by receivedBytes) if ( (len = recv(threadParam->hClientSock, (char*)(packet)+receivedBytes, packetLength-receivedBytes, 0)) > 0 ) { receivedBytes += len; continue; } else { printf(">>> recv() fail. len=%d (%d) \n", len, WSAGetLastError()); goto thread_cleanup; } } // STEP 4. if reading the packet is successful, print the information printf ("(%u) signature: 0x%X dsize: %u deviceId: %u type: %u idx: %u network: %u time: %u\n", len, packet->signature, packet->dummyDataSize, packet->deviceID, packet->type, packet->idx, packet->network, (unsigned int)packet->timestamp ); // STEP 5. if packet type = 0, create a new timestamp entry and send reply. // if packet type = 1, look up a timestamp in the map and calculate the RTT, and write it to the file if (packet->type == 0) { packets[packet->idx] = packet->timestamp; int slen = send(threadParam->hClientSock, (char*)packet, HEADER_LENGTH+packet->dummyDataSize, 0); if (slen <= 0) { printf ("** error!! send fail. (%d)\n", len, GetLastError()); break; } else { printf ("** idx (%u) reply bytes: %u\n", packet->idx, slen); } } else { std::map<unsigned int, double>::iterator itor; itor = packets.find(packet->idx); if (itor == packets.end()) { printf("** unknown packet idx(%u).\n", packet->idx); continue; } GetLocalTime(<); sprintf (message, "%02d:%02d:%02d, %u,%u,%u,%s,%f\n", lt.wHour, lt.wMinute, lt.wSecond, sizeof(Packet)+packet->dummyDataSize, packet->deviceID, packet->idx, GetNetworkTypeString(packet->network), packet->timestamp - packets[packet->idx]); if (fp) { fputs(message,fp); fflush(fp); } packets.erase(packet->idx); printf ("%s", message); } } /* char recvbuf [256] = {0,}; while((len=recv(threadParam->hClientSock, recvbuf, sizeof(recvbuf), 0)) > 0) { printf ("%s\n", recvbuf); send (threadParam->hClientSock, recvbuf, len, 0); ZeroMemory (recvbuf, sizeof(recvbuf)); } */ thread_cleanup: free(packet); closesocket (threadParam->hClientSock); if (fp) fclose(fp); packets.clear(); printf ("** disconnected(%s).\n", inet_ntoa ( (struct in_addr)threadParam->clntAddr.sin_addr )); error: free (threadParam); return 0; }