Ocean
ApplicationInterface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_BASE_APPLICATION_INTERFACE_H
9 #define META_OCEAN_BASE_APPLICATION_INTERFACE_H
10 
11 #include "ocean/base/Base.h"
12 #include "ocean/base/Callback.h"
13 #include "ocean/base/Lock.h"
14 #include "ocean/base/Singleton.h"
15 
16 #include <vector>
17 
18 namespace Ocean
19 {
20 
21 /**
22  * This class implements a very light application interface.
23  * The interface can be used to access basic application functionalities.<br>
24  * Define the callback function of each feature your application supports.<br>
25  * This interface is implemented as a singleton.
26  * @ingroup base
27  */
28 class OCEAN_BASE_EXPORT ApplicationInterface : public Singleton<ApplicationInterface>
29 {
30  friend class Singleton<ApplicationInterface>;
31 
32  public:
33 
34  /**
35  * Definition of an event id.
36  */
37  typedef unsigned int EventId;
38 
39  /**
40  * Definition of an invalid event id.
41  */
42  static const EventId invalidEventId;
43 
44  /**
45  * Definition of a vector holding event ids.
46  */
47  typedef std::vector<EventId> EventIds;
48 
49  /**
50  * Definition of a vector holding strings.
51  */
52  typedef std::vector<std::string> StringVector;
53 
54  /**
55  * Definition of a content add or remove callback function.
56  * The return parameter is the corresponding event id.<br>
57  * The first parameter holds the content to be added.<br>
58  */
60 
61  /**
62  * Definition of a content event callback function.
63  * The first parameter hold the event id.<br>
64  * The second parameter defines whether the event has been loaded (true) or unloaded (false)
65  * The third parameter defined the event state.<br>
66  */
68 
69  private:
70 
71  /**
72  * Definition of an vector holding event callbacks.
73  */
75 
76  public:
77 
78  /**
79  * Tells the application to add content.
80  * @param content Content to be loaded (may be e.g. urls of files)
81  * @return Corresponding event ids, one for each file
82  */
83  EventIds addContent(const StringVector& content);
84 
85  /**
86  * Tells the application to close all existing files.
87  * @param content Content to be unloaded (may be e.g. urls of files), if this parameter is empty the entire content will be removed
88  * @return Corresponding event ids, one for each file
89  */
91 
92  /**
93  * Event function for added content.
94  * @param eventId Event id of the added content
95  * @param state State of the add event
96  */
97  void contentAdded(const EventId eventId, const bool state);
98 
99  /**
100  * Event function for removed content.
101  * @param eventId Event id of the removed content
102  * @param state State of the remove event
103  */
104  void contentRemoved(const EventId eventId, const bool state);
105 
106  /**
107  * Sets or replaces the add content callback function.
108  * @param callback Callback function to be set
109  */
111 
112  /**
113  * Sets or replaces the remove content callback function.
114  * @param callback Callback function to be set
115  */
117 
118  /**
119  * Adds an event callback function.
120  * @param callback Callback to be added
121  */
123 
124  /**
125  * Removes an event callback function.
126  * @param callback Callback to be removed
127  */
129 
130  protected:
131 
132  /**
133  * Destructs an application interface object.
134  */
136 
137  private:
138 
139  /// Content add callback.
141 
142  /// Content remove callback.
144 
145  /// Event callbacks
147 
148  /// Interface lock.
150 };
151 
152 }
153 
154 #endif // META_OCEAN_BASE_APPLICATION_INTERFACE_H
This class implements a very light application interface.
Definition: ApplicationInterface.h:29
void setContentRemoveCallbackFunction(const ContentCallback &callback)
Sets or replaces the remove content callback function.
static const EventId invalidEventId
Definition of an invalid event id.
Definition: ApplicationInterface.h:42
EventCallbacks contentEventCallbacks
Event callbacks.
Definition: ApplicationInterface.h:146
unsigned int EventId
Definition of an event id.
Definition: ApplicationInterface.h:37
ContentCallback contentAddCallback
Content add callback.
Definition: ApplicationInterface.h:140
ContentCallback contentRemoveCallback
Content remove callback.
Definition: ApplicationInterface.h:143
void removeEventCallbackFunction(const EventCallback &callback)
Removes an event callback function.
Callback< void, EventId, bool, bool > EventCallback
Definition of a content event callback function.
Definition: ApplicationInterface.h:67
void contentAdded(const EventId eventId, const bool state)
Event function for added content.
void contentRemoved(const EventId eventId, const bool state)
Event function for removed content.
std::vector< std::string > StringVector
Definition of a vector holding strings.
Definition: ApplicationInterface.h:52
virtual ~ApplicationInterface()
Destructs an application interface object.
std::vector< EventId > EventIds
Definition of a vector holding event ids.
Definition: ApplicationInterface.h:47
Callback< EventIds, const StringVector & > ContentCallback
Definition of a content add or remove callback function.
Definition: ApplicationInterface.h:59
void addEventCallbackFunction(const EventCallback &callback)
Adds an event callback function.
EventIds addContent(const StringVector &content)
Tells the application to add content.
void setContentAddCallbackFunction(const ContentCallback &callback)
Sets or replaces the add content callback function.
Lock lock
Interface lock.
Definition: ApplicationInterface.h:149
Callbacks< EventCallback > EventCallbacks
Definition of an vector holding event callbacks.
Definition: ApplicationInterface.h:74
EventIds removeContent(const StringVector &content)
Tells the application to close all existing files.
This class implements a recursive lock object.
Definition: Lock.h:31
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15