int main() { char s[100] = "F o lg er"; ReplaceSpaces(s); printf("%s\n", s); return 0; }
int main(void) { char a[20] = " "; puts(a); ReplaceSpaces(a); puts(a); }
TagInfo* ParseLine(const char* buf,const String& base) { String pos; String file; SMatch m[10]; int n=10; if(reParse.Match(buf,m,n)) { TagInfo *i=new TagInfo; SetStr(i->name,buf,m[1]); SetStr(file,buf,m[2]); if(file[1]!=':' && file[0]!='\\') { file.Insert(0,base); } i->file=file; SetStr(pos,buf,m[3]); if(pos[0]=='/') { QuoteMeta(pos); ReplaceSpaces(pos); i->re=pos; if(m[5].start!=-1) { SetStr(pos,buf,m[5]); i->lineno=pos.ToInt(); } }else { i->lineno=pos.ToInt(); } SetStr(pos,buf,m[4]); i->type=pos[0]; if(m[5].start!=-1) { SetStr(i->info,buf,m[6]); } return i; } return NULL; }
QTSS_Error LogRequest(QTSS_ClientSessionObject inClientSession, QTSS_RTSPSessionObject inRTSPSession, QTSS_CliSesClosingReason *inCloseReasonPtr) { static StrPtrLen sUnknownStr(sVoidField); static StrPtrLen sTCPStr("TCP"); static StrPtrLen sUDPStr("UDP"); //Fetch the URL, user agent, movielength & movie bytes to log out of the RTP session enum { eTempLogItemSize = 256, // must be same or larger than others eURLSize = 256, eUserAgentSize = 256, ePlayerIDSize = 32, ePlayerVersionSize = 32, ePlayerLangSize = 32, ePlayerOSSize = 32, ePlayerOSVersSize = 32, ePlayerCPUSize = 32 }; char tempLogItemBuf[eTempLogItemSize] = { 0 }; StrPtrLen tempLogStr(tempLogItemBuf, eTempLogItemSize - 1); // // Check to see if this session is closing because authorization failed. If that's // the case, we've logged that already, let's not log it twice UInt32 theLen = 0; UInt32* authorizationFailed = NULL; (void)QTSS_GetValuePtr(inClientSession, sLoggedAuthorizationAttrID, 0, (void**)&authorizationFailed, &theLen); if ((authorizationFailed != NULL) && (*authorizationFailed > 0)) return QTSS_NoErr; ///inClientSession should never be NULL //inRTSPRequest may be NULL if this is a timeout OSMutexLocker locker(sLogMutex); CheckAccessLogState(false); if (sAccessLog == NULL) return QTSS_NoErr; //if logging is on, then log the request... first construct a timestamp char theDateBuffer[QTSSRollingLog::kMaxDateBufferSizeInBytes]; bool result = QTSSRollingLog::FormatDate(theDateBuffer, sLogTimeInGMT); //for now, just ignore the error. if (!result) theDateBuffer[0] = '\0'; theLen = sizeof(QTSS_RTSPSessionObject); QTSS_RTSPSessionObject theRTSPSession = inRTSPSession; if (theRTSPSession == NULL) (void)QTSS_GetValue(inClientSession, qtssCliSesLastRTSPSession, 0, (void*)&theRTSPSession, &theLen); // Get lots of neat info to log from the various dictionaries // Each attribute must be copied out to ensure that it is NULL terminated. // To ensure NULL termination, just memset the buffers to 0, and make sure that // the last byte of each array is untouched. Float32* packetLossPercent = NULL; Float64* movieDuration = NULL; UInt64* movieSizeInBytes = NULL; UInt32* movieAverageBitRatePtr = 0; UInt32 clientPacketsReceived = 0; UInt32 clientPacketsLost = 0; StrPtrLen* theTransportType = &sUnknownStr; SInt64* theCreateTime = NULL; SInt64* thePlayTime = NULL; UInt32 startPlayTimeInSecs = 0; char localIPAddrBuf[20] = { 0 }; StrPtrLen localIPAddr(localIPAddrBuf, 19); char localDNSBuf[70] = { 0 }; StrPtrLen localDNS(localDNSBuf, 69); char remoteDNSBuf[70] = { 0 }; StrPtrLen remoteDNS(remoteDNSBuf, 69); char remoteAddrBuf[20] = { 0 }; StrPtrLen remoteAddr(remoteAddrBuf, 19); char playerIDBuf[ePlayerIDSize] = { 0 }; StrPtrLen playerID(playerIDBuf, ePlayerIDSize - 1); // First, get networking info from the RTSP session (void)QTSS_GetValue(inClientSession, qtssCliRTSPSessLocalAddrStr, 0, localIPAddr.Ptr, &localIPAddr.Len); (void)QTSS_GetValue(inClientSession, qtssCliRTSPSessLocalDNS, 0, localDNS.Ptr, &localDNS.Len); (void)QTSS_GetValue(inClientSession, qtssCliSesHostName, 0, remoteDNS.Ptr, &remoteDNS.Len); (void)QTSS_GetValue(inClientSession, qtssCliRTSPSessRemoteAddrStr, 0, remoteAddr.Ptr, &remoteAddr.Len); (void)QTSS_GetValue(inClientSession, qtssCliRTSPSessRemoteAddrStr, 0, playerID.Ptr, &playerID.Len); UInt32* rtpBytesSent = NULL; UInt32* rtcpBytesRecv = NULL; UInt32* rtpPacketsSent = NULL; // Second, get networking info from the Client's session. // (Including the stats for incoming RTCP packets.) char urlBuf[eURLSize] = { 0 }; StrPtrLen url(urlBuf, eURLSize - 1); (void)QTSS_GetValue(inClientSession, qtssCliSesPresentationURL, 0, url.Ptr, &url.Len); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesPacketLossPercent, 0, (void**)&packetLossPercent, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesMovieDurationInSecs, 0, (void**)&movieDuration, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesMovieSizeInBytes, 0, (void**)&movieSizeInBytes, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesMovieAverageBitRate, 0, (void**)&movieAverageBitRatePtr, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesCreateTimeInMsec, 0, (void**)&theCreateTime, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesFirstPlayTimeInMsec, 0, (void**)&thePlayTime, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesRTPBytesSent, 0, (void**)&rtpBytesSent, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesRTPPacketsSent, 0, (void**)&rtpPacketsSent, &theLen); (void)QTSS_GetValuePtr(inClientSession, qtssCliSesRTCPBytesRecv, 0, (void**)&rtcpBytesRecv, &theLen); if (theCreateTime != NULL && thePlayTime != NULL) startPlayTimeInSecs = (UInt32)(((*theCreateTime - *thePlayTime) / 1000) + 0.5); // We need a value of 'c-bytes' to report as a log entry. This is supposed to be the total number // of bytes the client has received during the session. Unfortunately, the QT client does not give // us this number. We will use the following heuristic formula to estimate the number of bytes the // client has received during the session: // // client-bytes-received = bytes-sent * (100.0 - percent-packet-lost) / 100.0 // // The 'percent-packet-lost' value has been calculated internally by QTSS based on the RTCP packets // sent to the server from the client. If those values are accurate then the above formula will not // be exactly correct but it will be nearly correct. UInt32 clientBytesRecv = (UInt32)((*rtpBytesSent * (100.0 - *packetLossPercent)) / 100.0); tempLogStr.Ptr[0] = 0; tempLogStr.Len = eUserAgentSize; (void)QTSS_GetValue(inClientSession, qtssCliSesFirstUserAgent, 0, tempLogStr.Ptr, &tempLogStr.Len); char userAgentBuf[eUserAgentSize] = { 0 }; StrPtrLen userAgent(userAgentBuf, eUserAgentSize - 1); ReplaceSpaces(&tempLogStr, &userAgent, "%20"); UserAgentParser userAgentParser(&userAgent); // StrPtrLen* playerID = userAgentParser.GetUserID() ; StrPtrLen* playerVersion = userAgentParser.GetUserVersion(); StrPtrLen* playerLang = userAgentParser.GetUserLanguage(); StrPtrLen* playerOS = userAgentParser.GetrUserOS(); StrPtrLen* playerOSVers = userAgentParser.GetUserOSVersion(); StrPtrLen* playerCPU = userAgentParser.GetUserCPU(); // char playerIDBuf[ePlayerIDSize] = {}; char playerVersionBuf[ePlayerVersionSize] = { 0 }; char playerLangBuf[ePlayerLangSize] = { 0 }; char playerOSBuf[ePlayerOSSize] = { 0 }; char playerOSVersBuf[ePlayerOSVersSize] = { 0 }; char playerCPUBuf[ePlayerCPUSize] = { 0 }; UInt32 size; // (ePlayerIDSize < playerID->Len ) ? size = ePlayerIDSize -1 : size = playerID->Len; // if (playerID->Ptr != NULL) memcpy (playerIDBuf, playerID->Ptr, size); (ePlayerVersionSize < playerVersion->Len) ? size = ePlayerVersionSize - 1 : size = playerVersion->Len; if (playerVersion->Ptr != NULL) memcpy(playerVersionBuf, playerVersion->Ptr, size); (ePlayerLangSize < playerLang->Len) ? size = ePlayerLangSize - 1 : size = playerLang->Len; if (playerLang->Ptr != NULL) memcpy(playerLangBuf, playerLang->Ptr, size); (ePlayerOSSize < playerOS->Len) ? size = ePlayerOSSize - 1 : size = playerOS->Len; if (playerOS->Ptr != NULL) memcpy(playerOSBuf, playerOS->Ptr, size); (ePlayerOSVersSize < playerOSVers->Len) ? size = ePlayerOSVersSize - 1 : size = playerOSVers->Len; if (playerOSVers->Ptr != NULL) memcpy(playerOSVersBuf, playerOSVers->Ptr, size); (ePlayerCPUSize < playerCPU->Len) ? size = ePlayerCPUSize - 1 : size = playerCPU->Len; if (playerCPU->Ptr != NULL) memcpy(playerCPUBuf, playerCPU->Ptr, size); // clientPacketsReceived, clientPacketsLost, videoPayloadName and audioPayloadName // are all stored on a per-stream basis, so let's iterate through all the streams, // finding this information char videoPayloadNameBuf[32] = { 0 }; StrPtrLen videoPayloadName(videoPayloadNameBuf, 31); char audioPayloadNameBuf[32] = { 0 }; StrPtrLen audioPayloadName(audioPayloadNameBuf, 31); UInt32 qualityLevel = 0; UInt32 clientBufferTime = 0; UInt32 theStreamIndex = 0; bool* isTCPPtr = NULL; QTSS_RTPStreamObject theRTPStreamObject = NULL; for (UInt32 theStreamObjectLen = sizeof(theRTPStreamObject); QTSS_GetValue(inClientSession, qtssCliSesStreamObjects, theStreamIndex, (void*)&theRTPStreamObject, &theStreamObjectLen) == QTSS_NoErr; theStreamIndex++, theStreamObjectLen = sizeof(theRTPStreamObject)) { UInt32* streamPacketsReceived = NULL; UInt32* streamPacketsLost = NULL; (void)QTSS_GetValuePtr(theRTPStreamObject, qtssRTPStrTotPacketsRecv, 0, (void**)&streamPacketsReceived, &theLen); (void)QTSS_GetValuePtr(theRTPStreamObject, qtssRTPStrTotalLostPackets, 0, (void**)&streamPacketsLost, &theLen); // Add up packets received and packets lost to come up with a session wide total if (streamPacketsReceived != NULL) clientPacketsReceived += *streamPacketsReceived; if (streamPacketsLost != NULL) clientPacketsLost += *streamPacketsLost; // Identify the video and audio codec types QTSS_RTPPayloadType* thePayloadType = NULL; (void)QTSS_GetValuePtr(theRTPStreamObject, qtssRTPStrPayloadType, 0, (void**)&thePayloadType, &theLen); if (thePayloadType != NULL) { if (*thePayloadType == qtssVideoPayloadType) (void)QTSS_GetValue(theRTPStreamObject, qtssRTPStrPayloadName, 0, videoPayloadName.Ptr, &videoPayloadName.Len); else if (*thePayloadType == qtssAudioPayloadType) (void)QTSS_GetValue(theRTPStreamObject, qtssRTPStrPayloadName, 0, audioPayloadName.Ptr, &audioPayloadName.Len); } // If any one of the streams is being delivered over UDP instead of TCP, // report in the log that the transport type for this session was UDP. if (isTCPPtr == NULL) { (void)QTSS_GetValuePtr(theRTPStreamObject, qtssRTPStrIsTCP, 0, (void**)&isTCPPtr, &theLen); if (isTCPPtr != NULL) { if (*isTCPPtr == false) theTransportType = &sUDPStr; else theTransportType = &sTCPStr; } } Float32* clientBufferTimePtr = NULL; (void)QTSS_GetValuePtr(theRTPStreamObject, qtssRTPStrBufferDelayInSecs, 0, (void**)&clientBufferTimePtr, &theLen); if ((clientBufferTimePtr != NULL) && (*clientBufferTimePtr != 0)) { if (*clientBufferTimePtr > clientBufferTime) clientBufferTime = (UInt32)(*clientBufferTimePtr + .5); // round up to full seconds } } // Add the client buffer time to our client start latency (in whole seconds). startPlayTimeInSecs += clientBufferTime; if (*rtpPacketsSent == 0) // no packets sent qualityLevel = 0; // no quality else { if ((clientPacketsReceived == 0) && (clientPacketsLost == 0)) // no info from client qualityLevel = 100; //so assume 100 else { float qualityPercent = (float)clientPacketsReceived / (float)(clientPacketsReceived + clientPacketsLost); qualityPercent += (float).005; // round up qualityLevel = (UInt32)((float) 100.0 * qualityPercent); // average of sum of packet counts for all streams } } //we may not have an RTSP request. Assume that the status code is 504 timeout, if there is an RTSP //request, though, we can find out what the real status code of the response is static UInt32 sTimeoutCode = 504; UInt32* theStatusCode = &sTimeoutCode; theLen = sizeof(UInt32); (void)QTSS_GetValuePtr(inClientSession, qtssCliRTSPReqRealStatusCode, 0, (void **)&theStatusCode, &theLen); // qtss_printf("qtssCliRTSPReqRealStatusCode = %" _U32BITARG_ " \n", *theStatusCode); if (inCloseReasonPtr) do { if (*theStatusCode < 300) // it was a succesful RTSP request but... { if (*inCloseReasonPtr == qtssCliSesCloseTimeout) // there was a timeout { *theStatusCode = sTimeoutCode; // qtss_printf(" log timeout "); break; } if (*inCloseReasonPtr == qtssCliSesCloseClientTeardown) // there was a teardown { static QTSS_CliSesClosingReason sReason = qtssCliSesCloseClientTeardown; QTSS_CliSesClosingReason* theReasonPtr = &sReason; theLen = sizeof(QTSS_CliSesTeardownReason); (void)QTSS_GetValuePtr(inClientSession, qtssCliTeardownReason, 0, (void **)&theReasonPtr, &theLen); // qtss_printf("qtssCliTeardownReason = %" _U32BITARG_ " \n", *theReasonPtr); if (*theReasonPtr == qtssCliSesTearDownClientRequest) // the client asked for a tear down { // qtss_printf(" client requests teardown "); break; } if (*theReasonPtr == qtssCliSesTearDownUnsupportedMedia) // An error occured while streaming the file. { *theStatusCode = 415; // qtss_printf(" log UnsupportedMedia "); break; } if (*theReasonPtr == qtssCliSesTearDownBroadcastEnded) // a broadcaster stopped broadcasting { *theStatusCode = 452; // qtss_printf(" log broadcast removed "); break; } *theStatusCode = 500; // some unknown reason for cancelling the connection } // qtss_printf("return status "); // just use the qtssCliRTSPReqRealStatusCode for the reason } } while (false); // qtss_printf(" = %" _U32BITARG_ " \n", *theStatusCode); // Find out what time it is SInt64 curTime = QTSS_Milliseconds(); UInt32 numCurClients = 0; theLen = sizeof(numCurClients); (void)QTSS_GetValue(sServer, qtssRTPSvrCurConn, 0, &numCurClients, &theLen); /* IMPORTANT!!!! Some values such as cpu, #conns, need to be grabbed as the session starts, not when the teardown happened (I think) */ #if TESTUNIXTIME char thetestDateBuffer[QTSSRollingLog::kMaxDateBufferSizeInBytes]; TestUnixTime(QTSS_MilliSecsTo1970Secs(*theCreateTime), thetestDateBuffer); qtss_printf("%s\n", thetestDateBuffer); #endif float zeroFloat = 0; UInt64 zeroUInt64 = 0; Float32 fcpuUtilized = 0; theLen = sizeof(fcpuUtilized); (void)QTSS_GetValue(sServer, qtssSvrCPULoadPercent, 0, &fcpuUtilized, &theLen); UInt32 cpuUtilized = (UInt32)fcpuUtilized; char lastUserName[eTempLogItemSize] = { 0 }; StrPtrLen lastUserNameStr(lastUserName, eTempLogItemSize); char lastURLRealm[eTempLogItemSize] = { 0 }; StrPtrLen lastURLRealmStr(lastURLRealm, eTempLogItemSize); //qtss_printf("logging of saved params are in dictionary \n"); tempLogStr.Ptr[0] = 0; tempLogStr.Len = eTempLogItemSize; (void)QTSS_GetValue(inClientSession, qtssCliRTSPSesUserName, 0, tempLogStr.Ptr, &tempLogStr.Len); ReplaceSpaces(&tempLogStr, &lastUserNameStr, "%20"); //qtss_printf("qtssRTSPSesLastUserName dictionary item = %s len = %" _S32BITARG_ "\n",lastUserNameStr.Ptr,lastUserNameStr.Len); tempLogStr.Ptr[0] = 0; tempLogStr.Len = eTempLogItemSize; (void)QTSS_GetValue(inClientSession, qtssCliRTSPSesURLRealm, 0, tempLogStr.Ptr, &tempLogStr.Len); ReplaceSpaces(&tempLogStr, &lastURLRealmStr, "%20"); //qtss_printf("qtssRTSPSesLastURLRealm dictionary item = %s len = %" _S32BITARG_ "\n",lastURLRealmStr.Ptr,lastURLRealmStr.Len); char respMsgBuffer[1024] = { 0 }; StrPtrLen theRespMsg; (void)QTSS_GetValuePtr(inClientSession, qtssCliRTSPReqRespMsg, 0, (void**)&theRespMsg.Ptr, &theRespMsg.Len); StrPtrLen respMsgEncoded(respMsgBuffer, 1024 - 1); SInt32 theErr = StringTranslator::EncodeURL(theRespMsg.Ptr, theRespMsg.Len, respMsgEncoded.Ptr, respMsgEncoded.Len); if (theErr <= 0) respMsgEncoded.Ptr[0] = '\0'; else { respMsgEncoded.Len = theErr; respMsgEncoded.Ptr[respMsgEncoded.Len] = '\0'; } //cs-uri-query char urlQryBuf[eURLSize] = { 0 }; StrPtrLen urlQry(urlQryBuf, eURLSize - 1); (void)QTSS_GetValue(inClientSession, qtssCliSesReqQueryString, 0, urlQry.Ptr, &urlQry.Len); char tempLogBuffer[1024]; char logBuffer[2048]; // compatible fields (no respMsgEncoded field) ::memset(logBuffer, 0, 2048); qtss_sprintf(tempLogBuffer, "%s ", (remoteAddr.Ptr[0] == '\0') ? sVoidField : remoteAddr.Ptr); //c-ip* ::strcpy(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (theDateBuffer[0] == '\0') ? sVoidField : theDateBuffer); //date* time* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (remoteDNS.Ptr[0] == '\0') ? sVoidField : remoteDNS.Ptr); //c-dns ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (url.Ptr[0] == '\0') ? sVoidField : url.Ptr); //cs-uri-stem* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", startPlayTimeInSecs); //c-starttime ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", theCreateTime == NULL ? (UInt32)0 : (UInt32)(QTSS_MilliSecsTo1970Secs(curTime) - QTSS_MilliSecsTo1970Secs(*theCreateTime))); //x-duration* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _S32BITARG_ " ", (UInt32)1); //c-rate ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _S32BITARG_ " ", *theStatusCode); //c-status* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (playerIDBuf[0] == '\0') ? sVoidField : playerIDBuf); //c-playerid* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (playerVersionBuf[0] == '\0') ? sVoidField : playerVersionBuf); //c-playerversion ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (playerLangBuf[0] == '\0') ? sVoidField : playerLangBuf); //c-playerlanguage* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (userAgent.Ptr[0] == '\0') ? sVoidField : userAgent.Ptr); //cs(User-Agent) ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (playerOSBuf[0] == '\0') ? sVoidField : playerOSBuf); //c-os* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (playerOSVersBuf[0] == '\0') ? sVoidField : playerOSVersBuf); //c-osversion ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (playerCPUBuf[0] == '\0') ? sVoidField : playerCPUBuf); //c-cpu* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%0.0f ", movieDuration == NULL ? zeroFloat : *movieDuration); //filelength in secs* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _64BITARG_ "d ", movieSizeInBytes == NULL ? zeroUInt64 : *movieSizeInBytes); //filesize in bytes* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", movieAverageBitRatePtr == NULL ? (UInt32)0 : *movieAverageBitRatePtr); //avgbandwidth in bits per second ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", "RTP"); //protocol ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (theTransportType->Ptr[0] == '\0') ? sVoidField : theTransportType->Ptr); //transport ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (audioPayloadName.Ptr[0] == '\0') ? sVoidField : audioPayloadName.Ptr); //audiocodec* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (videoPayloadName.Ptr[0] == '\0') ? sVoidField : videoPayloadName.Ptr); //videocodec* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", rtpBytesSent == NULL ? (UInt32)0 : *rtpBytesSent); //sc-bytes* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", rtcpBytesRecv == NULL ? (UInt32)0 : *rtcpBytesRecv); //cs-bytes* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", clientBytesRecv); //c-bytes ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", rtpPacketsSent == NULL ? (UInt32)0 : *rtpPacketsSent); //s-pkts-sent* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", clientPacketsReceived); //c-pkts-recieved ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", clientPacketsLost); //c-pkts-lost-client* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", (UInt32)1); //c-buffercount ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", clientBufferTime); //c-totalbuffertime* ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", qualityLevel); //c-quality ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (localIPAddr.Ptr[0] == '\0') ? sVoidField : localIPAddr.Ptr); //s-ip ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (localDNS.Ptr[0] == '\0') ? sVoidField : localDNS.Ptr); //s-dns ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", numCurClients); //s-totalclients ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%" _U32BITARG_ " ", cpuUtilized); //s-cpu-util ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (urlQry.Ptr[0] == '\0') ? sVoidField : urlQry.Ptr); //cs-uri-query ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (lastUserName[0] == '\0') ? sVoidField : lastUserName); //c-username ::strcat(logBuffer, tempLogBuffer); qtss_sprintf(tempLogBuffer, "%s ", (lastURLRealm[0] == '\0') ? sVoidField : lastURLRealm); //sc(Realm) ::strcat(logBuffer, tempLogBuffer); ::strcat(logBuffer, "\n"); Assert(::strlen(logBuffer) < 2048); //finally, write the log message sAccessLog->WriteToLog(logBuffer, kAllowLogToRoll); return QTSS_NoErr; }
void c_FeatureReaderToHtml::ToTemplate(bool IsKml,c_RestDataReader* Reader, c_RestRequest* RestRequest , const string& FullUri,const string& UriBase ,string& HtmlStr,int StartIndex,int MaxCount) { Ptr<MgClassDefinition> classdef; // classdef = if( FeatureReader ) FeatureReader->GetClassDefinition() ; classdef = RestRequest->m_DataClassDef; if( !classdef ) return; //const c_CfgDataLayer* cfgdata = MgRest_MapNameToResourceId::GetCfgDataForClass(classfullname); const c_CfgDataResource* cfgresource = RestRequest->m_CfgDataResource; if( !cfgresource ) return; // error ; class has to be in configuration file const c_CfgRepTemplate* templatedata; if( RestRequest->m_CfgRepresentation->GetType() != c_CfgRepresentation::e_Template ) { return; } templatedata = (c_CfgRepTemplate*)RestRequest->m_CfgRepresentation; string rest_uri_part; if( cfgresource->m_RestUriPart.length() > 0 ) { MgUtil::WideCharToMultiByte(cfgresource->m_RestUriPart,rest_uri_part); } else { rest_uri_part = "/rest/data/"; } //ctemplate::Template::SetTemplateRootDirectory(g_HtmlTemplatePath); ctemplate::Template::SetTemplateRootDirectory(RestRequest->m_CfgDataResource->m_TemplateFolder); // get identity property name; STRING identname; if( classdef ) { Ptr<MgPropertyDefinitionCollection> idents = classdef->GetIdentityProperties(); if( idents->GetCount() == 1) { int ind=0; Ptr<MgPropertyDefinition> identprop = idents->GetItem(ind); identname = identprop->GetName(); } else { identname = L""; } } ctemplate::TemplateDictionary dict_main("KING.MGREST"); // now fill in request parameters if( RestRequest ) { Ptr<c_RestUriRequestParam> req_param = RestRequest->GetRequestParam(); MgStringPropertyCollection* params = req_param->GetParameters(); if( params && (params->GetCount()>0) ) { string dictkey; string param_name,param_val; string keyprefix = "REST_PARAM_"; for(int ind=0;ind<params->GetCount();ind++) { Ptr<MgStringProperty> param = params->GetItem(ind); MgUtil::WideCharToMultiByte(param->GetName(),param_name); ReplaceSpaces(param_name); // google ctemplate doesn't allow spaces MgUtil::WideCharToMultiByte(param->GetValue(),param_val); dict_main.SetValue(keyprefix+param_name,param_val); } } } string resturiparam; bool ismorerecords=false; int featurecount=0; if( (classdef != NULL) && (Reader!=NULL) ) { STRING wresturiparam = cfgresource->m_UriTag; MgUtil::WideCharToMultiByte(wresturiparam,resturiparam); bool isnext=true; int skipstart = StartIndex; if( skipstart > 0 ) { while ( (skipstart>0) && (isnext=Reader->ReadNext())==true ) { skipstart--; } } if( isnext ) { string dictname; // = mb_classname; MgUtil::WideCharToMultiByte(templatedata->m_HtmlTemp_Section,dictname); string nameprefix; // = mb_classname + "_"; MgUtil::WideCharToMultiByte(templatedata->m_HtmlTemp_Prefix,nameprefix); while ( Reader->ReadNext() ) { if( MaxCount >= 0 ) { if( featurecount >= MaxCount ) { ismorerecords=true; break; // go out } } ctemplate::TemplateDictionary* dict_section = dict_main.AddSectionDictionary(dictname); FillDictionary(dict_section,nameprefix,Reader); if( identname.length() > 0 ) { STRING strval; string mb_strval; GetPropertyAsString(Reader,identname,strval); MgUtil::WideCharToMultiByte(strval,mb_strval); // string dictkey = nameprefix + "REST_PNG"; string val = UriBase + rest_uri_part + resturiparam + "/" + mb_strval + ".png"; dict_section->SetValue(dictkey,val); dictkey = nameprefix + "REST_HTML"; val = UriBase + rest_uri_part + resturiparam + "/" + mb_strval + ".html"; dict_section->SetValue(dictkey,val); dictkey = nameprefix + "REST_KML"; val = UriBase + rest_uri_part + resturiparam + "/" + mb_strval + ".kml"; dict_section->SetValue(dictkey,val); dictkey = nameprefix + "REST_KMZ"; val = UriBase + rest_uri_part + resturiparam + "/" + mb_strval + ".kmz"; dict_section->SetValue(dictkey,val); dictkey = nameprefix + "REST_XML"; val = UriBase + rest_uri_part + resturiparam + "/" + mb_strval + ".xml"; dict_section->SetValue(dictkey,val); dictkey = nameprefix + "REST_JSON"; val = UriBase + rest_uri_part + resturiparam + "/" + mb_strval + ".json"; dict_section->SetValue(dictkey,val); // create feature identifier value as base64 coded string ident_base64; GetPropertyAsBase64(Reader,identname,ident_base64); dictkey = nameprefix + "REST_IDENT_BASE64"; dict_section->SetValue(dictkey,ident_base64); } featurecount++; } } // Now check additional data to be fetched for html template // it applies only to single feature templates if( featurecount==1 && templatedata->GetCountHtmlExtraData() > 0 ) { int count = templatedata->GetCountHtmlExtraData(); for(int ind=0;ind<count;ind++) { const c_CfgRepTemplateExtraData* extradata = templatedata->GetHtmlExtraData(ind); if( extradata->m_FetchUri.length() > 0 ) { // generate template unique name std::string filename,mb_str; MgUtil::WideCharToMultiByte(cfgresource->m_UriTag,filename); MgUtil::WideCharToMultiByte(extradata->m_HtmlTemp_Prefix,mb_str); filename += mb_str; MgUtil::WideCharToMultiByte(extradata->m_FetchUri,mb_str); filename=""; ctemplate::Template * temp = ctemplate::Template::StringToTemplate(mb_str,ctemplate::STRIP_WHITESPACE); /* ctemplate::Template * temp = ctemplate::Template::RegisterStringAsTemplate(filename, ctemplate::STRIP_WHITESPACE,ctemplate::TC_MANUAL,mb_str); */ std::string uristr; temp->Expand(&uristr,&dict_main); // Now use uristr to fetch data std::string mb_str2,mb_str3,mb_str4; MgUtil::WideCharToMultiByte(extradata->m_HtmlTemp_Section,mb_str2); MgUtil::WideCharToMultiByte(extradata->m_HtmlTemp_DataSection,mb_str3); MgUtil::WideCharToMultiByte(extradata->m_HtmlTemp_Prefix,mb_str4); c_RestFetchSource::FetchFeaturesToDictionary( uristr,&dict_main,mb_str2,mb_str3,mb_str4 ); delete temp; } } } // now add in dictionary values for next and previous if( ismorerecords || StartIndex>0 ) { Poco::URI uri_parser(FullUri); std::string query = uri_parser.getQuery(); c_RestUriRequestParam params; c_RestUri::ParseQuery(query.c_str(),¶ms); if( StartIndex>0 ) { int newstart = StartIndex - MaxCount; if( newstart < 0 ) newstart=0; newstart++; wchar_t strstart[20]; ::swprintf(&strstart[0],L"%d",newstart); if( params.ContainsParameter(L"Start") ) { params.SetParameterValue(L"Start",strstart); } else { params.AddParameter(L"Start",strstart); } wstring wuriquery; params.GetAsUriQuery(wuriquery); string uriquery; MgUtil::WideCharToMultiByte(wuriquery,uriquery); //string prev_uri = UriBase + rest_uri_part + resturiparam + "/" + ".html" + "?" + uriquery; string prev_uri = "?" + uriquery; // use only query part so link will be correct in case of url rewrites ctemplate::TemplateDictionary* dict_section = dict_main.AddSectionDictionary("PREVIOUS_PAGE_SECTION"); string dictkey = "PREVIOUS_PAGE"; dict_section->SetValue(dictkey,prev_uri); } else { // no previous link //string dictkey = nameprefix + "PREVIOUS_PAGE"; //dict_main.SetEscapedValue(,); } if( ismorerecords>0 ) { int newstart = StartIndex + MaxCount; if( newstart < 0 ) newstart=0; newstart++; wchar_t strstart[20]; ::swprintf(&strstart[0],L"%d",newstart); if( params.ContainsParameter(L"Start") ) { params.SetParameterValue(L"Start",strstart); } else { params.AddParameter(L"Start",strstart); } wstring wuriquery; params.GetAsUriQuery(wuriquery); string uriquery; MgUtil::WideCharToMultiByte(wuriquery,uriquery); //string next_uri = UriBase + rest_uri_part + resturiparam + "/" + ".html" + "?" + uriquery; string next_uri = "?" + uriquery; // use only query part so link will be correct in case of url rewrites ctemplate::TemplateDictionary* dict_section = dict_main.AddSectionDictionary("NEXT_PAGE_SECTION"); string dictkey = "NEXT_PAGE"; dict_section->SetValue(dictkey,next_uri); } else { // no previous link //string dictkey = nameprefix + "NEXT_PAGE"; //dict_main.SetEscapedValue(,); } } } string tmpl; // name of template to use if(Reader) { if( featurecount == 1 ) MgUtil::WideCharToMultiByte(templatedata->m_HtmlTemp_Single,tmpl); else { if( featurecount == 0 ) MgUtil::WideCharToMultiByte(templatedata->m_HtmlTemp_Zero,tmpl); else MgUtil::WideCharToMultiByte(templatedata->m_HtmlTemp_Many,tmpl); } } else { // if there was no feature reader MgUtil::WideCharToMultiByte(templatedata->m_HtmlTemp_Error,tmpl); if(RestRequest->m_RestResultObjectStatus == c_RestRequest::e_BBox_OutOfRange ) dict_main.ShowSection("EXCEPTION_BBOX_LIMIT"); if(RestRequest->m_RestResultObjectStatus == c_RestRequest::e_Count_OutOfRange ) dict_main.ShowSection("EXCEPTION_COUNT_LIMIT"); } /* string tmpl = mb_classname; // if there is only one feature then use different template // name of that template for class "parcel" is parcel.tpl , added "1" to end of class name if( count <= 1 ) { tmpl.append("1"); } tmpl.append(".tpl"); */ ctemplate::Template::ReloadAllIfChanged(); ctemplate::TemplateContext tc; if( IsKml ) tc = ctemplate::TC_XML; else tc = ctemplate::TC_HTML; //ctemplate::Template* tpl = ctemplate::Template::GetTemplateWithAutoEscaping(tmpl,ctemplate::DO_NOT_STRIP,tc); ctemplate::Template* tpl = ctemplate::Template::GetTemplate(tmpl,ctemplate::DO_NOT_STRIP); if( !tpl ) { //Ptr<MgStringCollection> scol = new MgStringCollection(); std::wstring wsarg; MgUtil::MultiByteToWideChar(tmpl,wsarg); //scol->Add(wsarg); std::wstring errmsg = L"Unable to load Template file '"; errmsg = errmsg.append(wsarg); errmsg = errmsg.append(L"'. Check config file and template file location!"); throw new MgRuntimeException(L"c_FeatureReaderToHtml::ToTemplate",__LINE__, __WFILE__, NULL, errmsg, NULL); } tpl->Expand(&HtmlStr,&dict_main); }//end of c_FeatureReaderToHtml::ToTemplate
void FillDictionary(ctemplate::TemplateDictionary* Dict,const std::string& NamePrefix, c_RestDataReader* FeatureReader) { int count = FeatureReader->GetPropertyCount(); for(int ind=0;ind<count;ind++) { STRING propname = FeatureReader->GetPropertyName(ind); if( !FeatureReader->IsNull(propname) ) { string dictkey = NamePrefix + MgUtil::WideCharToMultiByte(propname); ReplaceSpaces(dictkey); // google ctemplate doesn't allow spaces int ptype = FeatureReader->GetPropertyType(propname); switch( ptype ) { case MgPropertyType::Geometry: { /* int geomlength; BYTE_ARRAY_OUT geombytes = FeatureReader->GetGeometry(propname,geomlength); Ptr<MgByteReader> bytes = new MgByteReader( geombytes,geomlength,L"" ); */ try { Ptr<MgByteReader> bytes = FeatureReader->GetGeometry(propname); MgAgfReaderWriter agfReader; Ptr<MgGeometry> fgfgeom = agfReader.Read(bytes); MgWktReaderWriter wktReader; STRING wktstring = wktReader.Write(fgfgeom); string mb_wktstring = MgUtil::WideCharToMultiByte(wktstring); Dict->SetValue(dictkey,mb_wktstring); string kmlgeometry,kmlcentroid,kml_multi_centroid_polygon; double cent_x,cent_y; c_KmlUtil::ToKml(fgfgeom,kmlgeometry,kmlcentroid,cent_x,cent_y,kml_multi_centroid_polygon); Dict->SetValue(dictkey+"_KML",kmlgeometry); Dict->SetValue(dictkey+"_KML_CENTROID",kmlcentroid); Dict->SetValue(dictkey+"_KML_MULTI",kml_multi_centroid_polygon); string georsssimple; c_GeoRssUtil::ToGeoRssSimple(fgfgeom,georsssimple); Dict->SetValue(dictkey+"_GEORSS",georsssimple); string gml; c_GmlUtil::ToGML(fgfgeom,gml,c_GmlUtil::e_GmlFormat::GML311); Dict->SetValue(dictkey+"_GML",gml); char buff[4*64+6]; ::sprintf(buff, "%.7g", cent_x); Dict->SetValue(dictkey+"_CENTROID_X",buff); ::sprintf(buff, "%.7g", cent_y); Dict->SetValue(dictkey+"_CENTROID_Y",buff); Ptr<MgEnvelope> e2 = fgfgeom->Envelope(); Ptr<MgCoordinate> ll = e2->GetLowerLeftCoordinate(); Ptr<MgCoordinate> ur = e2->GetUpperRightCoordinate(); ::sprintf(buff, "%.7g,%.7g,%.7g,%.7g", ll->GetX(),ll->GetY(),ur->GetX(),ur->GetY()); Dict->SetValue(NamePrefix + "REST_ENVELOPE",buff); // set same value for BBOX Dict->SetValue(dictkey+"_BBOX",buff); ::sprintf(buff, "%.7g", ll->GetX()); Dict->SetValue(dictkey+"_BBOX_MIN_X",buff); ::sprintf(buff, "%.7g", ur->GetX()); Dict->SetValue(dictkey+"_BBOX_MAX_X",buff); ::sprintf(buff, "%.7g", (ll->GetX()+ur->GetX())/2.0); Dict->SetValue(dictkey+"_BBOX_MID_X",buff); ::sprintf(buff, "%.7g", ll->GetY()); Dict->SetValue(dictkey+"_BBOX_MIN_Y",buff); ::sprintf(buff, "%.7g", ur->GetY()); Dict->SetValue(dictkey+"_BBOX_MAX_Y",buff); ::sprintf(buff, "%.7g", (ll->GetY()+ur->GetY())/2.0); Dict->SetValue(dictkey+"_BBOX_MID_Y",buff); } catch (MgException *ex) // just ignore in case of invalid geometries { ex->Release(); } } break; case MgPropertyType::Int64: { INT64 val = FeatureReader->GetInt64(propname); std::string tmp = ""; MgUtil::Int64ToString(val, tmp); Dict->SetValue(dictkey,tmp); } break; case MgPropertyType::Int32: { long val = FeatureReader->GetInt32(propname); Dict->SetFormattedValue(dictkey,"%ld",val); } break; case MgPropertyType::Int16: { int val = FeatureReader->GetInt16(propname); Dict->SetIntValue(dictkey,val); } break; case MgPropertyType::Double: { double val = FeatureReader->GetDouble(propname); Dict->SetFormattedValue(dictkey,"%.5g",val); } break; case MgPropertyType::Single: { float val = FeatureReader->GetSingle(propname); Dict->SetFormattedValue(dictkey,"%.5f",val); } break; case MgPropertyType::Boolean: { bool val = FeatureReader->GetBoolean(propname); Dict->SetValue(dictkey,val ? "TRUE" : "FALSE"); } break; case MgPropertyType::Byte: { BYTE val = FeatureReader->GetByte(propname); Dict->SetIntValue(dictkey,val ); } break; case MgPropertyType::DateTime: { Ptr<MgDateTime> date = FeatureReader->GetDateTime(propname); string val; MgDateTimeToString(date,val); Dict->SetValue(dictkey,val ); // set date as Atom string Poco::DateTime dt(date->GetYear(), date->GetMonth(), date->GetDay(), date->GetHour(), date->GetMinute(), date->GetSecond()); std::string str = Poco::DateTimeFormatter::format(dt, Poco::DateTimeFormat::ISO8601_FORMAT); Dict->SetValue(dictkey+"_ATOM_DATE",str); } break; case MgPropertyType::String: { string val = MgUtil::WideCharToMultiByte(FeatureReader->GetString(propname)); Dict->SetValue(dictkey,val); } break; } } } }
struct RA_ARENA *RA_Create(char *name, u32 base, size_t uSize, struct BM_MAPPING *psMapping, size_t uQuantum, IMG_BOOL(*imp_alloc) (void *, size_t uSize, size_t *pActualSize, struct BM_MAPPING **ppsMapping, u32 _flags, u32 *pBase), void (*imp_free) (void *, u32, struct BM_MAPPING *), void(*backingstore_free) (void *, u32, u32, void *), void *pImportHandle) { struct RA_ARENA *pArena; struct BT *pBT; int i; PVR_DPF(PVR_DBG_MESSAGE, "RA_Create: " "name='%s', base=0x%x, uSize=0x%x, alloc=0x%x, free=0x%x", name, base, uSize, imp_alloc, imp_free); if (OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(*pArena), (void **) &pArena, NULL) != PVRSRV_OK) goto arena_fail; pArena->name = name; pArena->pImportAlloc = (imp_alloc != NULL) ? imp_alloc : _RequestAllocFail; pArena->pImportFree = imp_free; pArena->pBackingStoreFree = backingstore_free; pArena->pImportHandle = pImportHandle; for (i = 0; i < FREE_TABLE_LIMIT; i++) pArena->aHeadFree[i] = NULL; pArena->pHeadSegment = NULL; pArena->pTailSegment = NULL; pArena->uQuantum = uQuantum; #ifdef RA_STATS pArena->sStatistics.uSpanCount = 0; pArena->sStatistics.uLiveSegmentCount = 0; pArena->sStatistics.uFreeSegmentCount = 0; pArena->sStatistics.uFreeResourceCount = 0; pArena->sStatistics.uTotalResourceCount = 0; pArena->sStatistics.uCumulativeAllocs = 0; pArena->sStatistics.uCumulativeFrees = 0; pArena->sStatistics.uImportCount = 0; pArena->sStatistics.uExportCount = 0; #endif #if defined(CONFIG_PROC_FS) && defined(CONFIG_PVR_DEBUG_EXTRA) if (strcmp(pArena->name, "") != 0) { int ret; int (*pfnCreateProcEntry) (const char *, read_proc_t, write_proc_t, void *); pArena->bInitProcEntry = !PVRSRVGetInitServerState(PVRSRV_INIT_SERVER_SUCCESSFUL); pfnCreateProcEntry = pArena->bInitProcEntry ? CreateProcEntry : CreatePerProcessProcEntry; ret = snprintf(pArena->szProcInfoName, sizeof(pArena->szProcInfoName), "ra_info_%s", pArena->name); if (ret > 0 && ret < sizeof(pArena->szProcInfoName)) { (void)pfnCreateProcEntry(ReplaceSpaces (pArena->szProcInfoName), RA_DumpInfo, NULL, pArena); } else { pArena->szProcInfoName[0] = 0; PVR_DPF(PVR_DBG_ERROR, "RA_Create: " "couldn't create ra_info proc entry for arena %s", pArena->name); } ret = snprintf(pArena->szProcSegsName, sizeof(pArena->szProcSegsName), "ra_segs_%s", pArena->name); if (ret > 0 && ret < sizeof(pArena->szProcInfoName)) { (void)pfnCreateProcEntry(ReplaceSpaces (pArena->szProcSegsName), RA_DumpSegs, NULL, pArena); } else { pArena->szProcSegsName[0] = 0; PVR_DPF(PVR_DBG_ERROR, "RA_Create: " "couldn't create ra_segs proc entry for arena %s", pArena->name); } } #endif pArena->pSegmentHash = HASH_Create(MINIMUM_HASH_SIZE); if (pArena->pSegmentHash == NULL) goto hash_fail; if (uSize > 0) { uSize = (uSize + uQuantum - 1) / uQuantum * uQuantum; pBT = _InsertResource(pArena, base, uSize); if (pBT == NULL) goto insert_fail; pBT->psMapping = psMapping; } return pArena; insert_fail: HASH_Delete(pArena->pSegmentHash); hash_fail: OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(struct RA_ARENA), pArena, NULL); arena_fail: return NULL; }
RA_ARENA * RA_Create (IMG_CHAR *name, IMG_UINTPTR_T base, IMG_SIZE_T uSize, BM_MAPPING *psMapping, IMG_SIZE_T uQuantum, IMG_BOOL (*imp_alloc)(IMG_VOID *, IMG_SIZE_T uSize, IMG_SIZE_T *pActualSize, BM_MAPPING **ppsMapping, IMG_UINT32 _flags, IMG_UINTPTR_T *pBase), IMG_VOID (*imp_free) (IMG_VOID *, IMG_UINTPTR_T, BM_MAPPING *), IMG_VOID (*backingstore_free) (IMG_VOID*, IMG_SIZE_T, IMG_SIZE_T, IMG_HANDLE), IMG_VOID *pImportHandle) { RA_ARENA *pArena; BT *pBT; IMG_INT i; PVR_DPF ((PVR_DBG_MESSAGE, "RA_Create: name='%s', base=0x%x, uSize=0x%x, alloc=0x%x, free=0x%x", name, base, uSize, (IMG_UINTPTR_T)imp_alloc, (IMG_UINTPTR_T)imp_free)); if (OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof (*pArena), (IMG_VOID **)&pArena, IMG_NULL, "Resource Arena") != PVRSRV_OK) { goto arena_fail; } pArena->name = name; pArena->pImportAlloc = (imp_alloc!=IMG_NULL) ? imp_alloc : &_RequestAllocFail; pArena->pImportFree = imp_free; pArena->pBackingStoreFree = backingstore_free; pArena->pImportHandle = pImportHandle; for (i=0; i<FREE_TABLE_LIMIT; i++) pArena->aHeadFree[i] = IMG_NULL; pArena->pHeadSegment = IMG_NULL; pArena->pTailSegment = IMG_NULL; pArena->uQuantum = uQuantum; #ifdef RA_STATS pArena->sStatistics.uSpanCount = 0; pArena->sStatistics.uLiveSegmentCount = 0; pArena->sStatistics.uFreeSegmentCount = 0; pArena->sStatistics.uFreeResourceCount = 0; pArena->sStatistics.uTotalResourceCount = 0; pArena->sStatistics.uCumulativeAllocs = 0; pArena->sStatistics.uCumulativeFrees = 0; pArena->sStatistics.uImportCount = 0; pArena->sStatistics.uExportCount = 0; #endif #if defined(CONFIG_PROC_FS) && defined(DEBUG) if(strcmp(pArena->name,"") != 0) { IMG_INT ret; IMG_CHAR szProcInfoName[PROC_NAME_SIZE]; IMG_CHAR szProcSegsName[PROC_NAME_SIZE]; struct proc_dir_entry* (*pfnCreateProcEntrySeq)(const IMG_CHAR *, IMG_VOID*, pvr_next_proc_seq_t, pvr_show_proc_seq_t, pvr_off2element_proc_seq_t, pvr_startstop_proc_seq_t, write_proc_t); pArena->bInitProcEntry = !PVRSRVGetInitServerState(PVRSRV_INIT_SERVER_SUCCESSFUL); pfnCreateProcEntrySeq = pArena->bInitProcEntry ? CreateProcEntrySeq : CreatePerProcessProcEntrySeq; ret = snprintf(szProcInfoName, sizeof(szProcInfoName), "ra_info_%s", pArena->name); if (ret > 0 && ret < sizeof(szProcInfoName)) { pArena->pProcInfo = pfnCreateProcEntrySeq(ReplaceSpaces(szProcInfoName), pArena, NULL, RA_ProcSeqShowInfo, RA_ProcSeqOff2ElementInfo, NULL, NULL); } else { pArena->pProcInfo = 0; PVR_DPF((PVR_DBG_ERROR, "RA_Create: couldn't create ra_info proc entry for arena %s", pArena->name)); } ret = snprintf(szProcSegsName, sizeof(szProcSegsName), "ra_segs_%s", pArena->name); if (ret > 0 && ret < sizeof(szProcInfoName)) { pArena->pProcSegs = pfnCreateProcEntrySeq(ReplaceSpaces(szProcSegsName), pArena, NULL, RA_ProcSeqShowRegs, RA_ProcSeqOff2ElementRegs, NULL, NULL); } else { pArena->pProcSegs = 0; PVR_DPF((PVR_DBG_ERROR, "RA_Create: couldn't create ra_segs proc entry for arena %s", pArena->name)); } } #endif pArena->pSegmentHash = HASH_Create (MINIMUM_HASH_SIZE); if (pArena->pSegmentHash==IMG_NULL) { goto hash_fail; } if (uSize>0) { uSize = (uSize + uQuantum - 1) / uQuantum * uQuantum; pBT = _InsertResource (pArena, base, uSize); if (pBT == IMG_NULL) { goto insert_fail; } pBT->psMapping = psMapping; } return pArena; insert_fail: HASH_Delete (pArena->pSegmentHash); hash_fail: OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(RA_ARENA), pArena, IMG_NULL); arena_fail: return IMG_NULL; }