当前位置: 首页>>代码示例>>C++>>正文


C++ NPT_InputStreamReference::AsPointer方法代码示例

本文整理汇总了C++中NPT_InputStreamReference::AsPointer方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_InputStreamReference::AsPointer方法的具体用法?C++ NPT_InputStreamReference::AsPointer怎么用?C++ NPT_InputStreamReference::AsPointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPT_InputStreamReference的用法示例。


在下文中一共展示了NPT_InputStreamReference::AsPointer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

/*----------------------------------------------------------------------
|   PLT_Downloader::ProcessResponse
+---------------------------------------------------------------------*/
NPT_Result 
PLT_Downloader::ProcessResponse(NPT_Result                    res, 
                                const NPT_HttpRequest&        request, 
                                const NPT_HttpRequestContext& context, 
                                NPT_HttpResponse*             response)
{
    NPT_COMPILER_UNUSED(request);
    NPT_COMPILER_UNUSED(context);

    if (NPT_FAILED(res)) {
        NPT_LOG_WARNING_2("Downloader error %d for %s", res, m_URL.ToString().GetChars());
        m_State = PLT_DOWNLOADER_ERROR;
        return res;
    }

    m_State = PLT_DOWNLOADER_DOWNLOADING;

    NPT_HttpEntity* entity;
    NPT_InputStreamReference body;
    if (!response || 
        !(entity = response->GetEntity()) || 
        NPT_FAILED(entity->GetInputStream(body)) || 
        body.IsNull()) {
        m_State = PLT_DOWNLOADER_ERROR;
        NPT_LOG_WARNING_2("No body %d for %s", res, m_URL.ToString().GetChars());
        return NPT_FAILURE;
    }

    // Read body (no content length means until socket is closed)
    res = NPT_StreamToStreamCopy(*body.AsPointer(), 
        *m_Output.AsPointer(), 
        0, 
        entity->GetContentLength());

    if (NPT_FAILED(res)) {
        NPT_LOG_WARNING_2("Downloader error %d for %s", res, m_URL.ToString().GetChars());
        m_State = PLT_DOWNLOADER_ERROR;
        return res;
    }
    
    NPT_LOG_INFO_1("Finished downloading %s", m_URL.ToString().GetChars());
    m_State = PLT_DOWNLOADER_SUCCESS;
    return NPT_SUCCESS;
}
开发者ID:0xheart0,项目名称:xbmc,代码行数:47,代码来源:PltDownloader.cpp

示例2:

/*----------------------------------------------------------------------
|   PLT_Downloader::ProcessResponse
+---------------------------------------------------------------------*/
NPT_Result 
PLT_Downloader::ProcessResponse(NPT_Result                    res, 
                                NPT_HttpRequest*              request, 
                                const NPT_HttpRequestContext& context, 
                                NPT_HttpResponse* response)
{
    NPT_COMPILER_UNUSED(request);
    NPT_COMPILER_UNUSED(context);

    if (NPT_FAILED(res)) {
        m_State = PLT_DOWNLOADER_ERROR;
        return res;
    }

    m_State = PLT_DOWNLOADER_DOWNLOADING;

    NPT_HttpEntity* entity;
    NPT_InputStreamReference body;
    if (!response || !(entity = response->GetEntity()) || 
        NPT_FAILED(entity->GetInputStream(body)) || body.IsNull()) {
        m_State = PLT_DOWNLOADER_ERROR;
        return NPT_FAILURE;
    }

    // Read body (no content length means until socket is closed)
    res = NPT_StreamToStreamCopy(*body.AsPointer(), 
        *m_Output.AsPointer(), 
        0, 
        entity->GetContentLength());

    if (NPT_FAILED(res)) {
        m_State = PLT_DOWNLOADER_ERROR;
        return res;
    }

    m_State = PLT_DOWNLOADER_SUCCESS;
    return NPT_SUCCESS;
}
开发者ID:AWilco,项目名称:xbmc,代码行数:41,代码来源:PltDownloader.cpp

示例3: serveFile

void serveFile(AbortableTask *task, const NPT_String& filePath, const NPT_String& mimeType, const FrontEnd::RequestContext& reqCtx, const NPT_HttpRequest *req, NPT_HttpResponse& resp, HttpOutput *httpOutput)
{
	NPT_File f(filePath);
	NPT_FileInfo fileInfo;
	if (NPT_FAILED(f.GetInfo(fileInfo)) || fileInfo.m_Type != NPT_FileInfo::FILE_TYPE_REGULAR || NPT_FAILED(f.Open(NPT_FILE_OPEN_MODE_READ))) {
		setStatusCode(resp, 404);
		httpOutput->writeResponseHeader(resp);
		return;
	}

	MediaStore::FileDetail detail;
	detail.m_mimeType = mimeType;
	detail.m_path = filePath;
	detail.m_modificationTime = fileInfo.m_ModificationTime;
	detail.m_size = fileInfo.m_Size;
	detail.m_type = MediaStore::FileDetail::PosixFile;

	NPT_InputStreamReference fileInput;
	f.GetInputStream(fileInput);

	AdvFileReader reader(fileInput.AsPointer());
	serveStreamAdv(task, detail, &reader, reqCtx, req, resp, httpOutput, 1024 * 64);
}
开发者ID:bubbletreefrog,项目名称:DLNA,代码行数:23,代码来源:DJMediaStore.cpp

