summaryrefslogtreecommitdiff
path: root/include/compcore.h
blob: 4324ef43411816d1c71d202a12d583c1de4e290e (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
#ifndef _COMPCORE_H
#define _COMPCORE_H

#include <list>
#include "wrapable.h"

class PrivateCore;
class CompCore;
class CompDisplay;

#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 _CompTimeout {
    int			minTime;
    int			maxTime;
    int			minLeft;
    int			maxLeft;
    CallBackProc	callBack;
    void		*closure;
    CompTimeoutHandle   handle;
} CompTimeout;

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 *, CompOptionValue *)

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

    WRAPABLE_DEF(void, sessionEvent, CompSessionEvent, CompOption *, unsigned int)
};

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

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

	CompString name ();

	bool
	init ();

	bool
	addDisplay (const char *name);

	void
	removeDisplay (CompDisplay *);

	void
	eventLoop ();

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

	void
	removeFileWatch (CompFileWatchHandle handle);

	CompTimeoutHandle
	addTimeout (int	         minTime,
		    int	         maxTime,
		    CallBackProc callBack,
		    void	 *closure = NULL);

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

	void *
	removeTimeout (CompTimeoutHandle handle);

        // 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 *, CompOptionValue *)

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

	WRAPABLE_HND(void, sessionEvent, CompSessionEvent, CompOption *, unsigned int)

    private:
	PrivateCore *priv;
};

#endif