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.example.basic.app;
23 
24 private import ctini.ctini;
25 private import aermicioi.aedi;
26 
27 private import std.stdio;
28 private import std.experimental.logger;
29 private import std.conv;
30 private import std..string;
31 private import std.file;
32 
33 private import dxx.app;
34 private import dxx.util;
35 
36 enum CFG = DXXConfig ~ IniConfig!"basic.ini";
37 
38 mixin __Text!(CFG.basic.lang);
39 
40 class Example {
41 };
42 
43 alias BasicParam = Tuple!(
44         string,"name",
45         uint,"age",
46         Tuple!(
47         //  PluginDef[string],"plugins"
48           //PluginDef, "plugin"
49           Tuple!(
50             string,"pluginDirs"
51           ),"config",
52           Tuple!(
53             string,"name"
54           ),"workspace",
55           Tuple!(
56             string,"name",
57             string,"path",
58             string,"pluginVersion"
59           ),"plugin",
60         ),"dxx"
61 );
62 
63 /*
64 @component
65 class BasicComponents : RuntimeComponents!BasicParam {
66     override void registerAppDependencies(InjectionContainer injector) {
67         debug {
68             sharedLog.info("BasicComponents registerAppDependencies()");
69         }
70     }
71     shared static this() {
72         new BasicComponents;
73     }
74     mixin registerComponent!BasicComponents;
75 };
76 */
77 
78 mixin registerComponent!(PlatformRuntime!BasicParam);
79 
80 auto loadPlugin(PluginDef def) {
81   auto paths = getInjectorProperty!string(CFG.keys.pluginDirs);
82   foreach(path;paths.split(':')) {
83     if(PluginLoader.pluginFileName(def.name,path).exists) {
84       MsgLog.info("Load: "~def.name);
85       auto l = resolveInjector!PluginLoader();
86       assert(l);
87       l.load(def.name,path);
88       return l;
89     }
90   }
91   return null;
92 
93 }
94 
95 int main(string[] args) {
96     //scope(exit)terminateInjector;
97 
98     //auto m = new BasicComponents;
99     debug {
100         sharedLog.info("basic main");
101     }
102     MsgLog.info(MsgText!(CFG.basicMessages.MSG_APP_BANNER));
103 //    MsgLog.info("name = " ~ getInjectorProperty!string("name"));
104 //    MsgLog.info("age = " ~ (getInjectorProperty!uint("age")).to!string);
105     //string n =  getInjectorProperty!string("name");
106     //string n =  Properties.__("name");
107     string n = (getInjectorProperty!string("name"));
108     MsgLog.info("name = " ~ n);
109     //sharedLog.info("name = " ~ getInjectorProperty!string("name"));
110     //auto age = (getInjectorProperty!uint("age"));
111     //MsgLog.info("age = " ~ age.to!string);
112 
113     /*version(Posix) {
114         l.load("examples/plugin/bin/libdxx_plugin.so");
115     } else version(Windows) {
116         l.load("examples/plugin/bin/dxx_plugin.dll");
117     } else {
118         // ...
119     }*/
120     //MsgLog.info(CFG.keys.pluginDirs ~ " = " ~ paths);
121     /*auto plugin = "dxx_plugin";
122 
123     foreach(p;paths.split(',')) {
124       MsgLog.info("Path: " ~ p);
125       if(PluginLoader.pluginFileName(plugin,p).exists) {
126         MsgLog.info("Load: dxx_plugin");
127         l.load(plugin,p);
128         break;
129       }
130     }*/
131 
132     //auto plugins = getInjectorProperty!(PluginDef[])("dxx.plugins");
133     //auto plugin = getInjectorProperty!(PluginDef)("dxx.plugin");
134     //auto plugin=Tuple!(string,"name")("dxx_plugin");
135     //MsgLog.info("plugin = " ~ plugin.name);
136     PluginDef def;
137     def.name = getInjectorProperty!(string)("dxx.plugin.name");
138     auto plugin = def.loadPlugin();
139     //foreach(plugin;plugins) {
140     //}
141     assert(plugin);
142     plugin.update;
143     scope(exit)destroy(plugin);
144     //destroy(l);
145 
146     MsgLog.info("Done.");
147     return 0;
148 }