PreviousUpNext

15.4.1448  src/lib/x-kit/xclient/pkg/iccc/atom-imp.pkg

## atom-imp.pkg
#
# A Client-side server for atoms.
#
# See also:
#
#     src/lib/x-kit/xclient/pkg/iccc/atom.pkg

# Compiled by:
#     src/lib/x-kit/xclient/xclient-internals.sublib



stipulate
    include threadkit;                                                  # threadkit             is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
    package xt  =  xtypes;                                              # xtypes                is from   src/lib/x-kit/xclient/pkg/wire/xtypes.pkg
    package xok =  xsocket;                                             # xsocket               is from   src/lib/x-kit/xclient/pkg/wire/xsocket.pkg
    package w2v =  wire_to_value;                                       # wire_to_value         is from   src/lib/x-kit/xclient/pkg/wire/wire-to-value.pkg
    package v2w =  value_to_wire;                                       # value_to_wire         is from   src/lib/x-kit/xclient/pkg/wire/value-to-wire.pkg
    package aht =  atom_table;                                          # atom_table            is from   src/lib/x-kit/xclient/pkg/iccc/atom-table.pkg
    package dy  =  display;                                             # display               is from   src/lib/x-kit/xclient/pkg/wire/display.pkg
herein

    package   atom_imp
    : (weak)  Atom_Imp                                                  # Atom_Imp              is from   src/lib/x-kit/xclient/pkg/iccc/atom-imp.api
    {
        Atom = xt::Atom;

        Plea_Mail
          = PLEA_INTERN  (String, Oneshot_Maildrop(         Atom   ))
          | PLEA_LOOKUP  (String, Oneshot_Maildrop( Null_Or(Atom)  ))
          | PLEA_NAME    (Atom,   Oneshot_Maildrop(         String ))
          ;

        Atom_Imp
            =
            ATOM_IMP  Mailslot( Plea_Mail );

        fun intern connection arg
            =
            w2v::decode_intern_atom_reply
                (do_mailop
                    (xok::send_xrequest_and_read_reply
                        connection
                        (v2w::encode_intern_atom  arg)
                )   );

        fun make_atom_imp (dy::XDISPLAY { xsocket, ... } )
            =
            ATOM_IMP plea_slot
            where 

                plea_slot =   make_mailslot ();

                # NOTE: We are currently not using the local table;
                #       We also need to have a String --> atom mapping,
                #       and should initialize it with the standard atoms.  XXX BUGGO FIXME
                #

                 atom_table =  aht::make_hashtable  { size_hint => 32,  not_found_exception => FAIL "AtomTable" };
                 insert     =  aht::set atom_table;
                 find       =  aht::find atom_table;

                 fun do_plea (PLEA_INTERN (id, reply_1shot))
                        =>
                        set (reply_1shot, intern xsocket { name => id, only_if_exists => FALSE } );

                    do_plea (PLEA_LOOKUP (id, reply_1shot))
                        =>
                        case (intern xsocket { name => id, only_if_exists => TRUE } )
                            #
                            (xt::XATOM 0u0) =>   set (reply_1shot, NULL    );
                            atom            =>   set (reply_1shot, THE atom);
                        esac;

                    do_plea (PLEA_NAME (atom, reply_1shot))
                        =>
                        set (reply_1shot, name)
                        where 

                            name = w2v::decode_get_atom_name_reply (
                                       do_mailop (
                                           xok::send_xrequest_and_read_reply  xsocket  (
                                               v2w::encode_get_atom_name { atom }
                                           )
                                       )
                                   );
                       end;
                 end;

                 fun loop ()
                     =
                     {    do_plea  (take  plea_slot);
                          loop();
                     };

                 make_thread "atom imp" loop;
            end;                                #  fun make_server 

        fun rpc req_g (ATOM_IMP plea_slot) arg
            =
            {   reply_1shot =   make_oneshot_maildrop ();

                give  (plea_slot,  req_g (arg, reply_1shot));

                get  reply_1shot;
            };

        make_atom      =  rpc PLEA_INTERN;
        find_atom      =  rpc PLEA_LOOKUP;
        atom_to_string =  rpc PLEA_NAME;

    };                                  #  atom_imp 
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext