本文整理汇总了C++中HttpRequest::AddHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpRequest::AddHandler方法的具体用法?C++ HttpRequest::AddHandler怎么用?C++ HttpRequest::AddHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::AddHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
bool
Application::GetResource (const Uri *resourceBase, const Uri *uri,
NotifyFunc notify_cb, EventHandler write_cb,
DownloaderAccessPolicy policy, HttpRequest::Options options,
Cancellable *cancellable, gpointer user_data)
{
if (!uri) {
g_warning ("Passing a null uri to Application::GetResource");
if (notify_cb)
notify_cb (NotifyFailed, GPOINTER_TO_INT(NULL), user_data);
return false;
}
if (get_resource_cb && !uri->IsAbsolute ()) {
ManagedStreamCallbacks stream;
if (!Uri::IsNullOrEmpty (uri)) {
stream = get_resource_cb (resourceBase, uri);
} else {
memset (&stream, 0, sizeof (stream));
}
if (stream.handle) {
if (notify_cb)
notify_cb (NotifyStarted, GPOINTER_TO_INT(NULL), user_data);
if (write_cb) {
char buf[4096];
int offset = 0;
int nread;
if (stream.CanSeek (stream.handle))
stream.Seek (stream.handle, 0, 0);
HttpRequestWriteEventArgs *args = new HttpRequestWriteEventArgs (NULL, 0, 0);
do {
if ((nread = stream.Read (stream.handle, buf, 0, sizeof (buf))) <= 0)
break;
args->SetData (buf);
args->SetOffset (offset);
args->SetCount (nread);
write_cb (this, args, user_data);
offset += nread;
} while (true);
args->unref ();
}
if (notify_cb)
notify_cb (NotifyCompleted, GPOINTER_TO_INT(NULL), user_data);
stream.Close (stream.handle);
return true;
}
}
#if 0
// FIXME: drt 171 and 173 expect this to fail simply because the uri
// begins with a '/', but other drts (like 238) depend on this
// working. I give up.
if (!uri->isAbsolute && uri->path && uri->path[0] == '/') {
if (notify_cb)
notify_cb (NotifyFailed, NULL, user_data);
return false;
}
#endif
//no get_resource_cb or empty stream
HttpRequest *request;
if (!(request = GetDeployment ()->CreateHttpRequest (options))) {
if (notify_cb)
notify_cb (NotifyFailed, GPOINTER_TO_INT(NULL), user_data);
return false;
}
NotifyCtx *ctx = g_new (NotifyCtx, 1);
ctx->user_data = user_data;
ctx->notify_cb = notify_cb;
ctx->write_cb = write_cb;
ctx->request = request;
if (notify_cb) {
request->AddHandler (HttpRequest::ProgressChangedEvent, application_downloader_progress_changed, ctx);
request->AddHandler (HttpRequest::StartedEvent, application_downloader_started, ctx);
}
if (cancellable) {
cancellable->SetCancelFuncAndData (application_downloader_abort, request, ctx);
}
request->AddHandler (HttpRequest::WriteEvent, application_downloader_write, ctx);
request->AddHandler (HttpRequest::StoppedEvent, application_downloader_stopped, ctx);
request->Open ("GET", uri, resourceBase, policy);
request->Send ();
return true;
}