本文整理汇总了C++中NPT_List::GetFirstItem方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_List::GetFirstItem方法的具体用法?C++ NPT_List::GetFirstItem怎么用?C++ NPT_List::GetFirstItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_List
的用法示例。
在下文中一共展示了NPT_List::GetFirstItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
/*
* Presents a list to the user, allows the user to choose one item.
*
* Parameters:
* PLT_StringMap: A map that contains the set of items from
* which the user should choose. The key should be a unique ID,
* and the value should be a string describing the item.
* returns a NPT_String with the unique ID.
*/
const char*
PLT_MicroMediaController::ChooseIDFromTable(PLT_StringMap& table)
{
printf("Select one of the following:\n");
NPT_List<PLT_StringMapEntry*> entries = table.GetEntries();
if (entries.GetItemCount() == 0) {
printf("None available\n");
} else {
// display the list of entries
NPT_List<PLT_StringMapEntry*>::Iterator entry = entries.GetFirstItem();
int count = 0;
while (entry) {
printf("%d)\t%s (%s)\n", ++count, (const char*)(*entry)->GetValue(), (const char*)(*entry)->GetKey());
++entry;
}
int index, watchdog = 3;
char buffer[1024];
// wait for input
/*while (watchdog > 0) {
fgets(buffer, 1024, stdin);
strchomp(buffer);
if (1 != sscanf(buffer, "%d", &index)) {
printf("Please enter a number\n");
} else if (index < 0 || index > count) {
printf("Please choose one of the above, or 0 for none\n");
watchdog--;
index = 0;
} else {
watchdog = 0;
}
}*/
index = 1;
// find the entry back
if (index != 0) {
entry = entries.GetFirstItem();
while (entry && --index) {
++entry;
}
if (entry) {
return (*entry)->GetKey();
}
}
}
return NULL;
}
示例2: while
/*----------------------------------------------------------------------
| NPT_PosixQueue::Peek
+---------------------------------------------------------------------*/
NPT_Result
NPT_PosixQueue::Peek(NPT_QueueItem*& item, NPT_Timeout timeout)
{
struct timespec timed;
if (timeout != NPT_TIMEOUT_INFINITE) {
NPT_CHECK(GetTimeOut(timeout, timed));
}
// lock the mutex that protects the list
if (pthread_mutex_lock(&m_Mutex)) {
return NPT_FAILURE;
}
NPT_Result result = NPT_SUCCESS;
NPT_List<NPT_QueueItem*>::Iterator head = m_Items.GetFirstItem();
if (timeout) {
while (!head) {
// no item in the list, wait for one
++m_PoppersWaitingCount;
if (timeout == NPT_TIMEOUT_INFINITE) {
pthread_cond_wait(&m_CanPopCondition, &m_Mutex);
--m_PoppersWaitingCount;
} else {
int wait_res = pthread_cond_timedwait(&m_CanPopCondition,
&m_Mutex,
&timed);
--m_PoppersWaitingCount;
if (wait_res == ETIMEDOUT) {
result = NPT_ERROR_TIMEOUT;
break;
}
}
if (m_Aborting) {
result = NPT_ERROR_INTERRUPTED;
break;
}
head = m_Items.GetFirstItem();
}
} else {
if (!head) result = NPT_ERROR_LIST_EMPTY;
}
item = head?*head:NULL;
// unlock the mutex
pthread_mutex_unlock(&m_Mutex);
return result;
}
示例3: while
/*----------------------------------------------------------------------
| PLT_StateVariable::ValidateValue
+---------------------------------------------------------------------*/
NPT_Result
PLT_StateVariable::ValidateValue(const char* value)
{
if (m_DataType.Compare("string", true) == 0) {
// if we have a value allowed restriction, make sure the value is in our list
if (m_AllowedValues.GetItemCount()) {
// look for a comma separated list
NPT_String _value = value;
NPT_List<NPT_String> values = _value.Split(",");
NPT_List<NPT_String>::Iterator val = values.GetFirstItem();
while (val) {
val->Trim(" ");
if (!m_AllowedValues.Find(NPT_StringFinder(*val))) {
#if defined(NPT_CONFIG_ENABLE_LOGGING)
NPT_LOG_WARNING_2("Invalid value of %s for state variable %s",
(const char*)*val,
(const char*)m_Name);
for (unsigned long i=0; i < m_AllowedValues.GetItemCount(); i++) {
NPT_String *val2 = *m_AllowedValues.GetItem(i);
NPT_LOG_WARNING_1("Allowed: %s", (const char*)*val2);
}
#endif
return NPT_ERROR_INVALID_PARAMETERS;
}
++val;
}
}
}
// TODO: there are more to it than allowed values, we need to test for range, etc..
return NPT_SUCCESS;
}
示例4: dir
/*----------------------------------------------------------------------
| NPT_File::RemoveDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::RemoveDir(const char* path, bool force_if_not_empty)
{
NPT_String root_path = path;
// normalize path separators
root_path.Replace((NPT_FilePath::Separator[0] == '/')?'\\':'/', NPT_FilePath::Separator);
// remove superfluous delimiters at the end
root_path.TrimRight(NPT_FilePath::Separator);
// remove all entries in the directory if required
if (force_if_not_empty) {
// enumerate all entries
NPT_File dir(root_path);
NPT_List<NPT_String> entries;
NPT_CHECK_WARNING(dir.ListDir(entries));
for (NPT_List<NPT_String>::Iterator it = entries.GetFirstItem(); it; ++it) {
NPT_File::Remove(NPT_FilePath::Create(root_path, *it), true);
}
}
// remove the (now empty) directory
return NPT_File::RemoveDir(root_path);
}
示例5: while
/*----------------------------------------------------------------------
| PLT_MediaServer::ParseSort
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaServer::ParseSort(const NPT_String& sort, NPT_List<NPT_String>& list)
{
// reset output params first
list.Clear();
// easy out
if (sort.GetLength() == 0 || sort == "*") return NPT_SUCCESS;
list = sort.Split(",");
// verify each property has a namespace
NPT_List<NPT_String>::Iterator property = list.GetFirstItem();
while (property) {
NPT_List<NPT_String> parsed_property = (*property).Split(":");
if (parsed_property.GetItemCount() != 2)
parsed_property = (*property).Split("@");
if (parsed_property.GetItemCount() != 2 ||
(!(*property).StartsWith("-") && !(*property).StartsWith("+"))) {
NPT_LOG_WARNING_1("Invalid SortCriteria property %s", (*property).GetChars());
return NPT_FAILURE;
}
property++;
}
return NPT_SUCCESS;
}
示例6: if
/*----------------------------------------------------------------------
| 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();
}
示例7: while
/*----------------------------------------------------------------------
| NPT_Win32Queue::Peek
+---------------------------------------------------------------------*/
NPT_Result
NPT_Win32Queue::Peek(NPT_QueueItem*& item, NPT_Timeout timeout)
{
// default value
item = NULL;
// lock the mutex that protects the list
NPT_CHECK(m_Mutex.Lock());
NPT_Result result = NPT_SUCCESS;
NPT_List<NPT_QueueItem*>::Iterator head = m_Items.GetFirstItem();
if (timeout) {
while (!head) {
// no item in the list, wait for one
// reset the condition to indicate that the queue is empty
m_CanPopCondition->Reset();
// unlock the mutex so that another thread can push
m_Mutex.Unlock();
// wait for the condition to signal that we can pop
NPT_Result result = m_CanPopCondition->Wait(timeout);
if (NPT_FAILED(result)) return result;
// relock the mutex so that we can check the list again
NPT_CHECK(m_Mutex.Lock());
// try again
head = m_Items.GetFirstItem();
}
} else {
if (!head) result = NPT_ERROR_LIST_EMPTY;
}
if (head) item = *head;
// unlock the mutex
m_Mutex.Unlock();
return result;
}
示例8: while
/*----------------------------------------------------------------------
| NPT_String::Join
+---------------------------------------------------------------------*/
NPT_String
NPT_String::Join(NPT_List<NPT_String>& args, const char* separator)
{
NPT_String output;
NPT_List<NPT_String>::Iterator arg = args.GetFirstItem();
while (arg) {
output += *arg;
if (++arg) output += separator;
}
return output;
}
示例9: protocol
/*----------------------------------------------------------------------
| PLT_MediaController::FindMatchingProtocolInfo
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::FindMatchingProtocolInfo(NPT_List<NPT_String>& sinks,
const char* protocol_info)
{
PLT_ProtocolInfo protocol(protocol_info);
for (NPT_List<NPT_String>::Iterator iter = sinks.GetFirstItem();
iter;
iter++) {
PLT_ProtocolInfo sink(*iter);
if (sink.Match(protocol)) return NPT_SUCCESS;
}
return NPT_ERROR_NO_SUCH_ITEM;
}
示例10: xml
/*----------------------------------------------------------------------
| PLT_MediaServer::ParseTagList
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaServer::ParseTagList(const NPT_String& updates, NPT_Map<NPT_String,NPT_String>& tags)
{
// reset output params first
tags.Clear();
NPT_List<NPT_String> split = updates.Split(",");
NPT_XmlNode* node = NULL;
NPT_XmlElementNode* didl_partial = NULL;
NPT_XmlParser parser;
// as these are single name value pairs, separated by commas we wrap in a tag
// to create a valid tree
NPT_String xml("<TagValueList>");
for (NPT_List<NPT_String>::Iterator entry = split.GetFirstItem(); entry; entry++) {
NPT_String& element = (*entry);
if (element.IsEmpty())
xml.Append("<empty>empty</empty>");
else
xml.Append(element);
}
xml.Append("</TagValueList>");
NPT_LOG_FINE("Parsing TagList...");
NPT_CHECK_LABEL_SEVERE(parser.Parse(xml, node), cleanup);
if (!node || !node->AsElementNode()) {
NPT_LOG_SEVERE("Invalid node type");
goto cleanup;
}
didl_partial = node->AsElementNode();
if (didl_partial->GetTag().Compare("TagValueList", true)) {
NPT_LOG_SEVERE("Invalid node tag");
goto cleanup;
}
for (NPT_List<NPT_XmlNode*>::Iterator children = didl_partial->GetChildren().GetFirstItem(); children; children++) {
NPT_XmlElementNode* child = (*children)->AsElementNode();
if (!child) continue;
tags[child->GetTag()] = *child->GetText();
}
return NPT_SUCCESS;
cleanup:
if (node) delete node;
return NPT_FAILURE;
}
示例11: upnp
/*----------------------------------------------------------------------
| main
+---------------------------------------------------------------------*/
int
main(int /* argc */, char** argv)
{
/* parse command line */
ParseCommandLine(argv+1);
PLT_UPnP upnp(1900, !Options.broadcast);
PLT_DeviceHostReference device(
new PLT_FileMediaServer(
Options.path,
Options.friendly_name?Options.friendly_name:"Platinum UPnP Media Server",
false,
"SAMEDEVICEGUID",
(NPT_UInt16)Options.port)
);
NPT_List<NPT_String> list;
NPT_CHECK_SEVERE(PLT_UPnPMessageHelper::GetIPAddresses(list));
NPT_String ip = *(list.GetFirstItem());
//device->m_PresentationURL = NPT_HttpUrl(ip, 80, "/").ToString();
device->m_ModelDescription = "Platinum File Media Server";
device->m_ModelURL = "http://www.plutinosoft.com/";
device->m_ModelNumber = "1.0";
device->m_ModelName = "Platinum File Media Server";
device->m_Manufacturer = "Plutinosoft";
device->m_ManufacturerURL = "http://www.plutinosoft.com/";
if (Options.broadcast) device->SetBroadcast(true);
upnp.AddDevice(device);
NPT_String uuid = device->GetUUID();
NPT_CHECK_SEVERE(upnp.Start());
NPT_LOG_INFO("Press 'q' to quit.");
char buf[256];
while (gets(buf)) {
if (*buf == 'q')
break;
}
upnp.Stop();
return 0;
}
示例12: GetCurMediaRenderer
/*----------------------------------------------------------------------
| PLT_MicroMediaController::HandleCmd_seek
+---------------------------------------------------------------------*/
void
PLT_MicroMediaController::HandleCmd_seek(const char* command)
{
PLT_DeviceDataReference device;
GetCurMediaRenderer(device);
if (!device.IsNull()) {
// remove first part of command ("seek")
NPT_String target = command;
NPT_List<NPT_String> args = target.Split(" ");
if (args.GetItemCount() < 2) return;
args.Erase(args.GetFirstItem());
target = NPT_String::Join(args, " ");
Seek(device, 0, (target.Find(":")!=-1)?"REL_TIME":"X_DLNA_REL_BYTE", target, NULL);
}
}
示例13: if
/*----------------------------------------------------------------------
| CUPnP::CUPnP
+---------------------------------------------------------------------*/
CUPnP::CUPnP() :
m_MediaBrowser(NULL),
m_ServerHolder(new CDeviceHostReferenceHolder()),
m_RendererHolder(new CRendererReferenceHolder()),
m_CtrlPointHolder(new CCtrlPointReferenceHolder())
{
// initialize upnp context
m_UPnP = new PLT_UPnP();
// keep main IP around
m_IP = g_application.getNetworkManager().GetDefaultConnectionAddress().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.IsEmpty())
m_IP = "localhost";
// start upnp monitoring
m_UPnP->Start();
}
示例14: Start
/*----------------------------------------------------------------------
| PLT_FileMediaServer::Start
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::Start(PLT_SsdpListenTask* task)
{
// start our file server
m_FileServer = new PLT_HttpServer(m_FileServerPort);
NPT_CHECK_SEVERE(m_FileServer->Start());
m_FileServer->AddRequestHandler(m_FileServerHandler, "/", true);
// FIXME: hack for now: find the first valid non local ip address
// to use in item resources. TODO: we should advertise all ips as
// multiple resources instead.
NPT_List<NPT_String> ips;
PLT_UPnPMessageHelper::GetIPAddresses(ips);
if (ips.GetItemCount() == 0) return NPT_ERROR_INTERNAL;
// set the base paths for content and album arts
m_FileBaseUri = NPT_HttpUrl(*ips.GetFirstItem(), m_FileServer->GetPort(), "/content");
m_AlbumArtBaseUri = NPT_HttpUrl(*ips.GetFirstItem(), m_FileServer->GetPort(), "/albumart");
return PLT_MediaServer::Start(task);
}
示例15: SetupResponse
NPT_Result CHttpServer::SetupResponse(NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response)
{
NPT_String prefix = NPT_String::Format("PLT_HttpServer::SetupResponse %s request from %s for \"%s\"",
(const char*) request.GetMethod(),
(const char*) context.GetRemoteAddress().ToString(),
(const char*) request.GetUrl().ToString());
NPT_List<NPT_HttpRequestHandler*> handlers = FindRequestHandlers(request);
if (handlers.GetItemCount() == 0) return NPT_ERROR_NO_SUCH_ITEM;
// ask the handler to setup the response
NPT_Result result = (*handlers.GetFirstItem())->SetupResponse(request, context, response);
// DLNA compliance
UPNPMessageHelper::SetDate(response);
if (request.GetHeaders().GetHeader("Accept-Language")) {
response.GetHeaders().SetHeader("Content-Language", "en");
}
return result;
}