unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] [ELPA] Implement connman in enwc
@ 2024-03-29 22:10 Noé Lopez via Emacs development discussions.
  2024-04-01 22:51 ` Richard Stallman
  2024-09-27 17:34 ` Joseph Turner
  0 siblings, 2 replies; 11+ messages in thread
From: Noé Lopez via Emacs development discussions. @ 2024-03-29 22:10 UTC (permalink / raw)
  To: dunni; +Cc: emacs-devel, noelopez

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

Hi,

I've recently stumbled upon the enwc package, it said connman support
was experimental so I tried it and since there was no commits since a few
years I started finishing it myself.

Here is a patch that updates it to finish the connman support. I'm
sending it to emacs-devel because I understand it's hosted at ELPA (?)
If this is not the right place please tell me what needs to be done for
sending patches to inactive packages, thanks.

In the near future I would also like to finish the info manual that was
started for this package.

All the best,
Noé Lopez


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Finish-Connman-backend.patch --]
[-- Type: text/x-patch, Size: 8677 bytes --]

From b36714fd5aea523ec868227aecbe9579aa57c780 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9=20Lopez?= <noelopez@free.fr>
Date: Fri, 29 Mar 2024 16:32:50 +0100
Subject: [PATCH] Finish Connman backend

* enwc-cm.el: Finish backend.

* enwc.el: Update package metadata and document the changes.
---
 doc/enwc.texi | 10 ++++++
 enwc-cm.el    | 97 ++++++++++++++++++++++++++++++++-------------------
 enwc.el       |  9 +++--
 3 files changed, 76 insertions(+), 40 deletions(-)

diff --git a/doc/enwc.texi b/doc/enwc.texi
index dddb66df7d..154c2dcae1 100644
--- a/doc/enwc.texi
+++ b/doc/enwc.texi
@@ -75,4 +75,14 @@ First, the path to ENWC must be added to the @var{load-path} variable.  Then, in
 
 Now, simply press @kbd{M+x}, and type @kbd{ENWC}, and press @kbd{RET}.  ENWC will begin scanning for networks on the wireless interface, and display them in its buffer.
 
+@node Configuration
+@chapter Configuration
+
+TODO
+
+@node Commands
+@chapter Commands
+
+TODO
+
 @bye
diff --git a/enwc-cm.el b/enwc-cm.el
index 0dc64a7118..a94a772de3 100644
--- a/enwc-cm.el
+++ b/enwc-cm.el
@@ -1,4 +1,4 @@
-;; enwc-cm.el --- The ConnMan back-end to ENWC.
+;; enwc-cm.el --- The ConnMan back-end to ENWC. -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
 
