DriverSettingsMessageAdapter.h revision c4b6278c
1/*
2 * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Axel D��rfler, axeld@pinc-software.de
7 *		Michael Lotz <mmlr@mlotz.ch>
8 */
9#ifndef DRIVER_SETTINGS_MESSAGE_ADAPTER_H
10#define DRIVER_SETTINGS_MESSAGE_ADAPTER_H
11
12
13#include <driver_settings.h>
14#include <Message.h>
15
16
17class DriverSettingsConverter {
18public:
19								DriverSettingsConverter();
20	virtual						~DriverSettingsConverter();
21
22	virtual	status_t			ConvertFromDriverSettings(
23									const driver_parameter& parameter,
24									const char* name, int32 index, uint32 type,
25									BMessage& target);
26	virtual	status_t			ConvertEmptyFromDriverSettings(
27									const driver_parameter& parameter,
28									const char* name, uint32 type,
29									BMessage& target);
30
31	virtual	status_t			ConvertToDriverSettings(const BMessage& source,
32									const char* name, int32 index,
33									uint32 type, BString& value);
34};
35
36
37struct settings_template {
38	uint32		type;
39	const char*	name;
40	const settings_template* sub_template;
41	bool		parent_value;
42	DriverSettingsConverter* converter;
43};
44
45
46class DriverSettingsMessageAdapter {
47public:
48								DriverSettingsMessageAdapter();
49								~DriverSettingsMessageAdapter();
50
51			status_t			ConvertFromDriverSettings(
52									const driver_settings& settings,
53									const settings_template* settingsTemplate,
54									BMessage& message);
55			status_t			ConvertFromDriverSettings(const char* path,
56									const settings_template* settingsTemplate,
57									BMessage& message);
58
59			status_t			ConvertToDriverSettings(
60									const settings_template* settingsTemplate,
61									BString& settings, const BMessage& message);
62			status_t			ConvertToDriverSettings(const char* path,
63									const settings_template* settingsTemplate,
64									const BMessage& message);
65
66private:
67			const settings_template* _FindSettingsTemplate(
68									const settings_template* settingsTemplate,
69									const char* name);
70			const settings_template* _FindParentValueTemplate(
71									const settings_template* settingsTemplate);
72			status_t			_AddParameter(const driver_parameter& parameter,
73									const settings_template& settingsTemplate,
74									BMessage& message);
75
76			status_t			_ConvertFromDriverParameter(
77									const driver_parameter& parameter,
78									const settings_template* settingsTemplate,
79									BMessage& message);
80
81			status_t			_AppendSettings(
82									const settings_template* settingsTemplate,
83									BString& settings, const BMessage& message,
84									const char* name, type_code type,
85									int32 count,
86									const char* settingName = NULL);
87
88};
89
90
91#endif	// DRIVER_SETTINGS_MESSAGE_ADAPTER_H
92