Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Properties | Methods | Protected Attributes
URLSessionTask Struct Reference

#include <URLSessionTask.h>

Overview

URL session tasks are handles to pending URL operations.

Definition at line 68 of file URLSessionTask.h.

Inheritance diagram for URLSessionTask:
Object URLSessionDataTask URLSessionDownloadTask URLSessionUploadTask

Properties

size_t bytesExpectedToReceive
 The count of bytes this task expects to receive. More...
 
size_t bytesExpectedToSend
 The count of bytes this task expects to send. More...
 
size_t bytesReceived
 The count of bytes received. More...
 
size_t bytesSent
 The count of bytes sent. More...
 
URLSessionTaskCompletion completion
 The completion function. More...
 
ident data
 User data. More...
 
char * error
 The error buffer. More...
 
Object object
 The superclass. More...
 
URLSessionTaskProgress progress
 The progress function. More...
 
struct URLRequestrequest
 The request. More...
 
struct URLResponseresponse
 The response. More...
 
struct URLSessionsession
 The session. More...
 
URLSessionTaskState state
 The state. More...
 
ident handle
 The backing libcurl handle. More...
 
ident requestHeaders
 HTTP headers, in libcurl list structure. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_URLSessionTask (void)
 The URLSessionTask archetype. More...
 
void cancel (URLSessionTask *)
 Cancels this task. More...
 
void execute (URLSessionTask *)
 Executes this task synchronously, on the calling thread. More...
 
URLSessionTaskinitWithRequestInSession (URLSessionTask *, struct URLRequest *, struct URLSession *, URLSessionTaskCompletion)
 Initializes this task with the given URLRequest. More...
 
void resume (URLSessionTask *)
 Starts or resumes this task. More...
 
void setup (URLSessionTask *)
 Sets up this task. More...
 
void suspend (URLSessionTask *)
 Suspends this task. More...
 
void teardown (URLSessionTask *)
 Tears down this task. More...
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype. More...
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object. More...
 
void dealloc (Object *self)
 Frees all resources held by this Object. More...
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object. More...
 
_Bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object. More...
 
_Bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership. More...
 

Protected Attributes

URLSessionTaskInterface * interface
 The interface. More...
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface. More...
 

Property Details

◆ bytesExpectedToReceive

size_t URLSessionTask::bytesExpectedToReceive

The count of bytes this task expects to receive.

Definition at line 99 of file URLSessionTask.h.

◆ bytesExpectedToSend

size_t URLSessionTask::bytesExpectedToSend

The count of bytes this task expects to send.

Definition at line 104 of file URLSessionTask.h.

◆ bytesReceived

size_t URLSessionTask::bytesReceived

The count of bytes received.

Definition at line 109 of file URLSessionTask.h.

◆ bytesSent

size_t URLSessionTask::bytesSent

The count of bytes sent.

Definition at line 114 of file URLSessionTask.h.

◆ completion

URLSessionTaskCompletion URLSessionTask::completion

The completion function.

Definition at line 119 of file URLSessionTask.h.

◆ data

ident URLSessionTask::data ( void  )

User data.

Definition at line 124 of file URLSessionTask.h.

◆ error

char* URLSessionTask::error

The error buffer.

Definition at line 129 of file URLSessionTask.h.

◆ handle

ident URLSessionTask::handle

The backing libcurl handle.

Definition at line 88 of file URLSessionTask.h.

◆ interface

URLSessionTaskInterface* URLSessionTask::interface
protected

The interface.

Definition at line 79 of file URLSessionTask.h.

◆ object

Object URLSessionTask::object

The superclass.

Definition at line 73 of file URLSessionTask.h.

◆ progress

URLSessionTaskProgress URLSessionTask::progress

The progress function.

Definition at line 134 of file URLSessionTask.h.

◆ request

struct URLRequest* URLSessionTask::request

The request.

Definition at line 139 of file URLSessionTask.h.

◆ requestHeaders

ident URLSessionTask::requestHeaders

HTTP headers, in libcurl list structure.

Definition at line 93 of file URLSessionTask.h.

◆ response

struct URLResponse* URLSessionTask::response

The response.

Definition at line 144 of file URLSessionTask.h.

◆ session

struct URLSession* URLSessionTask::session

The session.

Definition at line 149 of file URLSessionTask.h.

◆ state

URLSessionTaskState URLSessionTask::state

The state.

Definition at line 154 of file URLSessionTask.h.

Method Details

◆ _URLSessionTask()

Class * _URLSessionTask ( void  )

The URLSessionTask archetype.

Returns
The URLSessionTask Class.

Definition at line 324 of file URLSessionTask.c.

