Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / include / freerdp / utils / svc_plugin.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol client.
3  * Static Virtual Channel Interface
4  *
5  * Copyright 2009-2011 Jay Sorg
6  * Copyright 2010-2011 Vic Lee
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #ifndef __SVC_PLUGIN_UTILS_H
22 #define __SVC_PLUGIN_UTILS_H
23
24 /* static channel plugin base implementation */
25
26 #include <freerdp/api.h>
27 #include <freerdp/svc.h>
28 #include <freerdp/utils/stream.h>
29 #include <freerdp/utils/event.h>
30 #include <freerdp/utils/debug.h>
31
32 typedef struct rdp_svc_plugin_private rdpSvcPluginPrivate;
33 typedef struct rdp_svc_plugin rdpSvcPlugin;
34
35 struct rdp_svc_plugin
36 {
37         CHANNEL_ENTRY_POINTS_EX channel_entry_points;
38         CHANNEL_DEF channel_def;
39
40         int interval_ms;
41
42         void (*connect_callback)(rdpSvcPlugin* plugin);
43         void (*receive_callback)(rdpSvcPlugin* plugin, STREAM* data_in);
44         void (*event_callback)(rdpSvcPlugin* plugin, RDP_EVENT* event);
45         void (*interval_callback)(rdpSvcPlugin* plugin);
46         void (*terminate_callback)(rdpSvcPlugin* plugin);
47
48         rdpSvcPluginPrivate* priv;
49 };
50
51 FREERDP_API void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints);
52 FREERDP_API int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out);
53 FREERDP_API int svc_plugin_send_event(rdpSvcPlugin* plugin, RDP_EVENT* event);
54
55 #define svc_plugin_get_data(_p) (RDP_PLUGIN_DATA*)(((rdpSvcPlugin*)_p)->channel_entry_points.pExtendedData)
56
57 #ifdef WITH_DEBUG_SVC
58 #define DEBUG_SVC(fmt, ...) DEBUG_CLASS(SVC, fmt, ## __VA_ARGS__)
59 #else
60 #define DEBUG_SVC(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
61 #endif
62
63 #define DEFINE_SVC_PLUGIN(_prefix, _name, _options) \
64 \
65 int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) \
66 { \
67         _prefix##Plugin* _p; \
68 \
69         _p = xnew(_prefix##Plugin); \
70 \
71         _p->plugin.channel_def.options = _options; \
72         strcpy(_p->plugin.channel_def.name, _name); \
73 \
74         _p->plugin.connect_callback = _prefix##_process_connect; \
75         _p->plugin.receive_callback = _prefix##_process_receive; \
76         _p->plugin.event_callback = _prefix##_process_event; \
77         _p->plugin.terminate_callback = _prefix##_process_terminate; \
78 \
79         svc_plugin_init((rdpSvcPlugin*)_p, pEntryPoints); \
80 \
81         return 1; \
82 }
83
84 #endif /* __SVC_PLUGIN_UTILS_H */