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.sdl.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!"sdl.ini";
37 
38 mixin __Text!(CFG.sdl.lang);
39 
40 class Example {
41 };
42 
43 alias BasicParam = Tuple!(
44         string,"name",
45         uint,"age",
46         PluginDef,"plugins"
47 );
48 
49 /*
50 @component
51 class BasicComponents : RuntimeComponents!BasicParam {
52     override void registerAppDependencies(InjectionContainer injector) {
53         debug {
54             sharedLog.info("BasicComponents registerAppDependencies()");
55         }
56     }
57     shared static this() {
58         new BasicComponents;
59     }
60     mixin registerComponent!BasicComponents;
61 };
62 */
63 
64 mixin registerComponent!(PlatformRuntime!BasicParam);
65 
66 
67 int main(string[] args) {
68     //scope(exit)terminateInjector;
69 
70     //auto m = new BasicComponents;
71     debug {
72         sharedLog.info("basic main");
73     }
74     MsgLog.info(MsgText!(CFG.basicMessages.MSG_APP_BANNER));
75 //    MsgLog.info("name = " ~ getInjectorProperty!string("name"));
76 //    MsgLog.info("age = " ~ (getInjectorProperty!uint("age")).to!string);
77     string n =  getInjectorProperty!string("name");
78     MsgLog.info("name = " ~ n);
79     //sharedLog.info("name = " ~ getInjectorProperty!string("name"));
80     auto age = (getInjectorProperty!uint("age"));
81     MsgLog.info("age = " ~ age.to!string);
82 
83     /*version(Posix) {
84         l.load("examples/plugin/bin/libdxx_plugin.so");
85     } else version(Windows) {
86         l.load("examples/plugin/bin/dxx_plugin.dll");
87     } else {
88         // ...
89     }*/
90     auto paths = getInjectorProperty!string(CFG.keys.pluginDirs);
91     MsgLog.info(CFG.keys.pluginDirs ~ " = " ~ paths);
92     /*auto plugin = "dxx_plugin";
93 
94     foreach(p;paths.split(',')) {
95       MsgLog.info("Path: " ~ p);
96       if(PluginLoader.pluginFileName(plugin,p).exists) {
97         MsgLog.info("Load: dxx_plugin");
98         l.load(plugin,p);
99         break;
100       }
101     }*/
102 
103     //auto plugins = getInjectorProperty!(PluginDef[])("plugins");
104     auto plugin = getInjectorProperty!(PluginDef)("plugins");
105     //auto plugin=Tuple!(string,"name")("dxx_plugin");
106 
107     //foreach(plugin;plugins) {
108       foreach(path;paths.split(',')) {
109         if(PluginLoader.pluginFileName(plugin.name,path).exists) {
110           MsgLog.info("Load: "~plugin.name);
111           auto l = resolveInjector!PluginLoader();
112           assert(l);
113           l.load(plugin.name,path);
114           l.update;
115           scope(exit)destroy(l);
116         }
117       }
118     //}
119 
120     MsgLog.info("Done.");
121     return 0;
122 }