324 {
325 static Class *clazz;
326 static Once once;
327
328 do_once(&once, {
329 clazz = _initialize(&(const ClassDef) {
330 .name = "URLSessionTask",
331 .superclass = _Object(),
332 .instanceSize = sizeof(URLSessionTask),
333 .interfaceOffset = offsetof(URLSessionTask, interface),
334 .interfaceSize = sizeof(URLSessionTaskInterface),
336 });
337 });
338
339 return clazz;
340}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
long Once
The Once type.
Definition: Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition: Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition: Class.h:41
The runtime representation of a Class.
Definition: Class.h:95
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition: Object.h:51
Class * _Object(void)
The Object archetype.
Definition: Object.c:136
URL session tasks are handles to pending URL operations.
URLSessionTaskInterface * interface
The interface.

◆ cancel()

void cancel ( URLSessionTask self)

Cancels this task.

Parameters
selfThe URLSessionTask.

Definition at line 70 of file URLSessionTask.c.

70 {
71
72 switch (self->state) {
78 break;
79 default:
80 break;
81 }
82}
@ URLSESSIONTASK_RESUMING
@ URLSESSIONTASK_SUSPENDING
@ URLSESSIONTASK_SUSPENDED
@ URLSESSIONTASK_RESUMED
@ URLSESSIONTASK_CANCELING
URLSessionTaskState state
The state.

◆ execute()

void execute ( URLSessionTask self)

Executes this task synchronously, on the calling thread.

Parameters
selfThe URLSessionTask.
Remarks
Do not mix calls to execute with calls to resume.

Definition at line 88 of file URLSessionTask.c.

88 {
89
90 $(self, setup);
91
92 curl_easy_perform(self->locals.handle);
93
94 curl_easy_getinfo(self->locals.handle, CURLINFO_RESPONSE_CODE, (long *) &self->response->httpStatusCode);
95
97
98 $(self, teardown);
99}
@ URLSESSIONTASK_COMPLETED
int httpStatusCode
The HTTP response status code.
Definition: URLResponse.h:63
struct URLResponse * response
The response.
ident handle
The backing libcurl handle.
void setup(URLSessionTask *)
Sets up this task.
void teardown(URLSessionTask *)
Tears down this task.

◆ initWithRequestInSession()

URLSessionTask * initWithRequestInSession ( URLSessionTask self,
struct URLRequest request,
struct URLSession session,
URLSessionTaskCompletion  completion 
)

Initializes this task with the given URLRequest.

Parameters
selfThe URLSessionTask.
requestThe request.
sessionThe session.
completionThe completion handler.
Returns
The initialized task, or NULL on error.

Definition at line 105 of file URLSessionTask.c.

106 {
107
108 assert(request);
109 assert(session);
110
111 self = (URLSessionTask *) super(Object, self, init);
112 if (self) {
113
114 self->error = calloc(1, CURL_ERROR_SIZE);
115 assert(self->error);
116
117 self->request = retain(request);
118 self->session = retain(session);
119
120 self->response = $(alloc(URLResponse), init);
121
122 self->completion = completion;
123
125 }
126
127 return self;
128}
ident retain(ident obj)
Atomically increment the given Object's reference count.
Definition: Class.c:211
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
#define super(type, obj, method,...)
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
Object * init(Object *self)
Initializes this Object.
Definition: Object.c:83
A protocol-agnostic abstraction for URLSessionTask responses.
Definition: URLResponse.h:42
char * error
The error buffer.
struct URLRequest * request
The request.
struct URLSession * session
The session.
URLSessionTaskCompletion completion
The completion function.

◆ resume()

void resume ( URLSessionTask self)

Starts or resumes this task.

Parameters
selfThe URLSessionTask.

Definition at line 134 of file URLSessionTask.c.

134 {
135
136 switch (self->state) {
140 break;
141 default:
142 break;
143 }
144}

◆ setup()

void setup ( URLSessionTask self)

Sets up this task.

Parameters
selfThe URLSessionTask.

Definition at line 75 of file URLSessionDataTask.c.

75 {
76
78
79 curl_easy_setopt(self->locals.handle, CURLOPT_WRITEFUNCTION, writeFunction);
80 curl_easy_setopt(self->locals.handle, CURLOPT_WRITEDATA, self);
81}
static size_t writeFunction(char *data, size_t size, size_t count, ident self)
The CURLOPT_WRITEFUNCTION callback.

◆ suspend()

void suspend ( URLSessionTask self)

Suspends this task.

Parameters
selfThe URLSessionTask.

Definition at line 272 of file URLSessionTask.c.

272 {
273
274 switch (self->state) {
278 break;
279 default:
280 break;
281 }
282}

◆ teardown()

void teardown ( URLSessionTask self)

Tears down this task.

Parameters
selfThe URLSessionTask.

Definition at line 288 of file URLSessionTask.c.

288 {
289
290 if (self->locals.handle) {
291 curl_easy_cleanup(self->locals.handle);
292 self->locals.handle = NULL;
293 }
294
295 if (self->locals.requestHeaders) {
296 curl_slist_free_all(self->locals.requestHeaders);
297 self->locals.requestHeaders = NULL;
298 }
299}
ident requestHeaders
HTTP headers, in libcurl list structure.

The documentation for this struct was generated from the following files: