本文整理汇总了C++中DeviceList::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ DeviceList::clear方法的具体用法?C++ DeviceList::clear怎么用?C++ DeviceList::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeviceList
的用法示例。
在下文中一共展示了DeviceList::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: discover
int DeviceDiscoverer::discover(
DeviceList& devices, const char* searchTarget, uint32_t timeout, int count)
{
int rval = -1;
// prepare device list
devices->setType(Array);
devices->clear();
// create SSDP request
HttpRequestHeader requestHeader;
createRequest(searchTarget, &requestHeader);
// create socket for sending request
DatagramSocket socket;
// bind to any available port
InternetAddressRef localAddr = new InternetAddress("0.0.0.0", 0);
if(socket.bind(&(*localAddr)))
{
// create the group address
InternetAddressRef groupAddr = new InternetAddress(
SSDP_MULTICAST_ADDRESS, SSDP_MULTICAST_PORT);
// create and send discover request datagram
DatagramRef request = new Datagram(groupAddr);
request->assignString(requestHeader.toString().c_str());
MO_CAT_DEBUG(MO_UPNP_CAT, "Sending UPnP request:\n%s",
requestHeader.toString().c_str());
if(socket.send(request))
{
// no devices yet
rval = 0;
// use timer to comply with user-supplied timeout
Timer timer;
timer.start();
uint32_t remaining = timeout;
InternetAddressRef addr = new InternetAddress();
while(rval >= 0 && remaining > 0 && (count == 0 || rval < count))
{
// set receive timeout and try to get ssdp responses
socket.setReceiveTimeout(remaining);
DatagramRef response = new Datagram(addr);
response->getBuffer()->resize(2048);
if(!socket.receive(response))
{
// check last exception
ExceptionRef e = Exception::get();
if(e->isType("monarch.net.SocketTimeout"))
{
MO_CAT_DEBUG(MO_UPNP_CAT, "UPnP request timed out.");
// exception indicates timed out
remaining = 0;
}
else
{
MO_CAT_ERROR(MO_UPNP_CAT,
"UPnP request error: %s",
JsonWriter::writeToString(
Exception::getAsDynamicObject()).c_str());
// some error other than a timeout
rval = -1;
}
}
else
{
// parse ssdp response
MO_CAT_DEBUG(MO_UPNP_CAT, "Received UPnP response:\n%s",
response->getString().c_str());
Device device = parseDevice(response->getString().c_str());
if(device.isNull())
{
MO_CAT_ERROR(MO_UPNP_CAT,
"UPnP response parse error: %s",
JsonWriter::writeToString(
Exception::getAsDynamicObject()).c_str());
// error in parsing
rval = -1;
}
else
{
MO_CAT_DEBUG(MO_UPNP_CAT,
"Found UPnP device: %s",
JsonWriter::writeToString(device).c_str());
// another device found
++rval;
devices->append(device);
// update remaining time (must be within 32-bit integer range)
remaining = (uint32_t)timer.getRemainingMilliseconds(timeout);
}
}
}
}
//.........这里部分代码省略.........