Revision: 6473
Author: iratqq
Date: Mon Jun 21 18:19:54 2010
Log: * scm/annotation-filter.scm (annotation-filter-open-unix-domain-socket)
  (annotation-filter-open-with-tcp-socket)
  (annotation-filter-open-with-pipe):
  - New function.
  (annotation-filter-init):
  - Check server type.
  (annotation-filter-release):
  - Close ports.
* scm/im-custom.scm (annotation-filter-server-setting?)
  (annotation-filter-unix-domain-socket-path)
  (annotation-filter-tcpserver-name)
  (annotation-filter-tcpserver-port):
  - Add new custom variables.

http://code.google.com/p/uim/source/detail?r=6473

Modified:
 /trunk/scm/annotation-filter.scm
 /trunk/scm/im-custom.scm

=======================================
--- /trunk/scm/annotation-filter.scm    Mon Jun 21 10:02:55 2010
+++ /trunk/scm/annotation-filter.scm    Mon Jun 21 18:19:54 2010
@@ -29,7 +29,9 @@
 ;;; SUCH DAMAGE.
 ;;;;

-(require-extension (srfi 1))
+(require-extension (srfi 1 2))
+(require "socket.scm")
+(require "fileio.scm")
 (require "process.scm")

 ;;
@@ -41,13 +43,32 @@
 ;; quit_message = "QUIT\n"
 ;;

-(define annotation-filter-pipe-pair #f)
+(define annotation-filter-socket-pair #f)
+
+(define (annotation-filter-open-unix-domain-socket)
+ (and-let* ((fd (unix-domain-socket-connect annotation-filter-unix-domain-socket-path)))
+    (cons fd fd)))
+
+(define (annotation-filter-open-with-tcp-socket)
+  (and-let* ((fd (tcp-connect annotation-filter-tcpserver-name
+                              annotation-filter-tcpserver-port)))
+     (cons fd fd)))
+
+(define (annotation-filter-open-with-pipe)
+  (process-io annotation-filter-command))

 (define (annotation-filter-init)
   (and (not (string=? "" annotation-filter-command))
-       (let ((fds (process-io annotation-filter-command)))
-         (set! annotation-filter-pipe-pair (cons (open-file-port (car fds))
- (open-file-port (cdr fds)))) + (let ((fds (cond ((eq? annotation-filter-server-setting? 'unixdomain)
+                         (annotation-filter-open-with-unix-domain-socket))
+                        ((eq? annotation-filter-server-setting? 'tcpserver)
+                         (annotation-filter-open-with-tcp-socket))
+                        ((eq? annotation-filter-server-setting? 'pipe)
+                         (annotation-filter-open-with-pipe))
+                        (else
+ (uim-notify-fatal (N_ "Custom filter connection is not defined")))))) + (set! annotation-filter-socket-pair (cons (open-file-port (car fds)) + (open-file-port (cdr fds))))
          #t)))

 (define (annotation-filter-read-message iport)
@@ -58,14 +79,19 @@
         (loop (file-read-line iport) (string-append rest line)))))

 (define (annotation-filter-get-text text enc)
-  (or (and annotation-filter-pipe-pair
-           (let ((iport (car annotation-filter-pipe-pair))
-                 (oport (cdr annotation-filter-pipe-pair)))
+  (or (and annotation-filter-socket-pair
+           (and-let* ((iport (car annotation-filter-socket-pair))
+                      (oport (cdr annotation-filter-socket-pair)))
              (file-display (format "GET\t~a\t~a\n" text enc) oport)
              (annotation-filter-read-message iport)))
       ""))

 (define (annotation-filter-release)
-  (if annotation-filter-pipe-pair
-      (file-display "QUIT\n" (cdr annotation-filter-pipe-pair)))
+  (and annotation-filter-socket-pair
+       (and-let* ((iport (car annotation-filter-socket-pair))
+                  (oport (cdr annotation-filter-socket-pair)))
+         (file-display "QUIT\n" oport)
+         (if (not (equal? iport oport))
+             (close-file-port oport))
+         (close-file-port iport)))
   #t)
=======================================
--- /trunk/scm/im-custom.scm    Mon Jun 21 10:02:55 2010
+++ /trunk/scm/im-custom.scm    Mon Jun 21 18:19:54 2010
@@ -676,21 +676,79 @@
                         (eq? annotation-agent 'dict))))

 (define-custom-group 'filter
-                    (N_ "Custom filter for annotation")
+                    (N_ "Custom filter")
                     (N_ "long description will be here."))

-(define-custom 'annotation-filter-command
-  ""
+(define-custom 'annotation-filter-server-setting? 'pipe
   '(annotation filter)
+  (list 'choice
+        (list 'unixdomain
+              (N_ "Unix domain")
+ (N_ "Use UNIX domain socket to communicate with custom filter."))
+        (list 'tcpserver
+              (N_ "TCP server")
+              (N_ "Use tcp server to communicate with custom filter"))
+        (list 'pipe
+              (N_ "Pipe")
+ (N_ "Use pipe. spawn new annotation-filter process to communicate with custom filter")))
+  (N_ "Custom filter connection setting")
+  (N_ "long description will be here."))
+
+(define-custom 'annotation-filter-unix-domain-socket-path "/path/of/socket"
+  '(annotation filter)
+  '(pathname regular-file)
+  (N_ "Path of custom filter socket")
+  (N_ "long description will be here."))
+
+(define-custom 'annotation-filter-tcpserver-name "localhost"
+  '(annotation filter)
+  '(string ".*")
+  (N_ "Custom filter server address")
+  (N_ "long description will be here."))
+
+(define-custom 'annotation-filter-tcpserver-port 6789
+  '(annotation filter)
+  '(integer 0 65535)
+  (N_ "Custom filter server port")
+  (N_ "long description will be here."))
+
+(define-custom 'annotation-filter-command "/path/of/filter-program"
+  '(annotation filter)
   '(pathname regular-file)
   (N_ "Path of custom filter")
   (N_ "long description will be here."))

+(custom-add-hook 'annotation-filter-unix-domain-socket-path
+                'custom-activity-hooks
+                (lambda ()
+                   (and enable-annotation?
+                        (eq? annotation-agent 'filter)
+                        (eq? annotation-filter-server-setting?
+                             'unixdomain))))
+
+(custom-add-hook 'annotation-filter-tcpserver-name
+                'custom-activity-hooks
+                (lambda ()
+                   (and enable-annotation?
+                        (eq? annotation-agent 'filter)
+                        (eq? annotation-filter-server-setting?
+                             'tcpserver))))
+
+(custom-add-hook 'annotation-filter-tcpserver-port
+                'custom-activity-hooks
+                (lambda ()
+                   (and enable-annotation?
+                        (eq? annotation-agent 'filter)
+                        (eq? annotation-filter-server-setting?
+                             'tcpserver))))
+
 (custom-add-hook 'annotation-filter-command
                 'custom-activity-hooks
                  (lambda ()
                    (and enable-annotation?
-                        (eq? annotation-agent 'filter))))
+                        (eq? annotation-agent 'filter)
+                        (eq? annotation-filter-server-setting?
+                             'pipe))))

 ;; uim-xim specific custom
 (define-custom-group 'xim

Reply via email to