Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Operation.h
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
27#include <Objectively/Object.h>
29
35typedef struct Operation Operation;
36typedef struct OperationInterface OperationInterface;
37
42typedef void (*OperationFunction)(Operation *operation);
43
50struct Operation {
51
56
61 OperationInterface *interface;
62
66 struct {
67
72
77
78 } locals;
79
85
90
95
100
105
110};
111
115struct OperationInterface {
116
120 ObjectInterface objectInterface;
121
129 void (*addDependency)(Operation *self, Operation *dependency);
130
137 void (*cancel)(Operation *self);
138
145 Array *(*dependencies)(const Operation *self);
146
155 Operation *(*init)(Operation *self);
156
166 Operation *(*initWithFunction)(Operation *self, OperationFunction function, ident data);
167
174 _Bool (*isReady)(const Operation *self);
175
183 void (*removeDependency)(Operation *self, Operation *dependency);
184
196 void (*start)(Operation *self);
197
204 void (*waitUntilFinished)(const Operation *self);
205};
206
POSIX Threads conditional variables.
Mutable arrays.
static MutableData * data(void)
Definition: MutableData.c:75
Object is the root Class of The Objectively Class hierarchy.
static void waitUntilFinished(const Operation *self)
Definition: Operation.c:199
static _Bool isReady(const Operation *self)
Definition: Operation.c:134
static void start(Operation *self)
Definition: Operation.c:171
static void cancel(Operation *self)
Definition: Operation.c:74
static void addDependency(Operation *self, Operation *dependency)
Definition: Operation.c:60
void(* OperationFunction)(Operation *operation)
The function type for Operation execution.
Definition: Operation.h:42
void * ident
The identity type, similar to Objective-C id.
Definition: Types.h:49
#define OBJECTIVELY_EXPORT
Definition: Types.h:36
Immutable arrays.
Definition: Array.h:56
The runtime representation of a Class.
Definition: Class.h:95
POSIX Threads conditional variables.
Definition: Condition.h:44
Mutable arrays.
Definition: MutableArray.h:40
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
An abstraction for discrete units of work, or tasks.
Definition: Operation.h:50
ident data
The user data.
Definition: Operation.h:89
Condition * condition
The Condition enabling waitUntilFinished.
Definition: Operation.h:71
_Bool isCancelled
true when this Operation has been cancelled, false otherwise.
Definition: Operation.h:99
OperationFunction function
The Operation function.
Definition: Operation.h:94
OperationInterface * interface
The interface.
Definition: Operation.h:61
MutableArray * dependencies
Contains Operations which must finish before this one can start.
Definition: Operation.h:76
Object object
The superclass.
Definition: Operation.h:55
Class * _Operation(void)
The Operation archetype.
Definition: Operation.c:233
_Bool isExecuting
true when this Operation is executing, false otherwise.
Definition: Operation.h:104
_Bool asynchronous
If true, this Operation will be expected to coordinate its own concurrency and internal state managem...
Definition: Operation.h:84
_Bool isFinished
true when this Operation is finished, false otherwise.
Definition: Operation.h:109