Changeset 199


Ignore:
Timestamp:
04/24/07 22:15:07 (18 years ago)
Author:
Erik Huelsmann
Message:

Add a dcc-chat-connection class; a non-abstract subclass of dcc-connection.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/package.lisp

    r193 r199  
    142142             ;; DCC specific dictionary
    143143             :dcc-connection
     144             :dcc-chat-connection
    144145             :irc-connection
    145146             :close-on-main
    146147             :remote-user
    147148             :dcc-close
     149             :make-dcc-chat-connection
    148150             )))
    149151
  • TabularUnified trunk/protocol.lisp

    r197 r199  
    336336    #+armedbear (ext:destroy-thread process))
    337337
    338 (defun read-message-loop (connection)
     338(defgeneric read-message-loop (connection))
     339(defmethod read-message-loop (connection)
    339340  (loop while (read-message connection)))
    340341
     
    361362    raw-message))
    362363
    363 (defmethod get-hooks ((connection connection) (class symbol))
     364;;applies to both irc and dcc-connections
     365(defmethod get-hooks (connection (class symbol))
    364366  "Return a list of all hooks for `class'."
    365367  (gethash class (hooks connection)))
    366368
    367 (defmethod add-hook ((connection connection) class hook)
     369;;applies to both irc and dcc-connections
     370(defmethod add-hook (connection class hook)
    368371  "Add `hook' to `class'."
    369372  (setf (gethash class (hooks connection))
     
    480483;; CHAT related generic functions
    481484(defgeneric send-dcc-message (connection message))
     485;;already defined in relation to `connection'
     486;; (defgeneric read-message (connection))
     487;;(defgeneric dcc-message-event (message)) <defined in event.lisp>
    482488
    483489;; SEND related generic functions
     
    487493    (and (streamp stream)
    488494         (open-stream-p stream))))
     495
     496(defmethod send-dcc-message ((connection dcc-connection) message)
     497  (format (output-stream connection) "~A~%" message)
     498  (force-output (network-stream connection)))
    489499
    490500(defmethod dcc-close ((connection dcc-connection))
     
    498508        (dcc-connections (irc-connection connection))
    499509        (remove connection (dcc-connections (irc-connection connection)))))
     510
     511
     512(defclass dcc-chat-connection (dcc-connection)
     513  ((output-stream
     514    :initarg :output-stream
     515    :initform nil
     516    :accessor output-stream
     517    :documentation "Stream used to communicate with the other end
     518of the network pipe.")
     519   (hooks
     520    :initform (make-hash-table :test #'equal)
     521    :accessor hooks))
     522  (:documentation ""))
     523
     524
     525(defun make-dcc-chat-connection (&key (remote-user nil)
     526;;                                      (remote-address nil)
     527;;                                      (remote-port nil)
     528                                      (client-stream nil)
     529                                      (irc-connection nil)
     530                                      (close-on-main t)
     531                                      (socket nil)
     532                                      (network-stream nil)
     533                                      (outgoing-external-format *default-outgoing-external-format*)
     534                                      (hooks nil))
     535  (let* ((output-stream (flexi-streams:make-flexi-stream
     536                         network-stream
     537                         :element-type 'character
     538                         :external-format (external-format-fixup
     539                                           outgoing-external-format)))
     540         (connection (make-instance 'dcc-chat-connection
     541                                    :remote-user remote-user
     542                                    :client-stream client-stream
     543                                    :output-stream output-stream
     544                                    :irc-connection irc-connection
     545                                    :close-on-main close-on-main
     546                                    :socket socket
     547                                    :network-stream network-stream)))
     548    (dolist (hook hooks)
     549      (add-hook connection (car hook) (cdar hook)))
     550    connection))
     551
     552(defmethod read-message ((connection dcc-chat-connection))
     553  (when (connectedp connection)
     554    (let* ((msg-string (read-protocol-line connection))
     555           (message (create-dcc-message msg-string)))
     556      (setf (connection message) connection)
     557      (when *debug-p*
     558        (format *debug-stream* "~A" (describe message))
     559        (force-output *debug-stream*))
     560      (dcc-message-event connection message)
     561      message))) ; needed because of the "loop while" in read-message-loop
     562
     563(defmethod read-message-loop ((connection dcc-chat-connection))
     564  ;; no special setup
     565  (call-next-method)
     566  ;; now, make sure the connection was closed and cleaned up properly...
     567  ;; it *was* the last message, after all...
     568  ;;##TODO, maybe we need some kind of 'auto-clean' slot to indicate
     569  ;; this is the desired behaviour?
     570  )
     571
    500572
    501573;;
     
    9691041    (force-output stream)))
    9701042
    971 
    972 (defmethod apply-to-hooks ((message irc-message))
     1043;; applies to both irc- and dcc-messages
     1044(defmethod apply-to-hooks (message)
    9731045  "Applies any applicable hooks to `message'.
    9741046
Note: See TracChangeset for help on using the changeset viewer.