Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 155 lines (116 sloc) 4.654 kb
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
;;; rudel-transport.el --- Rudel transport interface and backend
;;
;; Copyright (C) 2009, 2010 Jan Moringen
;;
;; Author: Jan Moringen <scymtym@users.sourceforge.net>
;; Keywords: rudel, backend, transport
;; X-RCS: $Id:$
;;
;; This file is part of Rudel.
;;
;; Rudel 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.
;;
;; Rudel 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 Rudel. If not, see <http://www.gnu.org/licenses>.


;;; Commentary:
;;
;; This file contains the interface definition for Rudel transport
;; objects and Rudel transport backends.


;;; History:
;;
;; 0.2 - Socket-like interface
;;
;; 0.1 - Initial version


;;; Code:
;;

(require 'eieio)

(require 'rudel-errors) ;; for `rudel-error'
(require 'rudel-backend)


;;; Error conditions
;;

;; rudel-malformed-message

(intern "rudel-malformed-message")

(put 'rudel-malformed-message 'error-conditions
     '(error
       rudel-error rudel-malformed-message))

(put 'rudel-malformed-message 'error-message
     "Received malformed message")


;;; Class rudel-transport
;;

(defclass rudel-transport ()
  ()
  "Interface for transport objects.")

(defgeneric rudel-set-filter ((this rudel-transport) handler)
  "Install HANDLER as dispatcher for messages received by THIS.")

(defgeneric rudel-set-sentinel ((this rudel-transport) handler)
  "Install HANDLER as dispatcher for state changes of THIS.")

(defgeneric rudel-send ((this rudel-transport) data)
  "Send DATA through THIS transport object.")

(defgeneric rudel-close ((this rudel-transport))
  "Close THIS.")

;; TODO we could get rid of this if we required implementations to
;; queue messages until a handler is installed
(defgeneric rudel-start ((this rudel-transport))
  "Start THIS.")


;;; Class rudel-listener
;;

(defclass rudel-listener ()
  ()
  "Interface for listener objects.
Listener objects wait for incoming connections and create
transport objects representing such connections."
:abstract t)

(defgeneric rudel-set-dispatcher ((this rudel-listener) handler)
  "Install HANDLER as dispatch function for incoming connections.
HANDLER has to accept a single argument which will be a transport
object representing the incoming connection.")

(defgeneric rudel-close ((this rudel-listener))
  "Cause THIS to stop listening for incoming connections.")


;;; Class rudel-transport-backend
;;

(defclass rudel-transport-backend (rudel-backend)
  ()
  "Interface implemented by transport backends."
  :abstract t)

(defgeneric rudel-ask-connect-info ((this rudel-transport-backend)
&optional info)
  "Retrieve information for making a new connection.
When INFO is non-nil, augment INFO to produce new list.
Return a property list that contains the collected information.")

(defgeneric rudel-make-connection ((this rudel-transport-backend)
info info-callback
&optional progress-callback)
  "Create a transport object according to INFO.

INFO-CALLBACK is called when the information provided in INFO is
not sufficient for establishing the requested
connection. INFO-CALLBACK has to accept the backend object and a
property list containing the current connection information and
return a property list containing the augmented connection
information.

When non-nil, PROGRESS-CALLBACK has to accept two arguments: a
state string and a float in the range [0, 1] indicating the
progress. PROGRESS-CALLBACK may be called repeatedly while the
connection is established.

The returned transport object has to be in a stopped state in the
sense that it does not attempt to dispatch any data to the filter
function before `rudel-start' has been called.")

(defgeneric rudel-wait-for-connections ((this rudel-transport-backend)
info info-callback)
  "Create and return listener object according to INFO.
INFO has to be a property list specifying desired properties of
the created listener.

INFO-CALLBACK is called when the information provided in INFO is
not sufficient for creating the requested listener. INFO-CALLBACK
has to accept the backend object and a property list containing
the current information and return a property list containing
augmented information.")

(provide 'rudel-transport)
;;; rudel-transport.el ends here
Something went wrong with that request. Please try again.