本文整理汇总了C++中CpiSubscription::RemoveRef方法的典型用法代码示例。如果您正苦于以下问题:C++ CpiSubscription::RemoveRef方法的具体用法?C++ CpiSubscription::RemoveRef怎么用?C++ CpiSubscription::RemoveRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CpiSubscription
的用法示例。
在下文中一共展示了CpiSubscription::RemoveRef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
//.........这里部分代码省略.........
catch (AsciiError&) {
const Brx& sid = iHeaderSid.Sid();
LOG2(kEvent, kError, "notification for %.*s failed to include id in path\n", PBUF(sid));
Error(HttpStatus::kPreconditionFailed);
}
subscription = iCpStack.SubscriptionManager().FindSubscription(id);
if (subscription == NULL) {
const Brx& sid = iHeaderSid.Sid();
LOG2(kEvent, kError, "notification for unexpected device - %.*s\n", PBUF(sid))
Error(HttpStatus::kPreconditionFailed);
}
}
catch(HttpError&) {}
catch(ReaderError&) {}
try {
// write response
Sws<128> writerBuffer(*this);
WriterHttpResponse response(writerBuffer);
response.WriteStatus(*iErrorStatus, Http::eHttp11);
response.WriteFlush();
// read entity
if (subscription != NULL) {
Bwh entity;
WriterBwh writer(1024);
if (iHeaderTransferEncoding.IsChunked()) {
iDechunker->SetChunked(true);
for (;;) {
Brn buf = iDechunker->Read(kMaxReadBytes);
writer.Write(buf);
if (buf.Bytes() == 0) { // end of stream
break;
}
}
}
else {
TUint length = iHeaderContentLength.ContentLength();
if (length == 0) {
// no Content-Length header, so read until remote socket closed (so ReaderError is thrown)
try {
for (;;) {
writer.Write(iReaderUntil->Read(kMaxReadBytes));
}
}
catch (ReaderError&) {
}
} else {
TUint remaining = length;
do {
Brn buf = iReaderUntil->Read(kMaxReadBytes);
remaining -= buf.Bytes();
writer.Write(buf);
} while (remaining > 0);
}
}
writer.TransferTo(entity);
// process entity
{
const Brx& sid = iHeaderSid.Sid();
LOG(kEvent, "EventSessionUpnp::Run, sid - %.*s seq - %u\n", PBUF(sid), iHeaderSeq.Seq());
}
/* defer validating the seq number till now to avoid holding subscription's lock during
potentially long-running network reads */
if (subscription->UpdateSequenceNumber(iHeaderSeq.Seq())) {
try {
ProcessNotification(*subscription, entity);
}
catch (Exception& ex) {
Log::Print("EventSessionUpnp::Run() unexpected exception %s from %s:%u\n", ex.Message(), ex.File(), ex.Line());
ASSERTS(); // ProcessNotification isn't expected to throw
}
subscription->Unlock();
}
else {
subscription->SetNotificationError();
}
}
}
catch(HttpError&) {
LogError(subscription, "HttpError");
}
catch(ReaderError&) {
LogError(subscription, "ReaderError");
}
catch(WriterError&) {
LogError(subscription, "WriterError");
}
catch(NetworkError&) {
LogError(subscription, "NetworkError");
}
catch(XmlError&) {
LogError(subscription, "XmlError");
}
if (subscription != NULL) {
subscription->RemoveRef();
}
}
示例2: Run
void EventSessionUpnp::Run()
{
CpiSubscription* subscription = NULL;
iErrorStatus = &HttpStatus::kOk;
try {
iReaderRequest->Flush();
iReaderRequest->Read();
// check headers
if (iReaderRequest->MethodNotAllowed()) {
Error(HttpStatus::kBadRequest);
}
if (!iHeaderNt.Received() || !iHeaderNts.Received()) {
Error(HttpStatus::kBadRequest);
}
if (iHeaderNt.Value() != kExpectedNt || iHeaderNts.Value() != kExpectedNts ||
!iHeaderSid.Received() || iHeaderSid.Sid().Bytes() == 0 || !iHeaderSeq.Received()) {
Error(HttpStatus::kPreconditionFailed);
}
subscription = CpiSubscriptionManager::FindSubscription(iHeaderSid.Sid());
if (subscription == NULL) {
/* the UPnP spec contains a potential race condition where the first NOTIFY
message can be processed ahead of the SUBSCRIBE reply which provides
the sid. Wait until any in-progress subscriptions complete and try
again in case that's what has happened here */
CpiSubscriptionManager::WaitForPendingAdds();
subscription = CpiSubscriptionManager::FindSubscription(iHeaderSid.Sid());
if (subscription == NULL) {
LOG2(kEvent, kError, "notification for unexpected device - ")
LOG2(kEvent, kError, iHeaderSid.Sid());
LOG2(kEvent, kError, "\n");
Error(HttpStatus::kPreconditionFailed);
}
}
if (!subscription->UpdateSequenceNumber(iHeaderSeq.Seq())) {
subscription->SetNotificationError();
subscription->RemoveRef();
subscription = NULL;
}
}
catch(HttpError) {}
catch(ReaderError) {}
try {
// write response
Sws<128> writerBuffer(*this);
WriterHttpResponse response(writerBuffer);
response.WriteStatus(*iErrorStatus, Http::eHttp11);
response.WriteFlush();
// read entity
if (subscription != NULL) {
Bwh entity;
if (iHeaderTransferEncoding.IsChunked()) {
ReaderHttpChunked dechunker(*iReadBuffer);
dechunker.Read();
dechunker.TransferTo(entity);
}
else {
TUint length = iHeaderContentLength.ContentLength();
if (length == 0) {
THROW(HttpError);
}
entity.Grow(length);
while (length > 0) {
TUint readBytes = (length<kMaxReadBytes? length : kMaxReadBytes);
entity.Append(iReadBuffer->Read(readBytes));
length -= readBytes;
}
}
// process entity
LOG(kEvent, "EventSessionUpnp::Run, sid - ");
LOG(kEvent, iHeaderSid.Sid());
LOG(kEvent, " seq - %u\n", iHeaderSeq.Seq());
ProcessNotification(*subscription, entity);
}
}
catch(HttpError) {
LogError(subscription, "HttpError");
}
catch(ReaderError) {
LogError(subscription, "ReaderError");
}
catch(WriterError) {
LogError(subscription, "WriterError");
}
catch(NetworkError) {
LogError(subscription, "NetworkError");
}
catch(XmlError) {
LogError(subscription, "XmlError");
}
if (subscription != NULL) {
subscription->RemoveRef();
}
}
示例3: HandleEventedUpdate
void CpiDeviceLpec::HandleEventedUpdate(const Brx& aUpdate)
{
Parser parser(aUpdate);
Brn lpecId = parser.Next(' ');
Bws<128> sid(iDevice->Udn());
sid.Append('-');
sid.Append(lpecId);
CpiSubscription* subscription = iCpStack.SubscriptionManager().FindSubscription(sid);
if (subscription == NULL) {
/* There is a very short window between Subscribe() returning and the new
subscription being added to its manager. As a lazy workaround for this,
sleep for a short period and retry before rejecting the update */
Thread::Sleep(1000);
subscription = iCpStack.SubscriptionManager().FindSubscription(sid);
}
if (subscription == NULL) {
LOG(kLpec, "LPEC: evented update received for unknown subscription - ");
LOG(kLpec, sid);
LOG(kLpec, "\n");
return;
}
Brn seqBuf = parser.Next(' ');
TUint seq;
try {
seq = Ascii::Uint(seqBuf);
}
catch (AsciiError&) {
LOG(kLpec, "LPEC: invalid sequence number - ");
LOG(kLpec, seqBuf);
LOG(kLpec, "in evented update\n");
subscription->RemoveRef();
return;
}
if (!subscription->UpdateSequenceNumber(seq)) {
LOG(kLpec, "LPEC: out of sequence update (%d) for ", seq);
LOG(kLpec, sid);
LOG(kLpec, "\n");
subscription->SetNotificationError();
subscription->RemoveRef();
return;
}
IEventProcessor* processor = static_cast<IEventProcessor*>(subscription);
processor->EventUpdateStart();
OutputProcessor outputProcessor;
try {
for (;;) {
Brn propName = parser.Next(' ');
if (propName.Bytes() == 0) {
// processed entire update
break;
}
(void)parser.Next(Lpec::kArgumentDelimiter);
Brn propVal = parser.Next(Lpec::kArgumentDelimiter);
processor->EventUpdate(propName, propVal, outputProcessor);
}
processor->EventUpdateEnd();
}
catch (AsciiError&) {
LOG2(kLpec, kError, "LPEC: Invalid evented update - ");
LOG2(kLpec, kError, aUpdate);
LOG2(kLpec, kError, "\n");
processor->EventUpdateError();
}
subscription->Unlock();
subscription->RemoveRef();
}