summaryrefslogtreecommitdiff
path: root/include/compcore.h
blob: eb508f291adbea2162217d911940b48ce542dcff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifndef _COMPCORE_H
#define _COMPCORE_H

#include <list>
#include <boost/function.hpp>
#include "wrapable.h"

#include <compoption.h>
#include <compsession.h>


class PrivateCore;
class CompCore;
class CompDisplay;
typedef std::list<CompDisplay *> CompDisplayList;

#define NOTIFY_CREATE_MASK (1 << 0)
#define NOTIFY_DELETE_MASK (1 << 1)
#define NOTIFY_MOVE_MASK   (1 << 2)
#define NOTIFY_MODIFY_MASK (1 << 3)

typedef void (*FileWatchCallBackProc) (const char *name,
				       void	  *closure);

typedef int CompFileWatchHandle;

typedef struct _CompFileWatch {
    char		  *path;
    int			  mask;
    FileWatchCallBackProc callBack;
    void		  *closure;
    CompFileWatchHandle   handle;
} CompFileWatch;

typedef struct _CompWatchFd {
    int			fd;
    CallBackProc	callBack;
    void		*closure;
    CompWatchFdHandle   handle;
} CompWatchFd;

int
allocCoreObjectPrivateIndex (CompObject *parent);

void
freeCoreObjectPrivateIndex (CompObject *parent,
			    int	       index);

CompBool
forEachCoreObject (CompObject	     *parent,
		   ObjectCallBackProc proc,
		   void		     *closure);

char *
nameCoreObject (CompObject *object);

CompObject *
findCoreObject (CompObject *parent,
		const char *name);

int
allocateCorePrivateIndex (void);

void
freeCorePrivateIndex (int index);


class CoreInterface : public WrapableInterface<CompCore> {
    public:
	CoreInterface ();

    WRAPABLE_DEF(void, fileWatchAdded, CompFileWatch *)
    WRAPABLE_DEF(void, fileWatchRemoved, CompFileWatch *)

    WRAPABLE_DEF(bool, initPluginForObject, CompPlugin *, CompObject *)
    WRAPABLE_DEF(void, finiPluginForObject, CompPlugin *, CompObject *)

    WRAPABLE_DEF(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOption::Value &)

    WRAPABLE_DEF(void, objectAdd, CompObject *, CompObject *)
    WRAPABLE_DEF(void, objectRemove, CompObject *, CompObject *)

    WRAPABLE_DEF(void, sessionEvent, CompSession::Event, CompOption::Vector &)
};

class CompCore : public WrapableHandler<CoreInterface>, public CompObject {

    public:
	class Timer {

	    public:

		typedef boost::function<bool ()> CallBack;
		
		Timer ();
		~Timer ();

		bool active ();
		unsigned int minTime ();
		unsigned int maxTime ();
		unsigned int minLeft ();
		unsigned int maxLeft ();
		
		void setTimes (unsigned int min, unsigned int max = 0);
		void setCallback (CallBack callback);

		void start ();
		void start (unsigned int min, unsigned int max = 0);
		void start (CallBack callback,
			    unsigned int min, unsigned int max = 0);
		void stop ();

		friend class CompCore;
		friend class PrivateCore;
		
	    private:
		bool         mActive;
		unsigned int mMinTime;
		unsigned int mMaxTime;
		int          mMinLeft;
		int          mMaxLeft;
		CallBack     mCallBack;
	};

    // functions
    public:
	CompCore ();
	~CompCore ();

	CompString name ();

	bool
	init ();

	bool
	addDisplay (const char *name);

	void
	removeDisplay (CompDisplay *);

	void
	eventLoop ();

	CompDisplayList &
	displays();
	
	CompFileWatchHandle
	addFileWatch (const char	    *path,
		      int		    mask,
		      FileWatchCallBackProc callBack,
		      void		    *closure);

	void
	removeFileWatch (CompFileWatchHandle handle);
	
	CompWatchFdHandle
	addWatchFd (int	         fd,
		    short int    events,
		    CallBackProc callBack,
		    void	 *closure);
	
	void
	removeWatchFd (CompWatchFdHandle handle);


	static int allocPrivateIndex ();
	static void freePrivateIndex (int index);

        // Wrapable interface

	WRAPABLE_HND(void, fileWatchAdded, CompFileWatch *)
	WRAPABLE_HND(void, fileWatchRemoved, CompFileWatch *)

	WRAPABLE_HND(bool, initPluginForObject, CompPlugin *, CompObject *)
	WRAPABLE_HND(void, finiPluginForObject, CompPlugin *, CompObject *)

	WRAPABLE_HND(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOption::Value &)

	WRAPABLE_HND(void, objectAdd, CompObject *, CompObject *)
	WRAPABLE_HND(void, objectRemove, CompObject *, CompObject *)

	WRAPABLE_HND(void, sessionEvent, CompSession::Event, CompOption::Vector &)

	friend class Timer;
    private:
	PrivateCore *priv;
};

#endif