PreviousUpNext

15.4.1574  src/lib/x-kit/widget/xkit/theme/object/default/object-theme-imp.pkg

## object-theme-imp.pkg
#
# For the big picture see the imp dataflow diagrams in
#
#     src/lib/x-kit/xclient/src/window/xclient-ximps.pkg
#

# Compiled by:
#     src/lib/x-kit/widget/xkit-widget.sublib


stipulate
    include package   threadkit;                                # threadkit                     is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
#   package ap  =  client_to_atom;                              # client_to_atom                is from   src/lib/x-kit/xclient/src/iccc/client-to-atom.pkg
#   package au  =  authentication;                              # authentication                is from   src/lib/x-kit/xclient/src/stuff/authentication.pkg
#   package cpm =  cs_pixmap;                                   # cs_pixmap                     is from   src/lib/x-kit/xclient/src/window/cs-pixmap.pkg
#   package cpt =  cs_pixmat;                                   # cs_pixmat                     is from   src/lib/x-kit/xclient/src/window/cs-pixmat.pkg
#   package dy  =  display;                                     # display                       is from   src/lib/x-kit/xclient/src/wire/display.pkg
#   package xet =  xevent_types;                                # xevent_types                  is from   src/lib/x-kit/xclient/src/wire/xevent-types.pkg
#   package w2x =  windowsystem_to_xserver;                     # windowsystem_to_xserver       is from   src/lib/x-kit/xclient/src/window/windowsystem-to-xserver.pkg
#   package fil =  file__premicrothread;                        # file__premicrothread          is from   src/lib/std/src/posix/file--premicrothread.pkg
#   package fti =  font_index;                                  # font_index                    is from   src/lib/x-kit/xclient/src/window/font-index.pkg
#   package r2k =  xevent_router_to_keymap;                     # xevent_router_to_keymap       is from   src/lib/x-kit/xclient/src/window/xevent-router-to-keymap.pkg
#   package mtx =  rw_matrix;                                   # rw_matrix                     is from   src/lib/std/src/rw-matrix.pkg
#   package r8  =  rgb8;                                        # rgb8                          is from   src/lib/x-kit/xclient/src/color/rgb8.pkg
#   package rgb =  rgb;                                         # rgb                           is from   src/lib/x-kit/xclient/src/color/rgb.pkg
#   package rop =  ro_pixmap;                                   # ro_pixmap                     is from   src/lib/x-kit/xclient/src/window/ro-pixmap.pkg
#   package rw  =  root_window;                                 # root_window                   is from   src/lib/x-kit/widget/lib/root-window.pkg
#   package rwv =  rw_vector;                                   # rw_vector                     is from   src/lib/std/src/rw-vector.pkg
#   package sep =  client_to_selection;                         # client_to_selection           is from   src/lib/x-kit/xclient/src/window/client-to-selection.pkg
#   package shp =  shade;                                       # shade                         is from   src/lib/x-kit/widget/lib/shade.pkg
#   package sj  =  socket_junk;                                 # socket_junk                   is from   src/lib/internet/socket-junk.pkg
#   package x2s =  xclient_to_sequencer;                        # xclient_to_sequencer          is from   src/lib/x-kit/xclient/src/wire/xclient-to-sequencer.pkg
#   package tr  =  logger;                                      # logger                        is from   src/lib/src/lib/thread-kit/src/lib/logger.pkg
#   package tsr =  thread_scheduler_is_running;                 # thread_scheduler_is_running   is from   src/lib/src/lib/thread-kit/src/core-thread-kit/thread-scheduler-is-running.pkg
#   package u1  =  one_byte_unt;                                # one_byte_unt                  is from   src/lib/std/one-byte-unt.pkg
#   package v1u =  vector_of_one_byte_unts;                     # vector_of_one_byte_unts       is from   src/lib/std/src/vector-of-one-byte-unts.pkg
#   package v2w =  value_to_wire;                               # value_to_wire                 is from   src/lib/x-kit/xclient/src/wire/value-to-wire.pkg
#   package wg  =  widget;                                      # widget                        is from   src/lib/x-kit/widget/old/basic/widget.pkg
#   package wi  =  window;                                      # window                        is from   src/lib/x-kit/xclient/src/window/window.pkg
#   package wme =  window_map_event_sink;                       # window_map_event_sink         is from   src/lib/x-kit/xclient/src/window/window-map-event-sink.pkg
#   package wpp =  client_to_window_watcher;                    # client_to_window_watcher      is from   src/lib/x-kit/xclient/src/window/client-to-window-watcher.pkg
#   package wy  =  widget_style;                                # widget_style                  is from   src/lib/x-kit/widget/lib/widget-style.pkg
#   package e2s =  xevent_to_string;                            # xevent_to_string              is from   src/lib/x-kit/xclient/src/to-string/xevent-to-string.pkg
#   package xc  =  xclient;                                     # xclient                       is from   src/lib/x-kit/xclient/xclient.pkg
#   package g2d =  geometry2d;                                  # geometry2d                    is from   src/lib/std/2d/geometry2d.pkg
#   package xj  =  xsession_junk;                               # xsession_junk                 is from   src/lib/x-kit/xclient/src/window/xsession-junk.pkg
#   package xt  =  xtypes;                                      # xtypes                        is from   src/lib/x-kit/xclient/src/wire/xtypes.pkg
#   package xtr =  xlogger;                                     # xlogger                       is from   src/lib/x-kit/xclient/src/stuff/xlogger.pkg

    package gtg =  guiboss_to_guishim;                          # guiboss_to_guishim            is from   src/lib/x-kit/widget/theme/guiboss-to-guishim.pkg

    package gt  =  guiboss_types;                               # guiboss_types                 is from   src/lib/x-kit/widget/gui/guiboss-types.pkg
    #
    package csi =  objectspace_imp;                             # objectspace_imp               is from   src/lib/x-kit/widget/space/object/objectspace-imp.pkg

    #
    package o2c =  object_to_objectspace;                       # object_to_objectspace         is from   src/lib/x-kit/widget/space/object/object-to-objectspace.pkg
    #
    package g2d =  geometry2d;                                  # geometry2d                    is from   src/lib/std/2d/geometry2d.pkg
    #
    tracefile   =  "widget-unit-test.trace.log";
