本文整理汇总了C++中NPT_SUCCEEDED函数的典型用法代码示例。如果您正苦于以下问题:C++ NPT_SUCCEEDED函数的具体用法?C++ NPT_SUCCEEDED怎么用?C++ NPT_SUCCEEDED使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NPT_SUCCEEDED函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: m_MediaBrowser
/*----------------------------------------------------------------------
| CUPnP::CUPnP
+---------------------------------------------------------------------*/
CUPnP::CUPnP() :
m_MediaBrowser(NULL),
m_MediaController(NULL),
m_LogHandler(NULL),
m_ServerHolder(new CDeviceHostReferenceHolder()),
m_RendererHolder(new CRendererReferenceHolder()),
m_CtrlPointHolder(new CCtrlPointReferenceHolder())
{
NPT_LogManager::GetDefault().Configure("plist:.level=FINE;.handlers=CustomHandler;");
NPT_LogHandler::Create("xbmc", "CustomHandler", m_LogHandler);
m_LogHandler->SetCustomHandlerFunction(&UPnPLogger);
// initialize upnp context
m_UPnP = new PLT_UPnP();
// keep main IP around
if (g_application.getNetwork().GetFirstConnectedInterface()) {
m_IP = g_application.getNetwork().GetFirstConnectedInterface()->GetCurrentIPAddress().c_str();
}
NPT_List<NPT_IpAddress> list;
if (NPT_SUCCEEDED(PLT_UPnPMessageHelper::GetIPAddresses(list)) && list.GetItemCount()) {
m_IP = (*(list.GetFirstItem())).ToString();
}
else if(m_IP.empty())
m_IP = "localhost";
// start upnp monitoring
m_UPnP->Start();
}
示例2: CreateRenderer
/*----------------------------------------------------------------------
| CUPnP::StartRenderer
+---------------------------------------------------------------------*/
void CUPnP::StartRenderer()
{
if (!m_RendererHolder->m_Device.IsNull()) return;
CStdString filename;
URIUtils::AddFileToFolder(CProfilesManager::Get().GetUserDataFolder(), "upnpserver.xml", filename);
CUPnPSettings::Get().Load(filename);
m_RendererHolder->m_Device = CreateRenderer(CUPnPSettings::Get().GetRendererPort());
NPT_Result res = m_UPnP->AddDevice(m_RendererHolder->m_Device);
// failed most likely because port is in use, try again with random port now
if (NPT_FAILED(res) && CUPnPSettings::Get().GetRendererPort() != 0) {
m_RendererHolder->m_Device = CreateRenderer(0);
res = m_UPnP->AddDevice(m_RendererHolder->m_Device);
}
// save port but don't overwrite saved settings if random
if (NPT_SUCCEEDED(res) && CUPnPSettings::Get().GetRendererPort() == 0) {
CUPnPSettings::Get().SetRendererPort(m_RendererHolder->m_Device->GetPort());
}
// save UUID
CUPnPSettings::Get().SetRendererUUID(m_RendererHolder->m_Device->GetUUID().GetChars());
CUPnPSettings::Get().Save(filename);
}
示例3: NPT_COMPILER_UNUSED
/*----------------------------------------------------------------------
| CMediaCrawler::ProcessFileRequest
+---------------------------------------------------------------------*/
NPT_Result
CMediaCrawler::ProcessFileRequest(NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response)
{
NPT_COMPILER_UNUSED(context);
NPT_LOG_FINE("CMediaCrawler::ProcessFileRequest Received Request:");
PLT_LOG_HTTP_MESSAGE(NPT_LOG_LEVEL_FINE, &request);
if (request.GetMethod().Compare("GET") && request.GetMethod().Compare("HEAD")) {
response.SetStatus(500, "Internal Server Error");
return NPT_SUCCESS;
}
// add the user agent header, some stupid media servers like YME needs it
if (!request.GetHeaders().GetHeader(NPT_HTTP_HEADER_USER_AGENT)) {
request.GetHeaders().SetHeader(NPT_HTTP_HEADER_USER_AGENT,
"Platinum/" PLT_PLATINUM_VERSION_STRING);
}
// File requested
NPT_HttpResponse* out_response = NULL;
NPT_HttpUrlQuery query(request.GetUrl().GetQuery());
const char* url = query.GetField("url");
if (url) {
// look for handler
CStreamHandler* handler = NULL;
NPT_ContainerFind(m_StreamHandlers, CStreamHandlerFinder(NULL, url), handler);
if (handler && NPT_SUCCEEDED(handler->ProcessFileRequest(request, out_response)) && out_response) {
// copy response code and reason
response.SetStatus(out_response->GetStatusCode(), out_response->GetReasonPhrase());
// copy headers
NPT_List<NPT_HttpHeader*>::Iterator headers = out_response->GetHeaders().GetHeaders().GetFirstItem();
while (headers) {
response.GetHeaders().SetHeader((*headers)->GetName(), (*headers)->GetValue());
++headers;
}
response.SetEntity(new NPT_HttpEntity(response.GetHeaders()));
// update inputstream
NPT_HttpEntity* out_entity;
if ((out_entity = out_response->GetEntity()) != NULL) {
NPT_InputStreamReference inputstream;
out_entity->GetInputStream(inputstream);
if (!inputstream.IsNull()) {
// set the stream but do not update the content length
response.GetEntity()->SetInputStream(inputstream, false);
}
}
delete out_response;
return NPT_SUCCESS;
}
}
response.SetStatus(404, "File Not Found");
return NPT_SUCCESS;
}
示例4: GetConfigValue
/*----------------------------------------------------------------------
| NPT_LogManager::ConfigureLogger
+---------------------------------------------------------------------*/
NPT_Result
NPT_LogManager::ConfigureLogger(NPT_Logger* logger)
{
/* configure the level */
NPT_String* level_value = GetConfigValue(logger->m_Name,".level");
if (level_value) {
NPT_Int32 value;
/* try a symbolic name */
value = NPT_Log::GetLogLevel(*level_value);
if (value < 0) {
/* try a numeric value */
if (NPT_FAILED(level_value->ToInteger(value, false))) {
value = -1;
}
}
if (value >= 0) {
logger->m_Level = value;
logger->m_LevelIsInherited = false;
}
}
/* remove any existing handlers */
logger->DeleteHandlers();
/* configure the handlers */
NPT_String* handlers = GetConfigValue(logger->m_Name,".handlers");
if (handlers) {
const char* handlers_list = handlers->GetChars();
const char* cursor = handlers_list;
const char* name_start = handlers_list;
NPT_String handler_name;
NPT_LogHandler* handler;
for (;;) {
if (*cursor == '\0' || *cursor == ',') {
if (cursor != name_start) {
handler_name.Assign(name_start, (NPT_Size)(cursor-name_start));
handler_name.Trim(" \t");
/* create a handler */
if (NPT_SUCCEEDED(
NPT_LogHandler::Create(logger->m_Name, handler_name, handler))) {
logger->AddHandler(handler);
}
}
if (*cursor == '\0') break;
name_start = cursor+1;
}
++cursor;
}
}
/* configure the forwarding */
NPT_String* forward = GetConfigValue(logger->m_Name,".forward");
if (forward && !ConfigValueIsBooleanTrue(*forward)) {
logger->m_ForwardToParent = false;
}
return NPT_SUCCESS;
}
示例5: NPT_LogTcpHandler
/*----------------------------------------------------------------------
| NPT_LogTcpHandler::Create
+---------------------------------------------------------------------*/
NPT_Result
NPT_LogTcpHandler::Create(const char* logger_name, NPT_LogHandler*& handler)
{
/* compute a prefix for the configuration of this handler */
NPT_String logger_prefix = logger_name;
logger_prefix += ".TcpHandler";
/* allocate a new object */
NPT_LogTcpHandler* instance = new NPT_LogTcpHandler();
handler = instance;
/* configure the object */
const NPT_String* hostname = LogManager.GetConfigValue(logger_prefix, ".hostname");
if (hostname) {
instance->m_Host = *hostname;
} else {
/* default hostname */
instance->m_Host = "localhost";
}
const NPT_String* port = LogManager.GetConfigValue(logger_prefix, ".port");
if (port) {
NPT_UInt32 port_int;
if (NPT_SUCCEEDED(port->ToInteger(port_int, true))) {
instance->m_Port = (NPT_UInt16)port_int;
} else {
instance->m_Port = NPT_LOG_TCP_HANDLER_DEFAULT_PORT;
}
} else {
/* default port */
instance->m_Port = NPT_LOG_TCP_HANDLER_DEFAULT_PORT;
}
return NPT_SUCCESS;
}
示例6: directory
/*----------------------------------------------------------------------
| PLT_FileMediaServer::GetEntryCount
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::GetEntryCount(const char* path, NPT_Cardinal& count)
{
NPT_String dir_path = path;
// reset output params
count = 0;
// ensure path ends with a delimiter
if (!dir_path.EndsWith(m_DirDelimiter)) {
dir_path += m_DirDelimiter;
}
NPT_Directory directory(dir_path);
NPT_String entryName;
NPT_Result res = directory.GetNextEntry(entryName);
if (NPT_FAILED(res)) {
NPT_LOG_WARNING_1("PLT_FileMediaServer::OnBrowseDirectChildren - failed to open dir %s", (const char*) path);
return res;
}
do {
/* Check if the item would be ok to add to a didl */
// NPT_Reference<PLT_MediaObject> item(BuildFromFilePath(dir_path + entryName, false));
// if (!item.IsNull()) {
// count++;
// }
NPT_DirectoryEntryInfo info;
if (ProceedWithEntry(dir_path + entryName, info)) count++;
res = directory.GetNextEntry(entryName);
} while (NPT_SUCCEEDED(res));
return NPT_SUCCESS;
}
示例7: file
/*----------------------------------------------------------------------
| PLT_HttpServer::ServeFile
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpServer::ServeFile(const NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response,
NPT_String file_path)
{
NPT_InputStreamReference stream;
NPT_File file(file_path);
NPT_FileInfo file_info;
// prevent hackers from accessing files outside of our root
if ((file_path.Find("/..") >= 0) || (file_path.Find("\\..") >= 0) ||
NPT_FAILED(NPT_File::GetInfo(file_path, &file_info))) {
return NPT_ERROR_NO_SUCH_ITEM;
}
// check for range requests
const NPT_String* range_spec = request.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_RANGE);
// handle potential 304 only if range header not set
NPT_DateTime date;
NPT_TimeStamp timestamp;
if (NPT_SUCCEEDED(PLT_UPnPMessageHelper::GetIfModifiedSince((NPT_HttpMessage&)request, date)) &&
!range_spec) {
date.ToTimeStamp(timestamp);
NPT_LOG_INFO_5("File %s timestamps: request=%d (%s) vs file=%d (%s)",
(const char*)request.GetUrl().GetPath(),
(NPT_UInt32)timestamp.ToSeconds(),
(const char*)date.ToString(),
(NPT_UInt32)file_info.m_ModificationTime,
(const char*)NPT_DateTime(file_info.m_ModificationTime).ToString());
if (timestamp >= file_info.m_ModificationTime) {
// it's a match
NPT_LOG_FINE_1("Returning 304 for %s", request.GetUrl().GetPath().GetChars());
response.SetStatus(304, "Not Modified", NPT_HTTP_PROTOCOL_1_1);
return NPT_SUCCESS;
}
}
// open file
if (NPT_FAILED(file.Open(NPT_FILE_OPEN_MODE_READ)) ||
NPT_FAILED(file.GetInputStream(stream)) ||
stream.IsNull()) {
return NPT_ERROR_NO_SUCH_ITEM;
}
// set Last-Modified and Cache-Control headers
if (file_info.m_ModificationTime) {
NPT_DateTime last_modified = NPT_DateTime(file_info.m_ModificationTime);
response.GetHeaders().SetHeader("Last-Modified", last_modified.ToString(NPT_DateTime::FORMAT_RFC_1123), true);
response.GetHeaders().SetHeader("Cache-Control", "max-age=0,must-revalidate", true);
//response.GetHeaders().SetHeader("Cache-Control", "max-age=1800", true);
}
PLT_HttpRequestContext tmp_context(request, context);
return ServeStream(request, context, response, stream, PLT_MimeType::GetMimeType(file_path, &tmp_context));
}
示例8: while
/*----------------------------------------------------------------------
| BtPlayerServer::Run
+---------------------------------------------------------------------*/
void
BtPlayerServer::Run()
{
NPT_Result result;
do {
result = m_Player.PumpMessage();
} while (NPT_SUCCEEDED(result));
}
示例9: while
/*----------------------------------------------------------------------
| PLT_MicroMediaController::PopDirectoryStackToRoot
+---------------------------------------------------------------------*/
void
PLT_MicroMediaController::PopDirectoryStackToRoot(void)
{
NPT_String val;
while (NPT_SUCCEEDED(m_CurBrowseDirectoryStack.Peek(val)) && val.Compare("0")) {
m_CurBrowseDirectoryStack.Pop(val);
}
}
示例10:
const Object *RootContainer::findObject(const NPT_String& id) const
{
Object **obj;
if (NPT_SUCCEEDED(m_objectMap.Get(id, obj))) {
return *obj;
}
return NULL;
}
示例11: PLT_DeviceData
/*----------------------------------------------------------------------
| PLT_DeviceData::SetDescription
+---------------------------------------------------------------------*/
NPT_Result
PLT_DeviceData::SetDescription(PLT_DeviceDataReference& root_device,
NPT_TimeInterval leasetime,
NPT_HttpUrl description_url,
const char* description,
const NPT_HttpRequestContext& context)
{
NPT_XmlParser parser;
NPT_XmlNode* tree = NULL;
NPT_Result res;
NPT_XmlElementNode* root = NULL;
NPT_String URLBase;
// create new device if none passed
if (root_device.IsNull()) {
root_device = new PLT_DeviceData(description_url, "", leasetime);
}
res = parser.Parse(description, tree);
NPT_CHECK_LABEL_SEVERE(res, cleanup);
root = tree->AsElementNode();
if (!root ||
root->GetTag() != "root" ||
!root->GetNamespace() ||
*root->GetNamespace() != "urn:schemas-upnp-org:device-1-0") {
NPT_LOG_INFO_1("root namespace is invalid: %s",
(root&&root->GetNamespace())?root->GetNamespace()->GetChars():"null");
NPT_CHECK_LABEL_SEVERE(NPT_FAILURE, cleanup);
}
// look for optional URLBase element
if (NPT_SUCCEEDED(PLT_XmlHelper::GetChildText(root, "URLBase", URLBase))) {
NPT_HttpUrl url(URLBase);
// Some devices like Connect360 try to be funny - not so
if (url.GetHost().ToLowercase() == "localhost" ||
url.GetHost().ToLowercase() == "127.0.0.1") {
url.SetHost(context.GetRemoteAddress().GetIpAddress().ToString());
}
root_device->SetURLBase(url);
} else {
// No URLBase, derive from description url
root_device->SetURLBase(description_url);
}
// at least one root device child element is required
NPT_XmlElementNode* device;
if (!(device = PLT_XmlHelper::GetChild(root, "device"))) {
NPT_CHECK_LABEL_SEVERE(NPT_FAILURE, cleanup);
}
res = SetDescriptionDevice(root_device, device, context);
cleanup:
// delete the tree
delete tree;
return res;
}
示例12: while
void FrontEnd::SsdpBroadcastTask::exec()
{
while (!aborted()) {
if (NPT_SUCCEEDED(m_waitVar.WaitWhileEquals(0, 5000))) {
break;
}
m_owner->broadcastIfNecessary();
}
}
示例13: PLT_ServiceEventSubURLFinder
/*----------------------------------------------------------------------
| PLT_DeviceData::FindServiceByEventSubURI
+---------------------------------------------------------------------*/
NPT_Result
PLT_DeviceData::FindServiceByEventSubURI(const char* uri,
PLT_Service*& service)
{
if (NPT_SUCCEEDED(NPT_ContainerFind(m_Services,
PLT_ServiceEventSubURLFinder(uri),
service))) {
return NPT_SUCCESS;
}
for (int i=0; i < (int)m_EmbeddedDevices.GetItemCount(); i++) {
if (NPT_SUCCEEDED(NPT_ContainerFind(m_EmbeddedDevices[i]->m_Services,
PLT_ServiceEventSubURLFinder(uri),
service)))
return NPT_SUCCESS;
}
return NPT_FAILURE;
}
示例14: NPT_LOG_WARNING_2
/*----------------------------------------------------------------------
| PLT_MediaBrowser::OnDeviceAdded
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::OnDeviceAdded(PLT_DeviceDataReference& device)
{
// verify the device implements the function we need
PLT_Service* serviceCDS;
PLT_Service* serviceCMR;
NPT_String type;
if (!device->GetType().StartsWith("urn:schemas-upnp-org:device:MediaServer"))
return NPT_FAILURE;
type = "urn:schemas-upnp-org:service:ContentDirectory:*";
if (NPT_FAILED(device->FindServiceByType(type, serviceCDS))) {
NPT_LOG_WARNING_2("Service %s not found in device \"%s\"",
type.GetChars(),
device->GetFriendlyName().GetChars());
return NPT_FAILURE;
} else {
// in case it's a newer upnp implementation, force to 1
serviceCDS->ForceVersion(1);
}
type = "urn:schemas-upnp-org:service:ConnectionManager:*";
if (NPT_FAILED(device->FindServiceByType(type, serviceCMR))) {
NPT_LOG_WARNING_2("Service %s not found in device \"%s\"",
type.GetChars(),
device->GetFriendlyName().GetChars());
return NPT_FAILURE;
} else {
// in case it's a newer upnp implementation, force to 1
serviceCMR->ForceVersion(1);
}
{
NPT_AutoLock lock(m_MediaServers);
PLT_DeviceDataReference data;
NPT_String uuid = device->GetUUID();
// is it a new device?
if (NPT_SUCCEEDED(NPT_ContainerFind(m_MediaServers, PLT_DeviceDataFinder(uuid), data))) {
NPT_LOG_WARNING_1("Device (%s) is already in our list!", (const char*)uuid);
return NPT_FAILURE;
}
NPT_LOG_FINE_1("Device Found: %s", (const char*)*device);
m_MediaServers.Add(device);
}
if (m_Delegate && m_Delegate->OnMSAdded(device)) {
m_CtrlPoint->Subscribe(serviceCDS);
m_CtrlPoint->Subscribe(serviceCMR);
}
return NPT_SUCCESS;
}
示例15: NPT_ContainerFind
/*----------------------------------------------------------------------
| PLT_DeviceData::FindEmbeddedDeviceByType
+---------------------------------------------------------------------*/
NPT_Result
PLT_DeviceData::FindEmbeddedDeviceByType(const char* type,
PLT_DeviceDataReference& device)
{
NPT_Result res = NPT_ContainerFind(m_EmbeddedDevices,
PLT_DeviceDataFinderByType(type),
device);
if (NPT_SUCCEEDED(res)) return res;
for (int i=0; i<(int)m_EmbeddedDevices.GetItemCount(); i++) {
res = m_EmbeddedDevices[i]->FindEmbeddedDeviceByType(
type,
device);
if (NPT_SUCCEEDED(res)) return res;
}
return NPT_FAILURE;
}