summaryrefslogtreecommitdiffstats
path: root/emacs.d/lisp/rudel/obby/.svn/text-base/rudel-obby-debug.el.svn-base
blob: 8f5f16887ecb6598f25834c74dd1261f8a92d0ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;;; rudel-obby-debug.el --- Debugging functions for obby backend
;;
;; Copyright (C) 2009 Jan Moringen
;;
;; Author: Jan Moringen <scymtym@users.sourceforge.net>
;; Keywords: Rudel, obby, debugging
;; X-RCS: $Id:$
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses>.


;;; Commentary:
;;
;; Debugging functions for the obby backend.


;;; History:
;;
;; 0.1 - Initial revision.


;;; Code:
;;

(require 'eieio)

(require 'rudel-debug)

(require 'rudel-obby-util)


;;; Variables
;;

(defvar rudel-obby-debug-old-state nil
  "Saves state of state machines across one function call.")


;;; Functions
;;

(defmethod rudel-send :before ((this rudel-obby-socket-owner)
			       name &rest arguments)
  "Print NAME and ARGUMENTS to debug stream."
  (let ((message (apply #'rudel-obby-assemble-message
			name arguments)))

    (with-slots (socket) this
      (rudel-debug-stream-insert
       (rudel-debug-stream-name socket)
       :sent
       (concat  (substring message 0 (min (length message) 100))
		(when (> (length message) 100)
		  "..."))
       (append (list name) arguments))))
    )

(defmethod rudel-receive :before ((this rudel-obby-socket-owner) data)
  "Print DATA to debug stream."
  (with-slots (socket) this
    (rudel-debug-stream-insert
     (rudel-debug-stream-name socket)
     :received
     (concat (substring data 0 (min (length data) 100))
	     (when (> (length data) 100)
	       "..."))))
  )

(defmethod rudel-message :before ((this rudel-obby-socket-owner)
				  message)
  "Print DATA to debug stream."
  (let ((data (apply #'rudel-obby-assemble-message message)))

    (with-slots (socket) this
      (rudel-debug-stream-insert
       (rudel-debug-stream-name socket)
       :received-processed
       (concat (substring data 0 (min (length data) 100))
	       (when (> (length data) 100)
		 "..."))
       message)
      ))
  )

(defmethod rudel-switch :before ((this rudel-obby-socket-owner)
				 state &rest arguments)
  "Store name of STATE for later printing."
  (with-slots (state) this
    (setq rudel-obby-debug-old-state
	  (if state
	      (object-name-string state)
	    "#start")))
  )

(defmethod rudel-switch :after ((this rudel-obby-socket-owner)
				state &rest arguments)
  "Print STATE and ARGUMENTS to debug stream."
  (with-slots (socket state) this
    (let ((old-state rudel-obby-debug-old-state)
	  (new-state (object-name-string state)))
      (unless (string= old-state new-state)
	(rudel-debug-stream-insert
	 (rudel-debug-stream-name socket)
	 :special
	 (if arguments
	     (format "%s -> %s %s" old-state new-state arguments)
	   (format "%s -> %s" old-state new-state))))))
  )

(provide 'rudel-obby-debug)
;;; rudel-obby-debug.el ends here