[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ba6061b 51/76: Created more robust backend system.
From: |
Ian Dunn |
Subject: |
[elpa] master ba6061b 51/76: Created more robust backend system. |
Date: |
Thu, 23 Feb 2017 19:42:52 -0500 (EST) |
branch: master
commit ba6061b886e549b9170a234f27722e5721948f92
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
Created more robust backend system.
---
lisp/enwc-backend.el | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++
lisp/enwc-setup.el | 84 -----------------------------
2 files changed, 148 insertions(+), 84 deletions(-)
diff --git a/lisp/enwc-backend.el b/lisp/enwc-backend.el
new file mode 100644
index 0000000..e79b8d2
--- /dev/null
+++ b/lisp/enwc-backend.el
@@ -0,0 +1,148 @@
+;;; enwc-backend.el --- Back-end functions for ENWC.
+
+;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
+
+;; Author: Ian Dunn <address@hidden>
+;; Keywords: external, network, wicd, manager, nm
+;; Version: 2.0
+;; Homepage: https://savannah.nongnu.org/p/enwc
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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, or (at your option)
+;; any later version.
+
+;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'map)
+
+(cl-defstruct enwc-backend
+ key ;; The symbol that identifies this backend.
+ ;; Loading/unloading functions
+ can-load-p
+ load
+ unload
+ ;; Scan interface
+ network-ids
+ scan
+ wireless-nw-props
+ ;; Connect/disconnect
+ connect
+ disconnect
+ ;; Maintenance
+ current-nw-id
+ is-connecting-p
+ is-wired-p
+ ;; get-profile-info
+ ;; save-nw-settings
+ )
+
+(defvar enwc-registered-backend-alist nil
+ "Alist of registered ENWC backends.
+
+Each entry in this list is of the form
+
+ (KEY . DEFINITION)
+
+Where KEY is a symbol identifying the backend, and DEFINITION is
+an enwc-backend struct.")
+
+(defcustom enwc-default-backend nil
+ "Key of the default backend to use."
+ :type 'symbol
+ :group 'enwc)
+
+(defvar enwc--current-backend nil)
+
+(defun enwc-register-backend (definition &optional forcep)
+ "Register the backend KEY with DEFINITION.
+
+Signals an error if a backend with KEY already exists and FORCEP is nil."
+ (cl-check-type definition enwc-backend)
+ (let ((key (enwc-backend-key definition)))
+ (when (and (map-contains-key enwc-registered-backend-alist key) (not
forcep))
+ (error "An ENWC backend with key '%s' has already been registered." key))
+ (map-put enwc-registered-backend-alist key definition)))
+
+;; Convenience functions to work with backends
+
+(defun enwc--can-load-p (backend)
+ (funcall (enwc-backend-can-load-p backend)))
+
+(defun enwc--load (backend)
+ (funcall (enwc-backend-load backend)))
+
+(defun enwc--unload (backend)
+ (funcall (enwc-backend-unload backend)))
+
+(defun enwc--scan (backend)
+ (funcall (enwc-backend-scan backend)))
+
+(defun enwc--network-ids (backend)
+ (funcall (enwc-backend-network-ids backend)))
+
+(defun enwc--wireless-nw-props (backend id)
+ (funcall (enwc-backend-wireless-nw-props backend) id))
+
+(defun enwc--connect (backend id &optional wired-p)
+ (funcall (enwc-backend-connect backend) id wired-p))
+
+(defun enwc--disconnect (backend &optional wired-p)
+ (funcall (enwc-backend-disconnect backend) wired-p))
+
+(defun enwc--current-nw-id (backend &optional wired-p)
+ (funcall (enwc-backend-current-nw-id backend) wired-p))
+
+(defun enwc--is-connecting-p (backend)
+ (funcall (enwc-backend-is-connecting-p backend)))
+
+(defun enwc--is-wired-p (backend)
+ (funcall (enwc-backend-is-wired-p backend)))
+
+;; Handle loading/unloading
+
+(defun enwc-load-backend (backend)
+ "Load BACKEND, which is a symbol denoting the backend to use."
+ (interactive
+ (list
+ (intern (completing-read "Backend: " enwc-registered-backend-alist nil
t))))
+ (when (and enwc--current-backend
+ (not (eq (enwc-backend-key enwc--current-backend) backend)))
+ (enwc-unload-current-backend))
+
+ (let ((new-backend (map-elt enwc-registered-backend-alist backend)))
+ (unless new-backend
+ (error "No registered backend %s" backend))
+
+ (unless (enwc--can-load-p new-backend)
+ (error "Backend %s is not usable." backend))
+
+ (enwc--load new-backend)
+ (setq enwc--current-backend new-backend)))
+
+(defun enwc-load-default-backend ()
+ (enwc-load-backend (map-elt enwc-registered-backend-alist
enwc-default-backend)))
+
+(defun enwc-unload-current-backend ()
+ "Unload the current backend."
+ (when enwc--current-backend
+ (enwc--unload enwc--current-backend)
+ (setq enwc--current-backend nil)))
+
+(provide 'enwc-backend)
+
+;;; enwc-backend.el ends here
diff --git a/lisp/enwc-setup.el b/lisp/enwc-setup.el
deleted file mode 100644
index 1e11100..0000000
--- a/lisp/enwc-setup.el
+++ /dev/null
@@ -1,84 +0,0 @@
-;; enwc-setup.el - Setup routines for ENWC
-
-;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
-
-;; Author: Ian Dunn <address@hidden>
-;; Keywords: network, wicd, manager, nm
-;; Version: 2.0
-;; Homepage: https://savannah.nongnu.org/p/enwc
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs 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, or (at your option)
-;; any later version.
-
-;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the Free
-;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-;; 02110-1301, USA.
-
-;;; Commentary:
-
-;;; Code:
-
-(require 'enwc)
-(require 'enwc-wicd)
-(require 'enwc-nm)
-
-(defun enwc-load-backend (&optional backend)
- "Load the backend BACKEND."
- (interactive)
- (unless backend
- (setq backend
- (intern (completing-read "Backend: " enwc-backends nil t))))
- (when (and enwc-current-backend
- (not (eq enwc-current-backend backend)))
- (enwc-unload-backend))
- (let ((service (symbol-value (intern (concat "enwc-"
- (symbol-name backend)
- "-dbus-service")))))
- ;;TODO: Might need a better way of doing this.
- ;; NM doesn't seem to want to ping.
- (unless (dbus-ping :system service)
- (error "Backend %s is not usable." backend))
-
- (enwc-call-backend-function "load" backend)
- (setq enwc-current-backend backend)))
-
-(defun enwc-unload-backend ()
- "Unload the current backend."
- (when enwc-current-backend
- (enwc-call-backend-function "unload")
- (setq enwc-current-backend nil)))
-
-;;;###autoload
-(defun enwc-setup ()
- "Set up ENWC.
-This sets up ENWC and confirms that one of the backends can be found on D-Bus."
- (when enwc-display-mode-line
- (enwc-enable-display-mode-line))
-
- (when (and enwc-auto-scan
- (> enwc-auto-scan-interval 0)
- (not enwc-scan-timer))
- (setq enwc-scan-timer
- (run-at-time t enwc-auto-scan-interval 'enwc-scan t)))
-
- (let ((back-list enwc-backends)
- cur-back pass)
- (while (and back-list (not pass))
- (setq cur-back (pop back-list))
- (setq pass (ignore-errors (enwc-load-backend cur-back))))
- (unless pass
- (error "No usable backend was found."))))
-
-(provide 'enwc-setup)
-
-;;; enwc-setup.el ends here
- [elpa] master 17f27c6 18/76: (enwc-nm-prop-to-prop, enwc-nm-get-sec-types): Removed., (continued)
- [elpa] master 17f27c6 18/76: (enwc-nm-prop-to-prop, enwc-nm-get-sec-types): Removed., Ian Dunn, 2017/02/23
- [elpa] master ee90297 31/76: (enwc-nm.el): Fixed several docstrings, and file header., Ian Dunn, 2017/02/23
- [elpa] master 4e0d5a2 41/76: Cosmetic changes., Ian Dunn, 2017/02/23
- [elpa] master 8f21449 45/76: Removed tag 2.0, Ian Dunn, 2017/02/23
- [elpa] master ec0539b 42/76: Fixed enwc-setup to be able to be called more than once., Ian Dunn, 2017/02/23
- [elpa] master 5c63470 48/76: Fixed autoloads generation and added hgignore., Ian Dunn, 2017/02/23
- [elpa] master 43c98da 50/76: Changed enwc-last-scan to a hashtable., Ian Dunn, 2017/02/23
- [elpa] master c6585bb 47/76: Added autoloads, Ian Dunn, 2017/02/23
- [elpa] master 48e7aa4 55/76: Updated Makefile, Ian Dunn, 2017/02/23
- [elpa] master 2e07c3a 54/76: Began work on WPA backend. EXPERIMENTAL!, Ian Dunn, 2017/02/23
- [elpa] master ba6061b 51/76: Created more robust backend system.,
Ian Dunn <=
- [elpa] master ad38333 59/76: Cleaned up enwc-refresh-widths and changed enwc-details-list to enwc-column-specs., Ian Dunn, 2017/02/23
- [elpa] master a46fe3c 64/76: Don't switch to the ENWC buffer when processing a scan., Ian Dunn, 2017/02/23
- [elpa] master 33515f8 66/76: Silenced byte-compiler., Ian Dunn, 2017/02/23
- [elpa] master bcb33e6 30/76: (enwc-get-networks): Improved docstring., Ian Dunn, 2017/02/23
- [elpa] master 245a82f 52/76: Moved Wicd and NetworkManager backends to new system., Ian Dunn, 2017/02/23
- [elpa] master 3b1bbc6 69/76: Fixed autoloads target in Makefile, Ian Dunn, 2017/02/23
- [elpa] master 8c17c8c 73/76: Updated hgignore to ignore elc files in top-level directory., Ian Dunn, 2017/02/23
- [elpa] master a3c59cc 74/76: Updated version to 2.0beta1, Ian Dunn, 2017/02/23
- [elpa] master 2e271c6 72/76: Moved lisp files into top-level directory., Ian Dunn, 2017/02/23
- [elpa] master b673e3a 63/76: Added default setup and removed experimental WPA supplicant backend., Ian Dunn, 2017/02/23