1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2016 Couchbase, Inc.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 #pragma once
18 
19 #include <string>
20 #include <cJSON_utils.h>
21 
22 /**
23  * The EventDescriptor class represents a single event descriptor and
24  * contains the meta information for a single event.
25  *
26  * The current implementation ignores the mandatory and optional attributes
27  */
28 class EventDescriptor {
29 public:
30     /**
31      * Initialize an object from the JSON representation of the event
32      * descriptor.
33      *
34      * @param root pointer to the json represenatation
35      * @throws std::logic_error if called with a JSON representation which
36      *         isn't what we expect
37      */
38     EventDescriptor(const cJSON* root);
39 
getId()40     const uint32_t getId() const {
41         return id;
42     }
43 
getName()44     const std::string& getName() const {
45         return name;
46     }
47 
getDescription()48     const std::string& getDescription() const {
49         return description;
50     }
51 
isSync()52     const bool isSync() const {
53         return sync;
54     }
55 
isEnabled()56     const bool isEnabled() const {
57         return enabled;
58     }
59 
isFilteringPermitted()60     const bool isFilteringPermitted() const {
61         return filteringPermitted;
62     }
63 
setSync(bool sync)64     void setSync(bool sync) {
65         EventDescriptor::sync = sync;
66     }
67 
setEnabled(bool enabled)68     void setEnabled(bool enabled) {
69         EventDescriptor::enabled = enabled;
70     }
71 
72 protected:
73     /**
74      * Locate the given field in the JSON
75      *
76      * @param root pointer to the first entry
77      * @param field the name of the field to locate
78      * @param type the expected type of the object (Note: there is no
79      *             cJSON_Bool #define, so you have to pass in cJSON_True
80      *             for that).
81      * @return the cJSON element for the object
82      * @throws std::logic_error if the field is missing or is of an
83      *         incorrect type
84      */
85     const cJSON* locate(const cJSON* root, const char* field, int type);
86 
87     const uint32_t id;
88     const std::string name;
89     const std::string description;
90     bool sync;
91     bool enabled;
92     bool filteringPermitted;
93 };
94 
95 
96