summaryrefslogtreecommitdiff
path: root/common/JackMetadata.h
blob: cd66f8ac8fd4704a18eb0953e26e8d01b010a4d7 (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
/*
  Copyright (C) 2011 David Robillard
  Copyright (C) 2013 Paul Davis

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published by
  the Free Software Foundation; either version 2.1 of the License, or (at
  your option) any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
  License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __JackMetadata__
#define __JackMetadata__

#include <stdint.h>

#if HAVE_DB
#include <db.h>
#endif

#include <jack/uuid.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    const char* key;
    const char* data;
    const char* type;
} jack_property_t;

typedef struct {
    jack_uuid_t      subject;
    uint32_t         property_cnt;
    jack_property_t* properties;
    uint32_t         property_size;
} jack_description_t;

typedef enum {
    PropertyCreated,
    PropertyChanged,
    PropertyDeleted
} jack_property_change_t;

typedef void (*JackPropertyChangeCallback)(jack_uuid_t            subject,
                                           const char*            key,
                                           jack_property_change_t change,
                                           void*                  arg);

#ifdef __cplusplus
}
#endif


namespace Jack
{

class JackClient;

/*!
\brief Metadata base.
*/

class JackMetadata
{
    private:

    #if HAVE_DB
        DB* fDB;
        DB_ENV* fDBenv;
        const bool fIsEngine;
    #endif

        int PropertyInit();
        int PropertyChangeNotify(JackClient* client, jack_uuid_t subject, const char* key, jack_property_change_t change);

    #if HAVE_DB
        void MakeKeyDbt(DBT* dbt, jack_uuid_t subject, const char* key);
    #endif

    public:

        JackMetadata(bool isEngine);
        ~JackMetadata();

        int GetProperty(jack_uuid_t subject, const char* key, char** value, char** type);
        int GetProperties(jack_uuid_t subject, jack_description_t* desc);
        int GetAllProperties(jack_description_t** descriptions);

        int GetDescription(jack_uuid_t subject, jack_description_t* desc);
        int GetAllDescriptions(jack_description_t** descs);
        void FreeDescription(jack_description_t* desc, int free_actual_description_too);

        int SetProperty(JackClient* client, jack_uuid_t subject, const char* key, const char* value, const char* type);

        int RemoveProperty(JackClient* client, jack_uuid_t subject, const char* key);
        int RemoveProperties(JackClient* client, jack_uuid_t subject);
        int RemoveAllProperties(JackClient* client);

};


} // end of namespace

#endif