1 /**
2 Copyright 2018 Mark Fisher
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 **/
22 module dxx.app.extension;
23 
24 private import std.algorithm;
25 
26 private import hunt.cache;
27 
28 private import dxx.util;
29 
30 struct ExtensionPointDesc {
31     string id;
32     string symbolicName;
33     string description;
34     string url;
35     void* executableExtension;
36 }
37 
38 interface ExtensionPoint {
39     //const(string) id();
40     inout(ExtensionPointDesc) desc() inout;
41 }
42 
43 struct ExtensionDesc {
44     string id;
45     string symbolicName;
46     string extensionPoint;
47     string description;
48     string url;
49     //void* delegate(string id) createExecutableExtension;
50     ConfigurationElement[string] configuration;
51     //void*  createExecutableExtension(string id){
52     //    return null;
53     //}
54 }
55 
56 struct ConfigurationElement {
57     string id;
58     string[string] attr;
59     ConfigurationElement[] children;
60     //ExtensionDesc* extension;
61     //ConfigurationElement* parent;
62 }
63 
64 interface Extension {
65     inout(ExtensionDesc) desc() inout;
66 }
67 
68 struct ExtensionEvent {
69     enum Type {
70         Register,Unregister
71     };
72     @property
73     Type eventType;
74     @property
75     string pluginId;
76     @property
77     ExtensionDesc* extension;
78 }
79 
80 class ExtensionsManager : SyncNotificationSource {
81     static class _Event {
82       ExtensionEvent ev;
83       this(ExtensionEvent.Type evType,string pluginId,ExtensionDesc* x) {
84         ev=ExtensionEvent(evType,pluginId,x);
85       }
86     };
87 
88     UCache xpCache;
89     UCache xCache;
90     void enumerateExtensions(alias T)(string xp) {
91         //extensions.filter!(a => a.desc.extensionPoint == xp).each!(a => T(a));
92     }
93     void enumerateExtensionPoints(alias T)(string xp) {
94     }
95     this() {
96         xpCache = UCache.CreateUCache();
97         xCache = UCache.CreateUCache();
98     }
99     void sendExtensionEvent(ExtensionEvent.Type type,string pluginId,ExtensionDesc* x) {
100       auto e = new _Event(type,pluginId,x);
101       _send!ExtensionEvent(&e.ev);
102     }
103     void registerExtensionPoint(ExtensionPointDesc* xp,string pluginId) {
104         //xpCache.put(pluginId ~ "." ~ xp.id,xp);
105     }
106     void unregisterExtensionPoint(ExtensionPointDesc* xp,string pluginId) {
107         //xpCache.remove(pluginId ~ "." ~ xp.id);
108     }
109     void registerExtension(ExtensionDesc* x,string pluginId) {
110         //xCache.put(pluginId ~ "." ~ x.id,x);
111         sendExtensionEvent(ExtensionEvent.Type.Register,pluginId,x);
112     }
113     void unregisterExtension(ExtensionDesc* x,string pluginId) {
114         //xCache.remove(pluginId ~ "." ~ x.id);
115         sendExtensionEvent(ExtensionEvent.Type.Unregister,pluginId,x);
116     }
117 }