3131; ; A specific kernel communication layer (kcomm for short) is implemented by
3232; ; extending the methods: `jupyter-comm-start' , `jupyter-comm-stop' ,
3333; ; `jupyter-comm-alive-p',`jupyter-event-handler' , `jupyter-send' , and possibly
34- ; ; `jupyter-initialize-connection ' .
34+ ; ; `jupyter-comm-initialize ' .
3535; ;
36- ; ; A client registers with the kcomm by calling `jupyter-connect-client ' and
37- ; ; de-registers with `jupyter-disconnect-client ' . The communication layer deals
36+ ; ; A client registers with the kcomm by calling `jupyter-comm-add-handler ' and
37+ ; ; de-registers with `jupyter-comm-remove-handler ' . The communication layer deals
3838; ; with "events" which are just lists with an identifying symbol as the head
3939; ; element. Events that occur on the communication layer meant for clients,
4040; ; e.g. a message received by a kernel or notification that a message was sent
6363 :group 'jupyter )
6464
6565(defclass jupyter-comm-layer ()
66- ((clients :type list :initform nil ))
66+ ((handlers :type list :initform nil ))
6767 :abstract t )
6868
69- (defmacro jupyter-comm-client -loop (comm client &rest body )
70- " Loop over COMM's clients , binding each to CLIENT before evaluating BODY."
69+ (defmacro jupyter-comm-handler -loop (comm handler &rest body )
70+ " Loop over COMM's handlers , binding each to HANDLER before evaluating BODY."
7171 (declare (indent 2 ))
72- (let ((clients (make-symbol " clients " )))
73- `(let ((, clients (oref , comm clients )))
74- (while , clients
75- (when-let* ((, client (jupyter-weak-ref-resolve (pop , clients ))))
72+ (let ((handlers (make-symbol " handlers " )))
73+ `(let ((, handlers (oref , comm handlers )))
74+ (while , handlers
75+ (when-let* ((, handler (jupyter-weak-ref-resolve (pop , handlers ))))
7676 ,@body )))))
7777
7878; ;; `jupyter-comm-layer'
8686(cl-defgeneric jupyter-comm-alive-p ((comm jupyter-comm-layer))
8787 " Return non-nil if communication has started on COMM." )
8888
89- (cl-defgeneric jupyter-connect-client ((comm jupyter-comm-layer) obj)
89+ (define-obsolete-function-alias ' jupyter-connect-client ' jupyter-comm-add-handler " 0.8.2 "
9090 " Register OBJ to receive events from COMM.
9191By default, on the first OBJ connected, `jupyter-comm-start' is
9292called if needed. This means that a call to
93- `jupyter-initialize-connection ' should precede a call to
94- `jupyter-connect-client ' ." )
93+ `jupyter-comm-initialize ' should precede a call to
94+ `jupyter-add-handler ' ." )
9595
96- (cl-defgeneric jupyter-disconnect-client ((comm jupyter-comm-layer) obj)
96+ (cl-defgeneric jupyter-comm-add-handler ((comm jupyter-comm-layer) obj)
97+ " Register OBJ to receive events from COMM.
98+ By default, on the first OBJ connected, `jupyter-comm-start' is
99+ called if needed. This means that a call to
100+ `jupyter-comm-initialize' should precede a call to
101+ `jupyter-add-handler' ." )
102+
103+ (define-obsolete-function-alias 'jupyter-disconnect-client 'jupyter-comm-remove-handler " 0.8.2"
104+ " De-register OBJ from receiving events from COMM.
105+ By default, on the last OBJ removed, `jupyter-comm-stop' is
106+ called if needed." )
107+
108+ (cl-defgeneric jupyter-comm-remove-handler ((comm jupyter-comm-layer) obj)
97109 " De-register OBJ from receiving events from COMM.
98110By default, on the last OBJ removed, `jupyter-comm-stop' is
99111called if needed." )
@@ -112,10 +124,17 @@ buffer.")
112124 " Send EVENT to the underlying kernel using COMM."
113125 (error " Subclasses need to override this method " ))
114126
115- (cl-defgeneric jupyter-initialize-connection ((comm jupyter-comm-layer) &rest _ignore)
127+ (define-obsolete-function-alias 'jupyter-initialize-connection 'jupyter-comm-initialize " 0.8.2"
128+ " Register OBJ to receive events from COMM.
129+ By default, on the first OBJ connected, `jupyter-comm-start' is
130+ called if needed. This means that a call to
131+ `jupyter-comm-initialize' should precede a call to
132+ `jupyter-add-handler' ." )
133+
134+ (cl-defgeneric jupyter-comm-initialize ((comm jupyter-comm-layer) &rest _ignore)
116135 " Initialize communication on COMM." )
117136
118- (cl-defmethod jupyter-initialize-connection ((comm jupyter-comm-layer) &rest _ignore)
137+ (cl-defmethod jupyter-comm-initialize ((comm jupyter-comm-layer) &rest _ignore)
119138 " Raise an error if COMM is already alive."
120139 (when (jupyter-comm-alive-p comm)
121140 (error " Can't initialize a live comm " )))
@@ -131,42 +150,42 @@ buffer.")
131150(cl-defmethod jupyter-channel-alive-p ((_comm jupyter-comm-layer) _channel)
132151 (error " Need to implement " ))
133152
134- (cl-defmethod jupyter-connect-client ((comm jupyter-comm-layer) obj)
135- (unless (cl-loop for ref in (oref comm clients )
153+ (cl-defmethod jupyter-comm-add-handler ((comm jupyter-comm-layer) obj)
154+ (unless (cl-loop for ref in (oref comm handlers )
136155 thereis (eq (jupyter-weak-ref-resolve ref) obj))
137- (push (jupyter-weak-ref obj) (oref comm clients )))
138- ; ; Remove any garbage collected clients
139- (oset comm clients
156+ (push (jupyter-weak-ref obj) (oref comm handlers )))
157+ ; ; Remove any garbage collected handlers
158+ (oset comm handlers
140159 (cl-remove-if-not #'jupyter-weak-ref-resolve
141- (oref comm clients )))
160+ (oref comm handlers )))
142161 (unless (jupyter-comm-alive-p comm)
143162 (jupyter-comm-start comm)))
144163
145- (cl-defmethod jupyter-disconnect-client ((comm jupyter-comm-layer) obj)
146- (oset comm clients
164+ (cl-defmethod jupyter-comm-remove-handler ((comm jupyter-comm-layer) obj)
165+ (oset comm handlers
147166 (cl-remove-if (lambda (ref )
148167 (let ((deref (jupyter-weak-ref-resolve ref)))
149168 (or (eq deref obj) (null deref))))
150- (oref comm clients ))))
169+ (oref comm handlers ))))
151170
152171(cl-defmethod jupyter-event-handler ((comm jupyter-comm-layer) event)
153- " Broadcast EVENT to all clients registered to receive them on COMM."
154- ; ; TODO: Dynamically cleanup list of garbage collected clients when looping
172+ " Broadcast EVENT to all handlers registered to receive them on COMM."
173+ ; ; TODO: Dynamically cleanup list of garbage collected handlers when looping
155174 ; ; over it.
156- (jupyter-comm-client -loop comm client
157- (run-at-time 0 nil #'jupyter-event-handler client event)))
175+ (jupyter-comm-handler -loop comm handler
176+ (run-at-time 0 nil #'jupyter-event-handler handler event)))
158177
159178; ;; `jupyter-comm-autostop'
160179
161180(defclass jupyter-comm-autostop ()
162181 ()
163182 :abstract t
164- :documentation " Stop the comm when the last client disconnects." )
183+ :documentation " Stop the comm when the last handler disconnects." )
165184
166- (cl-defmethod jupyter-disconnect-client :after ((comm jupyter-comm-autostop) _client )
167- " Stop COMM when there are no clients ."
185+ (cl-defmethod jupyter-comm-remove-handler :after ((comm jupyter-comm-autostop) _handler )
186+ " Stop COMM when there are no handlers ."
168187 (when (and (jupyter-comm-alive-p comm)
169- (zerop (length (oref comm clients ))))
188+ (zerop (length (oref comm handlers ))))
170189 (jupyter-comm-stop comm)))
171190
172191; ;; `jupyter-hb-comm'
0 commit comments