1999-12-16 04:25:11 -08:00
|
|
|
(*************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml LablTk library *)
|
|
|
|
(* *)
|
|
|
|
(* Francois Rouaix, Francois Pessaux and Jun Furuse *)
|
|
|
|
(* projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1999 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
|
|
(* This file is distributed under the terms of the GNU Library *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* General Public License, with the special exception on linking *)
|
|
|
|
(* described in file ../../../LICENSE. *)
|
1999-12-16 04:25:11 -08:00
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
open Unix
|
2001-09-06 01:52:32 -07:00
|
|
|
open Support
|
1999-11-30 06:59:39 -08:00
|
|
|
open Protocol
|
|
|
|
|
|
|
|
external add_file_input : file_descr -> cbid -> unit
|
|
|
|
= "camltk_add_file_input"
|
|
|
|
external rem_file_input : file_descr -> unit
|
|
|
|
= "camltk_rem_file_input"
|
|
|
|
external add_file_output : file_descr -> cbid -> unit
|
|
|
|
= "camltk_add_file_output"
|
|
|
|
external rem_file_output : file_descr -> unit
|
|
|
|
= "camltk_rem_file_output"
|
|
|
|
|
|
|
|
(* File input handlers *)
|
|
|
|
|
2000-04-02 18:57:52 -07:00
|
|
|
let fd_table = Hashtbl.create 37 (* Avoid space leak in callback table *)
|
1999-11-30 06:59:39 -08:00
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let add_fileinput ~fd ~callback:f =
|
1999-11-30 06:59:39 -08:00
|
|
|
let id = new_function_id () in
|
2001-09-06 01:52:32 -07:00
|
|
|
Hashtbl'.add callback_naming_table ~key:id ~data:(fun _ -> f());
|
|
|
|
Hashtbl'.add fd_table ~key:(fd, 'r') ~data:id;
|
1999-11-30 06:59:39 -08:00
|
|
|
if !Protocol.debug then begin
|
|
|
|
Protocol.prerr_cbid id; prerr_endline " for fileinput"
|
|
|
|
end;
|
|
|
|
add_file_input fd id
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let remove_fileinput ~fd =
|
1999-11-30 06:59:39 -08:00
|
|
|
try
|
2000-04-02 18:57:52 -07:00
|
|
|
let id = Hashtbl.find fd_table (fd, 'r') in
|
1999-11-30 06:59:39 -08:00
|
|
|
clear_callback id;
|
2000-04-02 18:57:52 -07:00
|
|
|
Hashtbl.remove fd_table (fd, 'r');
|
1999-11-30 06:59:39 -08:00
|
|
|
if !Protocol.debug then begin
|
|
|
|
prerr_string "clear ";
|
|
|
|
Protocol.prerr_cbid id;
|
|
|
|
prerr_endline " for fileinput"
|
|
|
|
end;
|
|
|
|
rem_file_input fd
|
|
|
|
with
|
|
|
|
Not_found -> ()
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let add_fileoutput ~fd ~callback:f =
|
1999-11-30 06:59:39 -08:00
|
|
|
let id = new_function_id () in
|
2001-09-06 01:52:32 -07:00
|
|
|
Hashtbl'.add callback_naming_table ~key:id ~data:(fun _ -> f());
|
|
|
|
Hashtbl'.add fd_table ~key:(fd, 'w') ~data:id;
|
1999-11-30 06:59:39 -08:00
|
|
|
if !Protocol.debug then begin
|
|
|
|
Protocol.prerr_cbid id; prerr_endline " for fileoutput"
|
|
|
|
end;
|
|
|
|
add_file_output fd id
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let remove_fileoutput ~fd =
|
1999-11-30 06:59:39 -08:00
|
|
|
try
|
2000-04-02 18:57:52 -07:00
|
|
|
let id = Hashtbl.find fd_table (fd, 'w') in
|
1999-11-30 06:59:39 -08:00
|
|
|
clear_callback id;
|
2000-04-02 18:57:52 -07:00
|
|
|
Hashtbl.remove fd_table (fd, 'w');
|
1999-11-30 06:59:39 -08:00
|
|
|
if !Protocol.debug then begin
|
|
|
|
prerr_string "clear ";
|
|
|
|
Protocol.prerr_cbid id;
|
|
|
|
prerr_endline " for fileoutput"
|
|
|
|
end;
|
|
|
|
rem_file_output fd
|
|
|
|
with
|
|
|
|
Not_found -> ()
|
|
|
|
|