herein

    package object_theme_imp
    :       Object_Theme_Imp                                                                                            # Object_Theme_Imp      is from   src/lib/x-kit/widget/theme/object/object-theme-imp.api
    {
        #
        include package   gui_to_object_theme;                                                                          # gui_to_object_theme   is from   src/lib/x-kit/widget/theme/object/gui-to-object-theme.pkg
        #
        Theme_State = Ref( Void );                                                                                      # Holds all nonephemeral mutable state maintained by skin.

        Imports = {                                                                                                     # Ports we use, provided by other imps.
                    int_sink:           Int -> Void,
                    guiboss_to_guishim: gtg::Guiboss_To_Guishim
                  };

        Me_Slot = Mailslot( { imports:  Imports,
                                  me:           Theme_State,
                                  run_gun':     Run_Gun,
                                  end_gun':     End_Gun
                                }
                              );
        Exports = {                                                                                                     # Ports we provide for use by other imps.
                    gui_to_object_theme:        Gui_To_Object_Theme
                  };


        Option = MICROTHREAD_NAME String;                                                                               # 

        Object_Theme_Egg =  Void -> (Exports,   (Imports, Run_Gun, End_Gun) -> Void);

        Runstate =  {                                                                                                   # These values will be statically globally visible throughout the code body for the imp.
                      me:               Theme_State,                                                                    # 
                      imports:          Imports,                                                                        # Imps to which we send requests.
                      to:               Replyqueue,                                                                     # The name makes   foo::pass_something(imp) to {. ... }   syntax read well.
                      end_gun':         End_Gun                                                                         # We shut down the microthread when this fires.
                    };

        Theme_Q    = Mailqueue( Runstate -> Void );

        fun run ( theme_q:              Theme_Q,                                                                        # 
                  #
                  runstate as
                  {                                                                                                     # These values will be statically globally visible throughout the code body for the imp.
                    me:                 Theme_State,                                                                    # 
                    imports:            Imports,                                                                        # Imps to which we send requests.
                    to:                 Replyqueue,                                                                     # The name makes   foo::pass_something(imp) to {. ... }   syntax read well.
                    end_gun':           End_Gun                                                                         # We shut down the microthread when this fires.
                  }
                )
            =
            loop ()
            where
                fun loop ()                                                                                             # Outer loop for the imp.
                    =
                    {   do_one_mailop' to [
                            #
                            (end_gun'                        ==>  shut_down_theme_imp'),
                            (take_from_mailqueue' theme_q    ==>  do_theme_plea)
                        ];

                        loop ();
                    }   
                    where
                        fun do_theme_plea thunk
                            =
                            thunk runstate;

                        fun shut_down_theme_imp' ()
                            =
                            {
                                thread_exit { success => TRUE };                                                        # Will not return.      
                            };
                    end;
            end;        



        fun startup   (reply_oneshot:  Oneshot_Maildrop( (Me_Slot, Exports) ))   ()                                     # Root fn of imp microthread.  Note currying.
            =
            {   me_slot  =  make_mailslot  ()   :  Me_Slot;
                #
                gui_to_object_theme
                    =
                    { do_something,
                      objectspace
                    };

                to          =  make_replyqueue();
                #
                put_in_oneshot (reply_oneshot, (me_slot, { gui_to_object_theme }));                                     # Return value from object_theme_egg'().

                (take_from_mailslot  me_slot)                                                                           # Input args from object_theme_egg'().
                    ->
                    { me, imports, run_gun', end_gun' };

                block_until_mailop_fires  run_gun';                                                                     # Wait for the starting gun.

                run (theme_q, { me, imports, to, end_gun' });                                                           # Will not return.
            }
            where
                theme_q     =  make_mailqueue (get_current_microthread()):  Theme_Q;

                fun do_something (i: Int)                                                                               # PUBLIC.
                    =   
                    put_in_mailqueue  (theme_q,
                        #
                        \\ ({ me, imports, ... }: Runstate)
                            =
                            imports.int_sink i                                                                          # Demonstrate use of imports.
                    );

                fun objectspace  (options: gt::Objectspace_Arg)                                                         # PUBLIC.
                    =
                    {   reply_oneshot =  make_oneshot_maildrop():  Oneshot_Maildrop( csi::Objectspace_Egg );
                        #
                        put_in_mailqueue  (theme_q,
                            #
                            \\ ({ me, ... })
                                =
                                {   (csi::make_objectspace_egg  options NULL) -> objectspace_egg;
                                    #
                                    put_in_oneshot (reply_oneshot, objectspace_egg);
                                }
                        );

                        get_from_oneshot reply_oneshot;
                    };

            end;


        fun process_options (options: List(Option), { name })
            =
            {   my_name   = REF name;
                #
                apply  do_option  options
                where
                    fun do_option (MICROTHREAD_NAME n)  =   my_name := n;
                end;

                { name => *my_name };
            };


        ##########################################################################################
        # PUBLIC.
        #
        fun make_object_theme_egg (options: List(Option))                                                               # PUBLIC. PHASE 1: Construct our state and initialize from 'options'.
            =
            {   (process_options (options, { name => "tmp" }))
                    ->
                    { name };
        
                me = REF ();

                \\ () = {   reply_oneshot = make_oneshot_maildrop():  Oneshot_Maildrop( (Me_Slot, Exports) );           # PUBLIC. PHASE 2: Start our microthread and return our Exports to caller.
                            #
                            xlogger::make_thread  name  (startup  reply_oneshot);                                       # Note that startup() is curried.

                            (get_from_oneshot  reply_oneshot) -> (me_slot, exports);

                            fun phase3                                                                                  # PUBLIC. PHASE 3: Accept our Imports, then wait for Run_Gun to fire.
                                (
                                  imports:      Imports,
                                  run_gun':     Run_Gun,        
                                  end_gun':     End_Gun
                                )
                                =
                                {
                                    put_in_mailslot  (me_slot, { me, imports, run_gun', end_gun' });
                                };

                            (exports, phase3);
                        };
            };
    };

end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext