PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/demo/src/yolk_demo.adb

http://github.com/ThomasLocke/yolk
Ada | 70 lines | 32 code | 9 blank | 29 comment | 0 complexity | 7d038e7d6ca8047458582e4aea2d213e MD5 | raw file
 1-------------------------------------------------------------------------------
 2--                                                                           --
 3--                   Copyright (C) 2010-, Thomas Løcke                   --
 4--                                                                           --
 5--  This is free software;  you can redistribute it and/or modify it         --
 6--  under terms of the  GNU General Public License  as published by the      --
 7--  Free Software  Foundation;  either version 3,  or (at your  option) any  --
 8--  later version. This library is distributed in the hope that it will be   --
 9--  useful, but WITHOUT ANY WARRANTY;  without even the implied warranty of  --
10--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
11--  You should have received a copy of the GNU General Public License and    --
12--  a copy of the GCC Runtime Library Exception along with this program;     --
13--  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
14--  <http://www.gnu.org/licenses/>.                                          --
15--                                                                           --
16-------------------------------------------------------------------------------
17
18--  Feel free to use this demo application as the foundation for your own
19--  applications.
20--
21--  Usually you just have to change the name of environment task and  the name
22--  of the file itself to match whatever you want to call your application.
23
24with Ada.Exceptions;
25with My_Handlers;
26with Websocket_Demo;
27with Yolk.Configuration;
28with Yolk.Log;
29with Yolk.Process_Control;
30with Yolk.Process_Owner;
31with Yolk.Server;
32with Yolk.Whoops;
33
34procedure Yolk_Demo is
35   use Ada.Exceptions;
36   use Yolk.Configuration;
37   use Yolk.Log;
38   use Yolk.Process_Control;
39   use Yolk.Process_Owner;
40   use Yolk.Server;
41
42   Web_Server : HTTP := Create
43     (Unexpected => Yolk.Whoops.Unexpected_Exception_Handler'Access);
44begin
45   Set_User (Username => Config.Get (Yolk_User));
46   --  Switch user.
47
48   Web_Server.Start (Dispatchers => My_Handlers.Get);
49   --  Start the HTTP server.
50
51   Websocket_Demo.Start;
52   --  Start the WebSocket demo.
53
54   Wait;
55   --  This is the main "loop". We will wait here as long as the
56   --  Yolk.Process_Control.Controller.Check entry barrier is False.
57
58   Web_Server.Stop;
59   --  Stop the HTTP server.
60
61   Websocket_Demo.Stop;
62   --  Stop the WebSocket demo.
63exception
64   when Event : others =>
65      Trace (Handle  => Error,
66             Message => Exception_Information (Event));
67      --  Write the exception information to the rotating Error log trace.
68      Web_Server.Stop;
69      Websocket_Demo.Stop;
70end Yolk_Demo;