def main(): with autobus2.Bus() as bus: sleep(1) with bus.connect_to({"autobus.example": "testobjectserver1"}) as connection: connection.wait_for_connect() connection.watch_object("test", changed) autobus2.wait_for_interrupt()
def main(): global state_object with Bus() as bus: service = bus.create_service({"type": "flipflop"}, active=False, use_py_object=Service()) state_object = service.create_object("state", 1, "The current state.") service.activate() wait_for_interrupt()
def main(): with Bus() as bus: server = atomically(Server) ConsoleSink(server).start() autobus_service = SixjetService() atomically(lambda: server.provider_list.append(autobus_service)) bus.create_service({"type": "sixjet"}, autobus_service) wait_for_interrupt() @atomically def _(): server.running = False
def main(): global pp print "Welcome to Sixjet Server." print "http://hg.opengroove.org/sixjet" print print "Connecting to the parallel port..." pp = Parallel() print "Resetting jets..." write_jets() print "Starting the sixjet autobus 2 service..." with Bus() as bus: bus.create_service({"type": "sixjet"}, from_py_object=Service()) print "Sixjet has started up. Use ^C to stop it." wait_for_interrupt() print "Shutting down the sixjet autobus 2 service..." print "Sixjet Server has shut down."
def run(bus_to_use): global bus global speak global rpc global timer_object global startup_object global timer_beeping_event global state_change_event global manual_state_change_event bus = bus_to_use speak = bus.get_service_proxy({"type": "speak"}, multiple=True) rpc = RPC() service = bus.create_service({"type": "timer"}, from_py_object=rpc, active=False) timer_object = service.create_object("timers", {}, "This object is a map of " "maps. The outer map maps timer numbers to maps representing " "those timers. Each timer's map contains a number of keys which " "will be described at some point (Alex: TODO: write this), which " "contain the timer's info.") startup_object = service.create_object("startup", 0, "The number of seconds since " "timerd started up.") # timer_beeping_event = bus.add_event("timer", "beeping", "This event is " # "fired whenever a timer that is counting down reaches zero and " # "has its state reset to stopped. It is passed one parameter, " # "the number of the timer that just went off. The event is fired " # "before the timer object is updated to reflect that the timer is " # "now stopped.") # state_change_event = bus.add_event("timer", "state_change", "This event " # "is fired whenever a timer changes state, both when a user " # "manually changes the timer's state and when the state changes " # "due to the timer reaching zero. This event is passed two " # "parameters: the number of the timer whose state changed and the " # "new state of the timer.") # manual_state_change_event = bus.add_event("timer", "manual_state_change", # "This event is fired whenever a timer's state is changed " # "manually by a call to either the set or set_attribute functions. " # "This event is passed the same set of parameters that " # "state_change is passed.") service.activate() IntervalThread().start() wait_for_interrupt()
def main(): with Bus() as bus: with bus.get_service_proxy({"autobus.example": "testobjectserver2"}, multiple=True) as proxy: proxy.watch_object("test", changed) wait_for_interrupt()
def main(): with Bus() as bus: bus.create_service({"type": "examples.hello"}, HelloService()) wait_for_interrupt()
@publish @eventloop.on("loop") def update_flash_time(self, delta): """ Adds the specified number of seconds to the current flash time. This can be negative to subtract from the current flash time. """ self.flash_time += delta if __name__ == "__main__": sys.argv with Bus() as bus: server = SixjetServer(ParallelBackend(Parallel().setData), bus) server.start() wait_for_interrupt() print "Shutting down server..." server.stop() server.join() print "Shutting down bus..." print "Server has shut down."
def main(): args = parser.parse_args() if args.mode is None and args.type is None: print "Use autosend2 --help for more information." return if args.mode == "help": print parser.format_help().replace("!!!INFO!!!", description.strip()) return mode = args.mode if mode is None: # Type, at least, will be present, since the "Use autosend2 --help ..." # message will have stopped us if it wasn't. So basically we need to # check to see if name is present, and if it is, then we call the # specified function, and if it isn't, then we search for the # introspection service and print a list of all supported functions. if args.name is not None: mode = "call" else: mode = "list" # Parse out the info filer from the arguments info_filter = parse_info_filter(args) # Now create a bus. with Bus() as bus: if mode == "discovery": # Print the discovery table header print discovery_mode_header # Add a listener listening for services that will print out # information to stdout bus.add_service_listener(partial(discovery_mode_listener, args), info_filter=info_filter, initial=True) # Wait until we're interrupted wait_for_interrupt() # This empty print is to add a new line after the one with ^C on it # so that things look a bit prettier when all of the REMOVED # messages are printed. print return if mode == "call": if not args.name: print "You need to specify the name of the function to call." return if args.multiple: # Open a multiple-service proxy, with a # bind_function that will call the requested function whenever # it binds to a service. The advantage of doing this instead of # creating the service proxy, waiting a few seconds, then # calling the function on it is that the function is called # nearly immediately instead of after a delay. with bus.get_service_proxy( info_filter, bind_function=partial(call_mode_onbind, args), multiple=True ) as proxy: # Wait a few seconds before stopping the service proxy time.sleep(args.time) else: # Open a single-service proxy, wait for it to bind to # something, then call the function and pass the result to # call_mode_print_result, which prints it out. with bus.get_service_proxy(info_filter) as proxy: proxy.wait_for_bind(timeout=args.time) try: call_mode_print_result(proxy[args.name](*parse_value_list(args.values))) except Exception as e: call_mode_print_result(e) return if mode == "list": # Open a service proxy on the available introspection services. # Note that we use a multiple service proxy here regardless of # what the user requested as we've no guarantee that the first # introspection service discovered will provide a service matching # the requested criteria. TODO: Perhaps consider watching the proxy # in the future if a single-service lookup has been requested to # immediately return once a suitable service is found. with bus.get_service_proxy({"type": "autobus.details"}, multiple=True) as proxy: # Wait a few seconds for the proxy to bind time.sleep(args.time) # Call the introspection function to get information about the # services int_results = proxy["get_details"]() # int_results will be a dict whose keys are the service ids of # the introspection services and whose values are dicts whose # keys are the actual service ids. We need to translate this # into results, which is simply a dict whose keys are service # ids and whose values are services. We also need to strip out # entries whose info objects don't match what we're looking for. results = {} # Iterate over the introspection services for _, services_dict in int_results.items(): # Iterate over the services this introspector knows about for service_id, service in services_dict.items(): # See if the service matches our filter, and see if # we've either specified --all or this service isn't # an introspection service if filter_matches(service["info"], info_filter) and ( args.all or not service["info"].get("type", "").startswith("autobus.") ): # It matches, so add it to the results results[service_id] = service # We've got the actual results. Now print a message if there # weren't any. if len(results) == 0: print "No matching services available." # If there were results, print them. for i, (service_id, service) in enumerate(results.items()): if i > 0: print "#" * 70 print "Service %s on %s (%s) -- %r:" % ( service["info"].get("type", "<unknown>"), service["info"].get("hostname", "<unknown>"), service_id, service["info"], ) if service.get("doc", None): print "\n" + service["doc"] print "=" * 70 functions = filter_hidden(args, service["functions"]) if len(functions) == 0: print "No functions available on this service." for j, (name, function) in enumerate(functions.items()): if j > 0: print "-" * 70 print "Function " + name + ":" if function.get("doc", None): print "\n" + function["doc"] print "=" * 70 events = filter_hidden(args, service["events"]) if len(events) == 0: print "No events available on this service." for j, (name, event) in enumerate(events.items()): if j > 0: print "-" * 70 print "Event " + name + ":" if event.get("doc"): print "\n" + event["doc"] print "=" * 70 objects = filter_hidden(args, service["objects"]) if len(objects) == 0: print "No objects available on this service." for j, (name, object) in enumerate(objects.items()): if j > 0: print "-" * 70 print "Object " + name + ":" if object.get("doc"): print "\n" + object["doc"] return print "Unsupported mode used: " + str(mode)
def main(self): with Bus() as bus: proxy = bus.get_service_proxy({"sixjet.provides": "states"}, multiple=True) proxy.watch_object("sixjet_states", self.receive_change) wait_for_interrupt()