@@ -94,31 +94,31 @@
   (concat enwc-cm-dbus-technology-path "ethernet"))
 
 (defun enwc-cm-get-network (id)
-  (nth id (enwc-cm-get-services)))
+  (assoc id (enwc-cm-get-services) #'string=))
 
 ;; connect
-(defun enwc-cm-connect (wired id)
-  (let ((path (concat enwc-cm-dbus-service-path (number-to-string id))))
-    (dbus-call-method :system
-                      enwc-cm-dbus-service
-                      path
-                      enwc-cm-dbus-service-interface
-                      "Connect")))
+(defun enwc-cm-connect (nw &optional wired)
+  (dbus-call-method :system
+                    enwc-cm-dbus-service
+                    nw
+                    enwc-cm-dbus-service-interface
+                    "Connect"))
 
 ;; disconnect
 (defun enwc-cm-disconnect (wired)
   (dbus-call-method :system
                     enwc-cm-dbus-service
-                    "/net/connman/service/CONNECTED-SERVICE"
+                    (enwc-cm-get-current-nw-id wired)
                     enwc-cm-dbus-service-interface
                     "Disconnect"))
 
 ;; scan
-(defun enwc-cm-scan (wired)
+(defun enwc-cm-scan (&optional wired)
   (let ((path (if wired
                   (enwc-cm-get-wired-tech-path)
                 (enwc-cm-get-wifi-tech-path))))
     (dbus-call-method-asynchronously :system
+				     enwc-cm-dbus-service
                                      path
                                      enwc-cm-dbus-technology-interface
                                      "Scan"
@@ -148,17 +148,22 @@
   (let ((network (enwc-cm-get-network id)))
     (car (cadr (assoc prop (cadr network))))))
 
-(defun enwc-cm-get-network-props (id wired)
+(defun enwc-cm-get-nw-props (id wired)
   (let ((network (enwc-cm-get-network id))
         props)
     ;; network should be a pair, (path . props)
     (unless network
       (error "Invalid Network Id %d" id))
     (setq props (cadr network))
-    (mapcar
-     (lambda (det)
-       (enwc-cm-dict-assoc props det))
-     enwc-cm-details-list)))
+    (let ((values (mapcar
+		   (lambda (det)
+		     (enwc-cm-dict-assoc props det))
+		   enwc-cm-details-list))))
+    `((essid . ,(or (enwc-cm-dict-assoc props "Name") "[hidden]"))
+	     (bssid . ,(enwc-cm-dict-assoc props "Ethernet/Address"))
+	     (strength . ,(enwc-cm-dict-assoc props "Strength"))
+	     (encrypt . ,(enwc-cm-dict-assoc props "Security"))
+	     (channel . ,(or (enwc-cm-dict-assoc props "Channel") 0)))))
 
 (defun enwc-cm-get-wireless-network-property (id prop)
   (enwc-cm-get-nw-prop id prop))
@@ -193,17 +198,17 @@
   (member (enwc-cm-dict-assoc (cadr service) "State")
           '("ready" "online")))
 
-(defun enwc-cm--find-connected-service (services num)
+(defun enwc-cm--find-connected-service (services)
   (if services
       (if (enwc-cm-is-connected-p (car services))
-          num
-        (enwc-cm--find-connected-service (cdr services) (1+ num)))
-    -1))
+          (car services)
+        (enwc-cm--find-connected-service (cdr services)))
+    nil))
 
-(defun enwc-cm-get-current-nw-id ()
+(defun enwc-cm-get-current-nw-id (wired) ;TODO : handle wired
   "Get the current network id."
   (let* ((services (enwc-cm-get-services)))
-    (enwc-cm--find-connected-service services 0)))
+    (car (enwc-cm--find-connected-service services))))
 
 ;; save-profile
 (defun enwc-cm-set-nw-prop (nw prop val &optional wired)
@@ -252,7 +257,7 @@
                     enwc-cm-dbus-manager-interface
                     "GetServices"))
 
-(defun enwc-cm-get-networks ()
+(defun enwc-cm-get-networks (&optional wired) ;TODO : handle wired
   (let ((services (enwc-cm-get-services)))
     (mapcar 'car services)))
 
@@ -293,15 +298,15 @@ FIELDS is an associative list of requested fields."
 (defmacro enwc-cm-agent-register-method (method)
   "Register a method METHOD with D-Bus.
 METHOD is assumed to be the camel-case D-Bus method."
-  `((dbus-register-method :session
-                          enwc-cm-dbus-agent-service
-                          enwc-cm-dbus-agent-path
-                          enwc-cm-dbus-agent-interface
-                          ,method
-                          (quote ,(car (read-from-string
-                                        (concat
-                                         "enwc-cm-agent-"
-                                         (enwc-cm-method-to-defun method))))))))
+  `(dbus-register-method :session
+                         enwc-cm-dbus-agent-service
+                         enwc-cm-dbus-agent-path
+                         enwc-cm-dbus-agent-interface
+                         ,method
+                         (quote ,(car (read-from-string
+                                       (concat
+                                        "enwc-cm-agent-"
+                                        (enwc-cm-method-to-defun method)))))))
 
 ;; Run during setup.
 (defun enwc-cm-setup ()
@@ -318,11 +323,11 @@ METHOD is assumed to be the camel-case D-Bus method."
   (enwc-cm-agent-register-method "Cancel")
 
   (dbus-call-method :system
-                    enwc-cm-dbus-manager-service
-                    enwc-cm-dbus-manager-path
+                    enwc-cm-dbus-service
+                    "/"
                     enwc-cm-dbus-manager-interface
                     "RegisterAgent"
-                    :string enwc-cm-dbus-agent-path))
+                    :object-path enwc-cm-dbus-agent-path))
 
 
 ;; (defun enwc-cm-get-encryption-type (id)
@@ -363,6 +368,28 @@ METHOD is assumed to be the camel-case D-Bus method."
 ;;     (enwc-cm-set-nw-prop wired id "Nameservers.Configuration"
 ;;                          new-dns-config)))
 
+
+(defun enwc-cm-can-load-p ()
+  (dbus-ping :system enwc-cm-dbus-service))
+
+(defun enwc-cm-is-wired ()		;TODO
+  nil)
+
+(enwc-register-backend
+ (make-enwc-backend
+  :key 'cm
+  :can-load-p #'enwc-cm-can-load-p
+  :load #'enwc-cm-setup
+  :unload #'enwc-cm-unload
+  :network-ids #'enwc-cm-get-networks
+  :scan #'enwc-cm-scan
+  :connect #'enwc-cm-connect
+  :disconnect #'enwc-cm-disconnect
+  :current-nw-id #'enwc-cm-get-current-nw-id
+  :is-connecting-p #'enwc-cm-check-connecting-p
+  :nw-props #'enwc-cm-get-nw-props
+  :is-wired-p #'enwc-cm-is-wired))
+
 (provide 'enwc-cm)
 
 ;; Local Variables:
diff --git a/enwc.el b/enwc.el
index 5bd01a5382..015dc41d01 100644
--- a/enwc.el
+++ b/enwc.el
@@ -3,8 +3,8 @@
 ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
 
 ;; Author: Ian Dunn <dunni@gnu.org>
-;; Keywords: external, network, wicd, manager, nm
-;; Version: 2.0
+;; Keywords: external, network, wicd, manager, nm, connman
+;; Version: 2.1
 ;; Package-Requires: ((emacs "25.1"))
 ;; Homepage: https://savannah.nongnu.org/p/enwc
 
@@ -30,14 +30,13 @@
 ;; ENWC is the Emacs Network Client.  It is designed to provide a front-end to
 ;; various network managers, such as NetworkManager and Wicd.
 ;;
-;; Currently, only NetworkManager and Wicd are supported, although experimental
-;; support exists for Connman.
+;; Currently, NetworkManager, Wicd and Connman are supported.
 ;;
 ;; In order to use this package, add
 ;;
 ;; (setq enwc-default-backend BACKEND-SYMBOL)
 ;;
-;; where BACKEND-SYMBOL is either 'wicd or 'nm, to your .emacs file (or other init
+;; where BACKEND-SYMBOL is either 'wicd, 'nm or 'cm, to your .emacs file (or other init
 ;; file).
 ;;
 ;; Then you can just run `enwc' to start everything.
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-09-28 18:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-29 22:10 [PATCH] [ELPA] Implement connman in enwc Noé Lopez via Emacs development discussions.
2024-04-01 22:51 ` Richard Stallman
2024-04-02 13:06   ` Noé Lopez via Emacs development discussions.
2024-04-04 22:42     ` Richard Stallman
2024-04-04 22:42     ` Richard Stallman
2024-04-05 20:00       ` Noé Lopez via Emacs development discussions.
2024-04-08 22:30         ` Richard Stallman
2024-04-14 13:01           ` Noé Lopez via Emacs development discussions.
2024-09-27 17:34 ` Joseph Turner
2024-09-28 11:03   ` Noé Lopez via Emacs development discussions.
2024-09-28 18:15     ` Joseph Turner

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).