Update to the new library 'json2'
[euphorik.git] / modules / erl / euphorik_daemon.erl
index 5760332..190458e 100755 (executable)
@@ -1,22 +1,61 @@
-% Module tournant en background s'occupant periodiquement de certaines tâches.\r
-% Auteur : G.Burri\r
-% Date : 05.11.2007\r
+% coding: utf-8\r
+% Copyright 2008 Grégory Burri\r
+%\r
+% This file is part of Euphorik.\r
+%\r
+% Euphorik is free software: you can redistribute it and/or modify\r
+% it under the terms of the GNU General Public License as published by\r
+% the Free Software Foundation, either version 3 of the License, or\r
+% (at your option) any later version.\r
+%\r
+% Euphorik is distributed in the hope that it will be useful,\r
+% but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+% GNU General Public License for more details.\r
+%\r
+% You should have received a copy of the GNU General Public License\r
+% along with Euphorik.  If not, see <http://www.gnu.org/licenses/>.\r
+%\r
+% Module tournant en background s'occupant periodiquement de certaines tâches :\r
+%  - rechargement des modules lors d'une mise en production\r
 \r
--module(euphorik_daemon).
--export([start/1]).
-
+\r
+-module(euphorik_daemon).\r
+-author("Greg Burri <greg.burri@gmail.com>").\r
+-export([start/1, reload_euphorik/0, loop/0]).\r
 -include("../include/euphorik_defines.hrl").\r
-
-
-% Démarre le démon
-start(A) ->\r
-   loop(A).
-
 \r
-loop(A) ->
-   euphorik_bd:elire_troll(),\r
-   timer:sleep(1000),\r
-   loop(A).
 \r
-
-
+% Démarre le démon\r
+start(_A) ->\r
+   register(euphorik_daemon, self()),\r
+   loop().\r
+\r
+\r
+loop() ->\r
+   receive\r
+      switch -> % To reload a new code, see 'reload_euphorik/0'.\r
+         euphorik_daemon:loop()\r
+   end.\r
+\r
+% Recharge tous les modules euphorik.\r
+% Appelé lors d'une mise en prod.\r
+% TODO : récupérer les noms à partir des .beam dans /modules/ebin\r
+reload_euphorik() ->\r
+   lists:foreach(\r
+      fun(M) ->\r
+         c:l(M) % (purge & load)\r
+      end,\r
+      [\r
+         euphorik_common,\r
+         euphorik_minichat_conversation,\r
+         euphorik_protocole,\r
+         euphorik_requests,\r
+         euphorik_bd,\r
+         euphorik_bd_admin,\r
+         euphorik_daemon\r
+      ]\r
+   ),\r
+   % changement du code du daemon\r
+   euphorik_daemon ! switch,\r
+   ok.\r