## xsocket-ximps.pkg
#
# For the big picture see the imp dataflow diagrams in
#
#
src/lib/x-kit/xclient/src/window/xclient-ximps.pkg#
# xsocket-ximps wraps up the ximps
#
# inbuf_ximp; # inbuf_ximp is from
src/lib/x-kit/xclient/src/wire/inbuf-ximp.pkg# outbuf_ximp; # outbuf_ximp is from
src/lib/x-kit/xclient/src/wire/outbuf-ximp.pkg# xsequencer_ximp; # xsequencer_ximp is from
src/lib/x-kit/xclient/src/wire/xsequencer-ximp.pkg# decode_xpackets_ximp; # decode_xpackets_ximp is from
src/lib/x-kit/xclient/src/wire/decode-xpackets-ximp.pkg#
# to look like a single logical ximp to the rest of
# the system.
# Compiled by:
#
src/lib/x-kit/xclient/xclient-internals.sublibstipulate
include package threadkit; # threadkit is from
src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg #
#
package un = unt; # unt is from
src/lib/std/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 w2v = wire_to_value; # wire_to_value is from
src/lib/x-kit/xclient/src/wire/wire-to-value.pkg package g2d = geometry2d; # geometry2d is from
src/lib/std/2d/geometry2d.pkg package xtr = xlogger; # xlogger is from
src/lib/x-kit/xclient/src/stuff/xlogger.pkg package sok = socket__premicrothread; # socket__premicrothread is from
src/lib/std/socket--premicrothread.pkg# package op = xsequencer_to_outbuf; # xsequencer_to_outbuf is from
src/lib/x-kit/xclient/src/wire/xsequencer-to-outbuf.pkg package x2s = xclient_to_sequencer; # xclient_to_sequencer is from
src/lib/x-kit/xclient/src/wire/xclient-to-sequencer.pkg package xes = xevent_sink; # xevent_sink is from
src/lib/x-kit/xclient/src/wire/xevent-sink.pkg package xew = xerror_well; # xerror_well is from
src/lib/x-kit/xclient/src/wire/xerror-well.pkg package xt = xtypes; # xtypes is from
src/lib/x-kit/xclient/src/wire/xtypes.pkg# package xet = xevent_types; # xevent_types is from
src/lib/x-kit/xclient/src/wire/xevent-types.pkg package ix = inbuf_ximp; # inbuf_ximp is from
src/lib/x-kit/xclient/src/wire/inbuf-ximp.pkg package ox = outbuf_ximp; # outbuf_ximp is from
src/lib/x-kit/xclient/src/wire/outbuf-ximp.pkg package xx = xsequencer_ximp; # xsequencer_ximp is from
src/lib/x-kit/xclient/src/wire/xsequencer-ximp.pkg package dxx = decode_xpackets_ximp; # decode_xpackets_ximp is from
src/lib/x-kit/xclient/src/wire/decode-xpackets-ximp.pkgherein
# This impset is typically instantiated by:
#
#
src/lib/x-kit/xclient/src/wire/xsocket-ximps.pkg package xsocket_ximps
: Xsocket_Ximps # Xsocket_Ximps is from
src/lib/x-kit/xclient/src/wire/xsocket-ximps.api {
Imports = { # Ports we use, provided by other imps.
xevent_sink: xes::Xevent_Sink # Carries xevents from decode_xpackets_ximp to "xbuf to widgettree root xevent router imp".
};
# We export two ports for use by external ximps,
# who will send requests to them:
#
# o Configstate for initial configuration.
# o xsequencer for widget requests.
#
Exports = { # Ports we provide for use by other imps.
xclient_to_sequencer: x2s::Xclient_To_Sequencer, # Requests from widget/application code.
xerror_well: xew::Xerror_Well # Errors from the X server.
};
Option = MICROTHREAD_NAME String; #
Xsocket_Ximps_Egg = Void -> (Exports, (Imports, Run_Gun, End_Gun) -> Void);
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_xsocket_ximps_egg # PUBLIC. PHASE 1: Construct our state and initialize from 'options'.
(
socket: sok::Socket (X, sok::Stream(sok::Active)), # Socket to use.
options: List(Option)
)
=
{ (process_options (options, { name => "tmp" }))
->
{ name };
me = { inbuf_egg => ix::make_inbuf_egg (socket, []),
outbuf_egg => ox::make_outbuf_egg (socket, []),
xsequencer_egg => xx::make_xsequencer_egg [],
decode_xpackets_egg => dxx::make_decode_xpackets_egg []
};
\\ () = { # PUBLIC. PHASE 2: Start our microthread and return our Exports to caller.
#
(me.inbuf_egg ()) -> (inbuf_exports, inbuf_egg');
(me.outbuf_egg ()) -> (outbuf_exports, outbuf_egg');
(me.xsequencer_egg ()) -> (xsequencer_exports, xsequencer_egg');
(me.decode_xpackets_egg ()) -> (decode_xpackets_exports, decode_xpackets_egg');
xclient_to_sequencer = xsequencer_exports.xclient_to_sequencer;
xerror_well = xsequencer_exports.xerror_well;
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
)
=
{
imports -> { xevent_sink }; # xevent_sink carries xevents from decode_xpackets_ximp to xevent_router_ximp.
inbuf_egg' ( { xpacket_sink => xsequencer_exports.xpacket_sink }, # Imports
run_gun', end_gun'
);
#
outbuf_egg' ( { }, # Imports
run_gun', end_gun'
);
xsequencer_egg' ( { xsequencer_to_outbuf => outbuf_exports.xsequencer_to_outbuf, # Imports
xpacket_sink => decode_xpackets_exports.xpacket_sink
},
run_gun', end_gun'
);
decode_xpackets_egg' ( { xevent_sink }, # Imports
run_gun', end_gun'
);
();
};
({ xclient_to_sequencer, xerror_well }, phase3);
};
};
}; # package xsocket_ximps
end;