def build_keyboard(cls, i, ex, args, meta_args): """Listen for keyboard event""" if meta_args.mode == 'single key': ex.on_event = hive.socket(cls.add_single_listener, identifier="event.add_handler") args.key = hive.parameter("str.keycode", "w") i.key = hive.property(cls, "key", "str.keycode", args.key) i.push_key = hive.push_in(i.key) ex.key = hive.antenna(i.push_key) i.on_key_changed = hive.triggerable(cls.change_listener_keys) hive.trigger(i.push_key, i.on_key_changed) i.on_pressed = hive.triggerfunc() ex.on_pressed = hive.hook(i.on_pressed) i.on_released = hive.triggerfunc() ex.on_released = hive.hook(i.on_released) i.is_pressed = hive.property(cls, "is_pressed", "bool") i.pull_is_pressed = hive.pull_out(i.is_pressed) ex.is_pressed = hive.output(i.pull_is_pressed) else: ex.on_event = hive.socket(cls.add_any_listener, identifier="event.add_handler") i.key_pressed = hive.property(cls, 'key_pressed', data_type='str.keycode') i.pull_key_pressed = hive.push_out(i.key_pressed) ex.key_pressed = hive.output(i.pull_key_pressed) i.key_released = hive.property(cls, 'key_released', data_type='str.keycode') i.pull_key_released = hive.push_out(i.key_released) ex.key_released = hive.output(i.pull_key_released)
def build_instantiator(cls, i, ex, args, meta_args): """Instantiates a Hive class at runtime""" # If this is built now, then it won't perform matchmaking, so use meta hive bind_meta_class = hive.meta_hive("BindEnvironment", build_bind_environment, declare_build_environment, builder_cls=BindEnvironmentClass) #assert bind_meta_class._hive_object_class i.bind_meta_class = hive.property(cls, "bind_meta_class", "class", bind_meta_class) i.trig_instantiate = hive.triggerfunc(cls.instantiate) i.do_instantiate = hive.triggerable(i.trig_instantiate) i.hive_class = hive.property(cls, "hive_class", "class") i.pull_hive_class = hive.pull_in(i.hive_class) ex.hive_class = hive.antenna(i.pull_hive_class) ex.create = hive.entry(i.do_instantiate) hive.trigger(i.trig_instantiate, i.pull_hive_class, pretrigger=True) ex.process_id = hive.property(cls, "last_created_process_id", "int.process_id") i.pull_process_id = hive.pull_out(ex.process_id) ex.last_process_id = hive.output(i.pull_process_id) i.push_stop_process = hive.push_in(cls.stop_hive) ex.stop_process = hive.antenna(i.push_stop_process) # Bind class plugin ex.bind_on_created = hive.socket(cls.add_on_created, identifier="bind.on_created", policy=hive.MultipleOptional) ex.add_get_plugins = hive.socket(cls.add_get_plugins, identifier="bind.get_plugins", policy=hive.MultipleOptional) ex.add_get_config = hive.socket(cls.add_get_config, identifier="bind.get_config", policy=hive.MultipleOptional) # Bind instantiator if meta_args.bind_process == 'child': # Add startup and stop callbacks ex.on_stopped = hive.plugin(cls.stop_all_processes, identifier="on_stopped")
def build_spawn(cls, i, ex, args, meta_args): """Spawn an entity into the scene""" ex.get_spawn_entity = hive.socket(cls.set_spawn_entity, "entity.spawn") # Associate entity with this hive so it is safely destroyed ex.get_register_destructor = hive.socket(cls.set_register_destructor, "entity.register_destructor") ex.on_entity_process_instantiated = hive.plugin( cls.on_entity_process_created, "bind.on_created") i.entity_class_id = hive.property(cls, "entity_class_id", "str.entity_class_id") i.pull_class_id = hive.pull_in(i.entity_class_id) ex.entity_class_id = hive.antenna(i.pull_class_id) i.entity_last_created_id = hive.property(cls, "entity_last_created_id", "int.entity_id") if meta_args.spawn_hive: i.pull_entity_id = hive.pull_out(i.entity_last_created_id) ex.entity_last_created_id = hive.output(i.pull_entity_id) else: i.push_entity_id = hive.push_out(i.entity_last_created_id) ex.created_entity_id = hive.output(i.push_entity_id) i.do_spawn = hive.triggerable(cls.do_spawn_entity) i.trigger = hive.triggerfunc(i.do_spawn) i.on_triggered = hive.triggerable(i.trigger) hive.trigger(i.trigger, i.pull_class_id, pretrigger=True) # Process instantiator if meta_args.spawn_hive: i.instantiator = Instantiator(forward_events='all', bind_process='child') # Pull entity to instantiator hive.connect(i.pull_entity_id, i.instantiator.entity_id) # Get last created ex.hive_class = hive.antenna(i.instantiator.hive_class) ex.last_process_id = hive.output(i.instantiator.last_process_id) ex.stop_process = hive.antenna(i.instantiator.stop_process) ex.pause_events = hive.antenna(i.instantiator.pause_events) ex.resume_events = hive.antenna(i.instantiator.resume_events) # Instantiate hive.trigger(i.trigger, i.instantiator.create) else: # Finally push out entity hive.trigger(i.trigger, i.push_entity_id) ex.spawn = hive.entry(i.on_triggered)
def build_import(cls, i, ex, args): """Interface to python import mechanism, with respect to editor project path""" i.import_path = hive.property(cls, "import_path", 'str') i.pull_import_path = hive.pull_in(i.import_path) ex.import_path = hive.antenna(i.pull_import_path) i.do_import = hive.triggerable(cls.do_import_from_path) i.module = hive.property(cls, "module", "module") i.pull_module = hive.pull_out(i.module) ex.module = hive.output(i.pull_module) hive.trigger(i.pull_module, i.pull_import_path, pretrigger=True) hive.trigger(i.pull_module, i.do_import, pretrigger=True)
def build_move(cls, i, ex, args, meta_args): """Apply a position delta to an entity""" coordinate_system = meta_args.coordinate_system i.displacement = hive.property(cls, "displacement", "vector") i.pull_displacement = hive.pull_in(i.displacement) ex.displacement = hive.antenna(i.pull_displacement) if meta_args.bound: ex.get_bound = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound") i.do_get_entity_id = hive.triggerable(cls.do_get_entity_id) hive.trigger(i.pull_displacement, i.do_get_entity_id) else: i.entity_id = hive.property(cls, "entity_id", "int.entity_id") i.pull_entity_id = hive.pull_in(i.entity_id) ex.entity_id = hive.antenna(i.pull_entity_id) hive.trigger(i.pull_displacement, i.pull_entity_id) if coordinate_system == 'absolute': ex.get_set_position = hive.socket( cls.set_set_position, identifier="entity.position.set.absolute") ex.get_get_position = hive.socket( cls.set_get_position, identifier="entity.position.get.absolute") i.do_set_position = hive.triggerable(cls.do_move_absolute) else: i.other_entity_id = hive.property(cls, "other_entity_id", "int.entity_id") i.pull_other_entity_id = hive.pull_in(i.other_entity_id) ex.other_entity_id = hive.antenna(i.pull_other_entity_id) hive.trigger(i.pull_displacement, i.pull_other_entity_id) ex.get_set_position = hive.socket( cls.set_set_position, identifier="entity.position.set.relative") ex.get_get_position = hive.socket( cls.set_get_position, identifier="entity.position.get.relative") i.do_set_position = hive.triggerable(cls.do_move_relative) hive.trigger(i.pull_displacement, i.do_set_position) ex.trig = hive.entry(i.pull_displacement)
def build_input_handler(cls, i, ex, args): i.update = hive.triggerable(cls.update) ex.update = hive.entry(i.update) i.event = hive.property(cls, "event", "tuple") i.push_event = hive.push_out(i.event) ex.event = hive.output(i.push_event)
def build_bind(cls, i, ex, args, meta_args): bind_mode = meta_args.bind_entity if bind_mode == 'bound': i.entity_id = hive.property(cls, "entity_id", "int.entity_id") i.pull_entity_id = hive.pull_in(i.entity_id) ex.entity_id = hive.antenna(i.pull_entity_id)
def build_watch(cls, i, ex, args, meta_args): """Watch value and indicate when it is changed. Uses a tick callback. """ args.start_value = hive.parameter(meta_args.data_type, None) i.value = hive.property(cls, "current_value", meta_args.data_type, args.start_value) if meta_args.mode == 'pull': i.value_in = hive.pull_in(i.value) else: i.value_in = hive.push_in(i.value) ex.value = hive.antenna(i.value_in) i.on_changed = hive.triggerfunc() ex.on_changed = hive.hook(i.on_changed) if meta_args.mode == 'pull': ex.get_add_handler = hive.socket(cls.set_add_handler, identifier="event.add_handler") else: i.compare_values = hive.triggerable(cls.compare_values) hive.trigger(i.value_in, i.compare_values)
def build_scene(cls, i, ex, args): i.bge_scene = hive.property(cls, "scene") ex.get_entity_id = hive.plugin(cls.get_entity_id, identifier="entity.get") ex.get_position_absolute = hive.plugin( cls.get_position_absolute, identifier="entity.position.absolute.get") ex.get_position_relative = hive.plugin( cls.get_position_relative, identifier="entity.position.relative.get") ex.get_orientation_absolute = hive.plugin( cls.get_orientation_absolute, identifier="entity.orientation.absolute.get") ex.get_orientation_relative = hive.plugin( cls.get_orientation_relative, identifier="entity.orientation.relative.get") ex.spawn_entity = hive.plugin(cls.spawn_entity, identifier="entity.spawn") ex.get_scene = hive.plugin(cls.get_scene, identifier="entity.get_current") import dragonfly ex.on_tick = dragonfly.event.Tick() def f(self): print("I") if not hasattr(self, 'a'): self.a = 1 self.spawn_entity.plugin()("Cube", "c1") i.mod_tick = hive.modifier(f) hive.trigger(ex.on_tick, i.mod_tick)
def build_dog(cls, i, ex, args): i.call = h.triggerfunc(cls.call) i.woof = h.triggerable(cls.woof) #h.trigger(i.call, i.woof) h.connect(i.call, i.woof) i.woof2 = h.modifier(woof2) i.bark = h.triggerfunc() h.trigger(i.bark, i.woof) i.woofed = h.triggerfunc() ex.woofs = h.property(cls, "woofs") ex.name = h.property(cls, "name") ex.woofs2 = h.variable(data_type="int", start_value=0) ex.woof = h.entry(i.woof) ex.woofed = h.hook(i.woofed) ex.bark = h.hook(i.bark) ex.call = h.hook(i.call)
def build_random(cls, i, ex, args): """HIVE interface to Python random module""" i.push_seed = hive.push_in(cls.set_seed) ex.seed = hive.antenna(i.push_seed) i.pull_random = hive.pull_out(cls.get_rand) ex.random = hive.output(i.pull_random) i.pull_bool = hive.pull_out(cls.get_bool) ex.bool = hive.output(i.pull_bool) # Randint i.randint_min = hive.property(cls, "randint_min", "int") i.randint_max = hive.property(cls, "randint_max", "int") i.randint_step = hive.property(cls, "randint_step", "int") i.pull_randint_min = hive.pull_in(i.randint_min) i.pull_randint_max = hive.pull_in(i.randint_max) i.pull_randint_step = hive.pull_in(i.randint_step) ex.int_min = hive.antenna(i.pull_randint_min) ex.int_max = hive.antenna(i.pull_randint_max) ex.int_step = hive.antenna(i.pull_randint_step) i.pull_int = hive.pull_out(cls.get_randrange) ex.int = hive.output(i.pull_int) hive.trigger(i.pull_int, i.pull_randint_max, pretrigger=True) hive.trigger(i.pull_int, i.pull_randint_min, pretrigger=True) hive.trigger(i.pull_int, i.pull_randint_step, pretrigger=True) # Randrange i.uniform_min = hive.property(cls, "uniform_min", "float") i.uniform_max = hive.property(cls, "uniform_max", "float") i.uniform_min_in = hive.pull_in(i.uniform_min) i.uniform_max_in = hive.pull_in(i.uniform_max) ex.uniform_min = hive.antenna(i.uniform_min_in) ex.uniform_max = hive.antenna(i.uniform_max_in) i.pull_uniform = hive.pull_out(cls.get_uniform) ex.uniform = hive.output(i.pull_uniform) hive.trigger(i.pull_uniform, i.uniform_max_in, pretrigger=True) hive.trigger(i.pull_uniform, i.uniform_min_in, pretrigger=True)
def build_dispatch(cls, i, ex, args): i.event = hive.property(cls, "event", "tuple.event") i.pull_event = hive.pull_in(i.event) ex.event = hive.antenna(i.pull_event) ex.get_read_event = hive.socket(cls.set_read_event, identifier="event.process") i.dispatch = hive.triggerable(cls.dispatch) ex.trig = hive.entry(i.dispatch)
def build_this(cls, i, ex, args): """Access to current bound entity""" ex.get_bound_entity = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound") i.entity_id = hive.property(cls, "entity_id", "int.entity_id") i.pull_entity_id = hive.pull_out(i.entity_id) ex.entity_id = hive.output(i.pull_entity_id) i.do_get_entity_id = hive.triggerable(cls.get_entity_id) hive.trigger(i.pull_entity_id, i.do_get_entity_id, pretrigger=True)
def build_animation(cls, i, ex, args, meta_args): """Play animation for actor""" i.do_start = hive.triggerable(cls.start) i.do_stop = hive.triggerable(cls.stop) ex.start = hive.entry(i.do_start) ex.stop = hive.entry(i.do_stop) i.current_frame = hive.property(cls, "current_frame", "int") i.end_frame = hive.property(cls, "end_frame", "int") i.start_frame = hive.property(cls, "start_frame", "int") i.pull_current_frame = hive.pull_out(i.current_frame) i.pull_end_frame = hive.pull_in(i.end_frame) i.pull_start_frame = hive.pull_in(i.start_frame) ex.current_frame = hive.output(i.pull_current_frame) ex.start_frame = hive.antenna(i.pull_start_frame) ex.end_frame = hive.antenna(i.pull_end_frame)
def build_dog(cls, i, ex, args, meta_args): print(meta_args) print("Invoked Builder") args.name = hive.parameter("str") ex.name = hive.property(cls, "name", "str", args.name) for ix in range(meta_args.puppies): mod = hive.modifier(lambda h: print("Puppy {} barked".format(h.name))) setattr(i, "mod_{}".format(ix), mod) setattr(ex, "bark_{}".format(ix), hive.entry(mod))
def build_listener(cls, i, ex, args, meta_args): """Tick event sensor, trigger on_tick every tick""" i.on_event = hive.triggerfunc() ex.on_event = hive.hook(i.on_event) ex.get_add_handler = hive.socket(cls.set_add_handler, "event.add_handler") if meta_args.mode == 'leader': i.after_leader = hive.property(cls, 'after_leader', 'tuple') i.pull_after_leader = hive.pull_out(i.after_leader) ex.after_leader = hive.output(i.pull_after_leader)
def build_tag(cls, i, ex, args, meta_args): """Access to entity tag API""" if meta_args.bound: ex.get_bound = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound") i.do_get_bound_entity_id = hive.triggerable(cls.get_entity_id) else: i.entity_id = hive.property(cls, "entity_id", "int.entity_id") i.pull_entity_id = hive.pull_in(i.entity_id) ex.entity_id = hive.antenna(i.pull_entity_id) i.do_get_bound_entity_id = hive.triggerable(i.pull_entity_id) i.tag_name = hive.property(cls, "tag_name", "str") i.tag_value = hive.property(cls, "tag_value", meta_args.data_type) i.pull_tag_name = hive.pull_in(i.tag_name) ex.name = hive.antenna(i.pull_tag_name) if meta_args.mode == 'get': ex.get_get_tag = hive.socket(cls.set_get_tag, identifier="entity.tag.get") i.pull_tag_value = hive.pull_out(i.tag_value) ex.value = hive.output(i.pull_tag_value) i.do_get_tag = hive.triggerable(cls.get_tag) hive.trigger(i.pull_tag_value, i.do_get_bound_entity_id) hive.trigger(i.pull_tag_value, i.pull_tag_name) hive.trigger(i.pull_tag_value, i.do_get_tag) else: ex.get_set_tag = hive.socket(cls.set_set_tag, identifier="entity.tag.set") i.push_tag_value = hive.push_in(i.tag_value) ex.value = hive.antenna(i.push_tag_value) i.do_get_tag = hive.triggerable(cls.get_tag) hive.trigger(i.push_tag_value, i.do_get_bound_entity_id) hive.trigger(i.push_tag_value, i.pull_tag_name) hive.trigger(i.push_tag_value, i.do_get_tag)
def build_myhive(cls, i, ex, args): ex.a_ = hive.property(cls, "a", "int") ex.b_ = hive.property(cls, "b", "int") i.a_in = hive.push_in(ex.a_) i.b_in = hive.push_in(ex.b_) ex.a = hive.antenna(i.a_in) ex.b = hive.antenna(i.b_in) ex.c_ = hive.attribute() i.c_out = hive.push_out(ex.c_) ex.c = hive.output(i.c_out) # On triggered def on_triggered(this): this.c_ = this.a_ + this.b_ this.c.push() i.on_triggered = hive.modifier(lambda this: setattr(this, 'c_', (this.a_ + this.b_))) ex.trigger = hive.entry(i.on_triggered)
def time_builder(cls, i, ex, args): """Access to Python time module""" i.elapsed = hive.property(cls, 'elapsed', 'float') i.elapsed_out = hive.pull_out(i.elapsed) ex.elapsed_out = hive.output(i.elapsed_out) ex.get_add_handler = hive.socket(cls.set_add_handler, "event.add_handler") ex.on_started = hive.plugin(cls.on_started, "on_started", policy=hive.SingleRequired) ex.get_get_tick_rate = hive.socket(cls.set_get_tick_rate, "app.get_tick_rate")
def build_chessboard(cls, i, ex, args): prop_move = h.property(cls, "prop_move", "str") # TODO: make buffer i.make_move = h.push_in(prop_move) i.trig_make_move = h.triggerable(cls.trig_make_move) # TODO: make modifier h.trigger(i.make_move, i.trig_make_move) ex.make_move = h.antenna(i.make_move) ex.do_make_move = cls.make_move ex.p_make_move = h.plugin(cls.make_move) ex.prop_move = prop_move ex.set_turn = h.socket(cls.set_turn) ex.add_moveprocessor = h.socket(cls.add_moveprocessor)
def build_server(cls, i, ex, args): i.local_address = hive.property(cls, "local_address", "tuple") i.push_bind_address = hive.push_in(i.local_address) ex.bind_to = hive.antenna(i.push_bind_address) i.do_bind = hive.triggerable(cls.do_bind) hive.trigger(i.push_bind_address, i.do_bind) # Receiving connection i.connected_address = hive.property(cls, "connected_address", "tuple") i.push_connected_address = hive.push_out(i.connected_address) ex.on_client_connected = hive.output(i.push_connected_address) # Receiving connection i.disconnected_address = hive.property(cls, "disconnected_address", "tuple") i.push_disconnected_address = hive.push_out(i.disconnected_address) ex.on_client_disconnected = hive.output(i.push_disconnected_address) # Receiving i.from_address = hive.property(cls, "from_address", "tuple") i.pull_from_address = hive.pull_out(i.from_address) ex.from_address = hive.output(i.pull_from_address) i.received_data = hive.property(cls, "received_data", "bytes") i.push_received = hive.push_out(i.received_data) ex.on_received = hive.output(i.push_received) # Hive callbacks i.on_disconnected = hive.triggerfunc() i.on_connected = hive.triggerfunc() i.on_received = hive.triggerfunc() hive.trigger(i.on_received, i.push_received) hive.trigger(i.on_connected, i.push_connected_address) hive.trigger(i.on_disconnected, i.push_disconnected_address) # Sending i.to_address = hive.property(cls, "to_address", "tuple") i.pull_to_address = hive.pull_in(i.to_address) ex.to_address = hive.antenna(i.pull_to_address) i.outgoing_data = hive.property(cls, "outgoing_data", "bytes") i.push_outgoing_data = hive.push_in(i.outgoing_data) ex.send = hive.antenna(i.push_outgoing_data) i.do_send_data = hive.triggerable(cls.do_send) hive.trigger(i.push_outgoing_data, i.pull_to_address, pretrigger=True) hive.trigger(i.push_outgoing_data, i.do_send_data) i.synchronise_data = hive.triggerable(cls.synchronise) i.on_tick = OnTick() hive.connect(i.on_tick.on_tick, i.synchronise_data)
def build_commandline(cls, i, ex, args): i.start = h.triggerable(cls.start) i.stop = h.triggerable(cls.stop) i.flush = h.triggerable(cls.flush) prop_command = h.property(cls, "command", "str") i.push_command = h.push_out(prop_command) ex.prop_command = prop_command ex.command = h.output(i.push_command) ex.send_command = cls.send_command ex.start = h.entry(i.start) ex.flush = h.entry(i.flush) ex.stop = h.entry(i.stop) ex.listen = h.socket(cls.add_listener)
def build_collision(cls, i, ex, args): """Interface to collision events for bound hive""" i.hit_entity = hive.property(cls, "hit_entity_id", "int.entity_id") i.hit_position = hive.property(cls, "hit_position", "vector") i.hit_normal = hive.property(cls, "hit_normal", "vector") i.hit_impulse = hive.property(cls, "hit_impulse", "vector") i.pull_hit_entity = hive.pull_out(i.hit_entity) i.pull_hit_position = hive.pull_out(i.hit_position) i.pull_hit_normal = hive.pull_out(i.hit_normal) i.pull_hit_impulse = hive.pull_out(i.hit_impulse) ex.hit_entity = hive.output(i.pull_hit_entity) ex.hit_position = hive.output(i.pull_hit_position) ex.hit_normal = hive.output(i.pull_hit_normal) ex.hit_impulse = hive.output(i.pull_hit_impulse) i.on_collided = hive.triggerfunc() ex.on_collided = hive.hook(i.on_collided) ex.get_get_entity_id = hive.socket(cls.set_get_entity_id, "entity.get_bound") ex.get_add_handler = hive.socket(cls.set_add_handler, "event.add_handler")
def build_keyboard(cls, i, ex, args): ex.on_event = hive.socket(cls.add_single_listener, identifier="event.add_handler") i.on_tick = hive.triggerfunc() ex.name = hive.variable(("str", ), "<Sensor>") ex.key = hive.property(cls, "key", "str") ex.is_positive = hive.variable(("bool", ), False) i.positive = hive.pull_out(ex.is_positive) ex.positive = hive.output(i.positive) i.trig_out = hive.triggerfunc() ex.trig_out = hive.hook(i.trig_out)
def build_parent(cls, i, ex, args, meta_args): """Set/Get entity parent""" ex.get_get_parent = hive.socket(cls.set_get_parent, identifier="entity.parent.get") ex.get_set_parent = hive.socket(cls.set_set_parent, identifier="entity.parent.set") i.parent_id = hive.property(cls, "parent_id", "int.entity_id") if meta_args.bound: ex.get_bound = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound") i.do_get_bound_entity_id = hive.triggerable(cls.get_entity_id) else: i.entity_id = hive.property(cls, "entity_id", "int.entity_id") i.pull_entity_id = hive.pull_in(i.entity_id) ex.entity_id = hive.antenna(i.pull_entity_id) i.do_get_bound_entity_id = hive.triggerable(i.pull_entity_id) if meta_args.mode == "get": i.pull_parent_id = hive.pull_out(i.parent_id) ex.parent_id = hive.output(i.pull_parent_id) i.get_parent_id = hive.triggerable(cls.get_parent_id) hive.trigger(i.pull_parent_id, i.do_get_bound_entity_id, pretrigger=True) hive.trigger(i.pull_parent_id, i.get_parent_id, pretrigger=True) else: i.push_parent_id = hive.push_in(i.parent_id_id) ex.parent_id = hive.antenna(i.push_parent_id) i.set_parent = hive.triggerable(cls.set_parent) hive.trigger(i.push_parent_id, i.do_get_bound_entity_id) hive.trigger(i.push_parent_id, i.set_parent)
def build_server(cls, i, ex, args): i.connect_address = hive.property(cls, "server_address", "tuple") i.push_connect = hive.push_in(i.connect_address) ex.connect_to = hive.antenna(i.push_connect) i.do_connect = hive.triggerable(cls.do_connect) hive.trigger(i.push_connect, i.do_connect) # Hive callbacks i.on_disconnected = hive.triggerfunc() i.on_connected = hive.triggerfunc() i.on_received = hive.triggerfunc() # Receiving connection ex.on_connected = hive.hook(i.on_connected) # Lost connection ex.on_disconnected = hive.hook(i.on_disconnected) # Receiving i.received_data = hive.property(cls, "received_data", "bytes") i.push_received = hive.push_out(i.received_data) ex.on_received = hive.output(i.push_received) hive.trigger(i.on_received, i.push_received) # Sending i.outgoing_data = hive.property(cls, "outgoing_data", "bytes") i.push_outgoing_data = hive.push_in(i.outgoing_data) ex.send = hive.antenna(i.push_outgoing_data) i.do_send_data = hive.triggerable(cls.do_send) hive.trigger(i.push_outgoing_data, i.do_send_data) i.synchronise_data = hive.triggerable(cls.synchronise) i.on_tick = OnTick() hive.connect(i.on_tick.on_tick, i.synchronise_data)
def build_dictionary(cls, i, ex, args, meta_args): """Interface to dictionary object""" ex.dict = hive.property(cls, "dict", "dict") i.dict_in = hive.push_in(ex.dict) ex.dict_ = hive.antenna(i.dict_in) i.dict_out = hive.pull_out(ex.dict) ex.dict_out = hive.output(i.dict_out) i.key = hive.property(cls, "key", meta_args.key_data_type) i.value = hive.property(cls, "value", meta_args.data_type) # Setitem i.set_key_in = hive.pull_in(i.key) ex.set_key = hive.antenna(i.set_key_in) i.in_value = hive.push_in(i.value) ex.in_value = hive.antenna(i.in_value) i.set_value = hive.triggerable(cls.set_value) hive.trigger(i.in_value, i.set_key_in) hive.trigger(i.set_key_in, i.set_value) i.get_key_in = hive.pull_in(i.key) ex.get_key = hive.antenna(i.get_key_in) i.out_value = hive.pull_out(i.value) ex.out_value = hive.output(i.out_value) i.get_value = hive.triggerable(cls.get_value) # Before outputting, update key hive.trigger(i.out_value, i.get_key_in, pretrigger=True) hive.trigger(i.get_key_in, i.get_value)
def build_bind(cls, i, ex, args, meta_args): if meta_args.forward_events == "none": return if meta_args.forward_events == "by_leader": i.event_leader = hive.property(cls, "leader", "tuple") i.pull_event_leader = hive.pull_in(i.event_leader) ex.event_leader = hive.antenna(i.pull_event_leader) i.push_pause_in = hive.push_in(cls.pause) ex.pause_events = hive.antenna(i.push_pause_in) i.push_resume_in = hive.push_in(cls.resume) ex.resume_events = hive.antenna(i.push_resume_in) ex.on_created = hive.plugin(cls.on_created, "bind.on_created")
def build_bind_environment(cls, i, ex, args, meta_args): """Provides plugins to new embedded hive instance""" ex.hive = meta_args.hive_class() # Startup / End callback ex.get_on_started = hive.socket(cls.add_on_started, identifier="on_started", policy=hive.MultipleOptional) ex.get_on_stopped = hive.socket(cls.add_on_stopped, identifier="on_stopped", policy=hive.MultipleOptional) i.on_started = hive.triggerable(cls.start) i.on_stopped = hive.triggerable(cls.stop) ex.on_started = hive.entry(i.on_started) ex.on_stopped = hive.entry(i.on_stopped) i.state = hive.property(cls, 'state', 'str') i.pull_state = hive.pull_out(i.state) ex.state = hive.output(i.pull_state)
def build_dog(cls, i, ex, args): i.call = hive.triggerfunc(cls.call) i.woof = hive.triggerable(cls.woof) hive.trigger(i.call, i.woof) i.bark = hive.triggerfunc() hive.trigger(i.bark, i.woof) i.woof_only = hive.triggerable(cls.woof) i.woofed = hive.triggerfunc() ex.woofs = hive.property(cls, "woofs") ex.woof = hive.entry(i.woof) ex.woof_only = hive.entry(i.woof_only) ex.woofed = hive.hook(i.woofed) ex.bark = hive.hook(i.bark) ex.call = hive.hook(i.call)