From 9623fe7dc2b9f56ff7fcd93b655937e504ac26c1 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Fri, 22 Jun 2012 16:41:53 -0700 Subject: [PATCH] channels: added a sample virtual channel plugin --- channels/CMakeLists.txt | 1 + channels/skel/CMakeLists.txt | 30 +++++++++ channels/skel/readme.txt | 7 ++ channels/skel/skel_main.c | 125 +++++++++++++++++++++++++++++++++++ channels/skel/skel_main.h | 26 ++++++++ 5 files changed, 189 insertions(+) create mode 100644 channels/skel/CMakeLists.txt create mode 100644 channels/skel/readme.txt create mode 100644 channels/skel/skel_main.c create mode 100644 channels/skel/skel_main.h diff --git a/channels/CMakeLists.txt b/channels/CMakeLists.txt index 648e2a819..efb877c08 100644 --- a/channels/CMakeLists.txt +++ b/channels/CMakeLists.txt @@ -23,4 +23,5 @@ add_subdirectory(rdpdbg) add_subdirectory(rdpdr) add_subdirectory(rail) add_subdirectory(rdpsnd) +add_subdirectory(skel) diff --git a/channels/skel/CMakeLists.txt b/channels/skel/CMakeLists.txt new file mode 100644 index 000000000..1bc5354ea --- /dev/null +++ b/channels/skel/CMakeLists.txt @@ -0,0 +1,30 @@ +# FreeRDP: A Remote Desktop Protocol Client +# FreeRDP cmake build script +# +# Copyright 2011 O.S. Systems Software Ltda. +# Copyright 2011 Otavio Salvador +# Copyright 2011 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(SKEL_SRCS + skel_main.c + skel_main.h +) + +add_library(skel ${SKEL_SRCS}) +set_target_properties(skel PROPERTIES PREFIX "") + +target_link_libraries(skel freerdp-utils) + +install(TARGETS skel DESTINATION ${FREERDP_PLUGIN_PATH}) diff --git a/channels/skel/readme.txt b/channels/skel/readme.txt new file mode 100644 index 000000000..217589fa2 --- /dev/null +++ b/channels/skel/readme.txt @@ -0,0 +1,7 @@ + +This is a skeleton virtual channel plugin for freerdp +To create your own virtual channel plugin, copy this directory +then change all references of "skel" to your plugin name +remember, plugin name are 7 chars or less, no spaces or funny chars + +Jay diff --git a/channels/skel/skel_main.c b/channels/skel/skel_main.c new file mode 100644 index 000000000..305f7c05f --- /dev/null +++ b/channels/skel/skel_main.c @@ -0,0 +1,125 @@ +/** + * FreeRDP: A Remote Desktop Protocol client. + * Audio Output Virtual Channel + * + * Copyright 2009-2012 Jay Sorg + * Copyright 2010-2012 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WIN32 +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "skel_main.h" + +struct skel_plugin +{ + rdpSvcPlugin plugin; + + /* put your private data here */ + +}; + +static void skel_process_interval(rdpSvcPlugin* plugin) +{ + printf("skel_process_interval:\n"); +} + +static void skel_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) +{ + skelPlugin* skel = (skelPlugin*)plugin; + STREAM* data_out; + int bytes; + + printf("skel_process_receive:\n"); + + if (skel == NULL) + { + return; + } + + /* process data in(from server) here */ + /* here we just send the same data back */ + + bytes = stream_get_length(data_in); + if (bytes > 0) + { + data_out = stream_new(bytes); + stream_copy(data_out, data_in, bytes); + /* svc_plugin_send takes ownership of data_out, that is why + we do not free it */ + svc_plugin_send(plugin, data_out); + } + + stream_free(data_in); +} + +static void skel_process_connect(rdpSvcPlugin* plugin) +{ + skelPlugin* skel = (skelPlugin*)plugin; + DEBUG_SVC("connecting"); + + printf("skel_process_connect:\n"); + + if (skel == NULL) + { + return; + } + + /* if you want a call from channel thread once is a while do this */ + plugin->interval_ms = 1000; + plugin->interval_callback = skel_process_interval; + +} + +static void skel_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +{ + printf("skel_process_event:\n"); + + /* events comming from main freerdp window to plugin */ + /* send them back with svc_plugin_send_event */ + + freerdp_event_free(event); +} + +static void skel_process_terminate(rdpSvcPlugin* plugin) +{ + skelPlugin* skel = (skelPlugin*)plugin; + + printf("skel_process_terminate:\n"); + + if (skel == NULL) + { + return; + } + + /* put your cleanup here */ + + xfree(plugin); +} + +DEFINE_SVC_PLUGIN(skel, "skel", + CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP) diff --git a/channels/skel/skel_main.h b/channels/skel/skel_main.h new file mode 100644 index 000000000..582e48a5a --- /dev/null +++ b/channels/skel/skel_main.h @@ -0,0 +1,26 @@ +/** + * FreeRDP: A Remote Desktop Protocol client. + * Audio Output Virtual Channel + * + * Copyright 2012 Jay Sorg + * Copyright 2010-2012 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SKEL_MAIN_H +#define __SKEL_MAIN_H + +typedef struct skel_plugin skelPlugin; + +#endif /* __SKEL_MAIN_H */