1 // This file is written in D programming language
2 /**
3 *   Copyright: © 2014 Anton Gushcha
4 *   License: Subject to the terms of the MIT license, as written in the included LICENSE file.
5 *   Authors: NCrashed <ncrashed@gmail.com>
6 */
7 module test02;
8 
9 import std.file;
10 
11 import dlogg.strict;
12 import daemonize.d;
13 
14 version(Server)
15 {
16     alias daemon = Daemon!(
17         "Test2",
18         
19         KeyValueList!(
20             Composition!(Signal.Terminate, Signal.Quit, Signal.Shutdown, Signal.Stop), (shared ILogger logger, Signal signal)
21             {
22                 write("output.txt", "Test string 1");
23                 return false; 
24             },
25             Signal.HangUp, (logger)
26             {
27                 write("output.txt", "Test string 2");
28                 return false;
29             }),
30         
31         (logger, shouldExit) {
32             while(!shouldExit()) {}
33             return 0;
34         }
35     );
36     
37     int main()
38     {
39         return buildDaemon!daemon.run(new shared StrictLogger("logfile.log")); 
40     }
41 } 
42 else
43 {
44     alias daemon = DaemonClient!(
45         "Test2",
46         Composition!(Signal.Terminate, Signal.Quit, Signal.Shutdown, Signal.Stop),
47         Signal.HangUp
48     );
49     
50     int main()
51     {
52         alias client = buildDaemon!daemon;
53         
54         Signal sig;
55         version(Test1) sig = Signal.Terminate;
56         version(Test2) sig = Signal.Quit;
57         version(Test3) sig = Signal.Shutdown;
58         version(Test4) sig = Signal.Stop;
59         version(Test5) sig = Signal.HangUp;
60         
61         client.sendSignal(new shared StrictLogger("logfile.log"), sig);
62         return 0;
63     }
64 }