1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 #import <ExpoModulesCore/EXTaskInterface.h>
4 
5 @protocol EXTaskServiceInterface
6 
7 /**
8  *  Returns boolean value whether the task with given name is already registered for given appId.
9  */
10 - (BOOL)hasRegisteredTaskWithName:(nonnull NSString *)taskName
11                          forAppId:(nonnull NSString *)appId;
12 
13 /**
14  *  Registers task in any kind of persistent storage, so it could be restored in future sessions.
15  */
16 - (void)registerTaskWithName:(nonnull NSString *)taskName
17                        appId:(nonnull NSString *)appId
18                       appUrl:(nonnull NSString *)appUrl
19                consumerClass:(nonnull Class)consumerClass
20                      options:(nullable NSDictionary *)options;
21 
22 /**
23  *  Unregisters task with given name and for given appId. If consumer class is provided,
24  *  it can throw an exception if task's consumer is not a member of that class.
25  */
26 - (void)unregisterTaskWithName:(nonnull NSString *)taskName
27                       forAppId:(nonnull NSString *)appId
28                  consumerClass:(nullable Class)consumerClass;
29 
30 /**
31  *  Unregisters all tasks registered for the app with given appId.
32  */
33 - (void)unregisterAllTasksForAppId:(nonnull NSString *)appId;
34 
35 /**
36  *  Returns boolean value whether or not the task's consumer is a member of given class.
37  */
38 - (BOOL)taskWithName:(nonnull NSString *)taskName
39             forAppId:(nonnull NSString *)appId
40   hasConsumerOfClass:(nonnull Class)consumerClass;
41 
42 /**
43  *  Returns options associated with the task with given name and appId or nil if task not found.
44  */
45 - (nullable NSDictionary *)getOptionsForTaskName:(nonnull NSString *)taskName
46                                         forAppId:(nonnull NSString *)appId;
47 
48 /**
49  *  Returns an array of registered tasks for given appId.
50  */
51 - (nonnull NSArray *)getRegisteredTasksForAppId:(nullable NSString *)appId;
52 
53 /**
54  *  Notifies the service that a task has just finished.
55  */
56 - (void)notifyTaskWithName:(nonnull NSString *)taskName
57                   forAppId:(nonnull NSString *)appId
58      didFinishWithResponse:(nonnull NSDictionary *)response;
59 
60 /**
61  *  Passes a reference of task manager for given appId to the service.
62  */
63 - (void)setTaskManager:(nonnull id<EXTaskManagerInterface>)taskManager
64               forAppId:(nonnull NSString *)appId
65                withUrl:(nonnull NSString *)appUrl;
66 
67 @end
68