示例4: serveFile2

void serveFile2(AbortableTask *task, const NPT_String& filePath, const NPT_String& mimeType, const FrontEnd::RequestContext& reqCtx, const NPT_HttpRequest *req, NPT_HttpResponse& resp, HttpOutput *httpOutput)
{
#if 1
	NPT_File f(filePath);
	NPT_FileInfo fileInfo;
	if (NPT_FAILED(f.GetInfo(fileInfo)) || fileInfo.m_Type != NPT_FileInfo::FILE_TYPE_REGULAR || NPT_FAILED(f.Open(NPT_FILE_OPEN_MODE_READ))) {
		setStatusCode(resp, 404);
		httpOutput->writeResponseHeader(resp);
		return;
	}

	NPT_InputStreamReference fileInput;
	f.GetInputStream(fileInput);
	serveStream(task, fileInput.AsPointer(), fileInfo.m_ModificationTime, mimeType, reqCtx, req, resp, httpOutput);
#else
	bool isGetMethod = req->GetMethod().Compare("GET") == 0;
	bool isHeadMethod = req->GetMethod().Compare("HEAD") == 0;
	if (isGetMethod || isHeadMethod) {
		NPT_Result nr;
		NPT_File f(filePath);
		NPT_FileInfo fileInfo;
		if (NPT_FAILED(f.GetInfo(fileInfo)) || fileInfo.m_Type != NPT_FileInfo::FILE_TYPE_REGULAR || NPT_FAILED(f.Open(NPT_FILE_OPEN_MODE_READ))) {
			setStatusCode(resp, 404);
			httpOutput->writeResponseHeader(resp);
			return;
		}

		NPT_InputStreamReference fileInput;
		f.GetInputStream(fileInput);

		NPT_UInt64 offset, length;

		NPT_HttpHeader *hdrRange = req->GetHeaders().GetHeader("RANGE");
		if (hdrRange) {
			if (!parseRangeHeader(hdrRange->GetValue(), fileInfo.m_Size, offset, length)) {
				setStatusCode(resp, 416);
				httpOutput->writeResponseHeader(resp);
				return;
			}
			setStatusCode(resp, 206);
			resp.GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_RANGE, NPT_String::Format("bytes %s-%s/%s", NPT_String::FromIntegerU(offset).GetChars(), NPT_String::FromIntegerU(offset + length - 1).GetChars(), NPT_String::FromIntegerU(fileInfo.m_Size).GetChars()));
			fileInput->Seek(offset);
		} else {
			offset = 0;
			length = fileInfo.m_Size;
			setStatusCode(resp, 200);
		}

		resp.GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_TYPE, mimeType);
		resp.GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_LENGTH, NPT_String::FromIntegerU(length));
		resp.GetHeaders().SetHeader("Last-Modified", NPT_DateTime(fileInfo.m_ModificationTime).ToString(NPT_DateTime::FORMAT_RFC_1123));
		resp.GetHeaders().SetHeader("Accept-Ranges", "bytes");

		resp.GetHeaders().SetHeader("EXT", "");
		if (reqCtx.transferMode != FrontEnd::TM_None) {
			const char *transferMode = "Streaming";
			switch (reqCtx.transferMode) {
			case FrontEnd::TM_Background:
				transferMode = "Background";
				break;
			case FrontEnd::TM_Interactive:
				transferMode = "Interactive";
				break;
			}
			resp.GetHeaders().SetHeader("transferMode.dlna.org", transferMode);
		}

		if (reqCtx.getcontentFeaturesReq) {
			NPT_String contentFeatures("DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000");
			resp.GetHeaders().SetHeader("contentFeatures.dlna.org", contentFeatures);
		}

		httpOutput->writeResponseHeader(resp);

		if (isGetMethod) {

			bool abortFlag = false;
			ServeFileAbortCallback abortCallback(&abortFlag);

			if (task->registerAbortCallback(&abortCallback)) {
				NPT_DataBuffer buffer(4096);

				NPT_UInt64 cbRemain = length;

				for (;;) {
					if (abortFlag) {
						break;
					}

					if (cbRemain == 0) {
						break;
					}

					NPT_Size cbRead;
					NPT_UInt64 cbToRead = cbRemain;
					if (cbToRead > buffer.GetBufferSize()) {
						cbToRead = buffer.GetBufferSize();
					}
					nr = fileInput->Read(buffer.UseData(), buffer.GetBufferSize(), &cbRead);
					if (NPT_FAILED(nr)) {
//.........这里部分代码省略.........
开发者ID:bubbletreefrog,项目名称:DLNA,代码行数:101,代码来源:DJMediaStore.cpp


注:本文中的NPT_InputStreamReference::AsPointer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。