FreeRDP/channels/rdpdr/client/devman.c

118 lines
2.6 KiB
C
Raw Normal View History

2011-08-04 19:22:58 +04:00
/**
2012-10-09 05:00:07 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
2011-08-04 19:22:58 +04:00
*
* Copyright 2010-2011 Vic Lee
2012-10-09 05:00:07 +04:00
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
2011-08-04 19:22:58 +04:00
*
* 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.
*/
#ifdef HAVE_CONFIG_H
2011-08-04 19:22:58 +04:00
#include "config.h"
#endif
2011-08-04 19:22:58 +04:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2011-08-04 19:22:58 +04:00
#include <freerdp/types.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/list.h>
#include <freerdp/utils/svc_plugin.h>
#include <freerdp/utils/load_plugin.h>
#include <freerdp/client/channels.h>
2011-08-04 19:22:58 +04:00
2012-10-09 05:00:07 +04:00
#include "rdpdr_main.h"
2011-08-04 19:22:58 +04:00
#include "devman.h"
DEVMAN* devman_new(rdpSvcPlugin* plugin)
{
DEVMAN* devman;
devman = xnew(DEVMAN);
devman->plugin = plugin;
devman->id_sequence = 1;
devman->devices = list_new();
2011-08-05 19:19:43 +04:00
return devman;
2011-08-04 19:22:58 +04:00
}
void devman_free(DEVMAN* devman)
{
DEVICE* device;
2012-02-10 05:04:27 +04:00
while ((device = (DEVICE*) list_dequeue(devman->devices)) != NULL)
2011-08-04 19:22:58 +04:00
IFCALL(device->Free, device);
2012-02-10 05:04:27 +04:00
2011-08-04 19:22:58 +04:00
list_free(devman->devices);
2012-02-10 05:04:27 +04:00
free(devman);
2011-08-04 19:22:58 +04:00
}
static void devman_register_device(DEVMAN* devman, DEVICE* device)
{
device->id = devman->id_sequence++;
list_add(devman->devices, device);
DEBUG_SVC("device %d.%s registered", device->id, device->name);
}
2011-08-18 01:28:26 +04:00
boolean devman_load_device_service(DEVMAN* devman, RDP_PLUGIN_DATA* plugin_data)
2011-08-04 19:22:58 +04:00
{
char* name;
2011-08-04 19:22:58 +04:00
DEVICE_SERVICE_ENTRY_POINTS ep;
PDEVICE_SERVICE_ENTRY entry = NULL;
2011-08-04 19:22:58 +04:00
name = (char*) plugin_data->data[0];
entry = (PDEVICE_SERVICE_ENTRY) freerdp_channels_find_static_device_service_entry(name);
if (!entry)
{
printf("loading device service %s (plugin)\n", name);
entry = freerdp_load_plugin(name, "DeviceServiceEntry");
}
else
{
printf("loading device service %s (static)\n", name);
}
2012-02-10 05:04:27 +04:00
2011-08-04 19:22:58 +04:00
if (entry == NULL)
return false;
2011-08-04 19:22:58 +04:00
ep.devman = devman;
ep.RegisterDevice = devman_register_device;
ep.plugin_data = plugin_data;
entry(&ep);
return true;
2011-08-04 19:22:58 +04:00
}
2011-08-05 21:54:40 +04:00
DEVICE* devman_get_device_by_id(DEVMAN* devman, uint32 id)
{
LIST_ITEM* item;
DEVICE* device;
for (item = devman->devices->head; item; item = item->next)
{
2012-02-10 05:04:27 +04:00
device = (DEVICE*) item->data;
2011-08-05 21:54:40 +04:00
if (device->id == id)
return device;
}
2012-02-10 05:04:27 +04:00
2011-08-05 21:54:40 +04:00
return NULL;
}