Skip to content

Commit

Permalink
Move looping into a service, rather than the kernel.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeickle committed Nov 2, 2013
1 parent 844e795 commit 5cb1253
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
26 changes: 4 additions & 22 deletions src/lib/core/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import inspect

from src.lib.util.registry import RegistryFactory, RegistryDict, RegistryList
from src.lib.core.services.loop import LoopService

# Define a list-like container for storing registered services.
ServiceList = RegistryFactory("ServiceList", RegistryList)
Expand All @@ -15,27 +14,10 @@ class Kernel(object):
responsible for service registration and orchestration.
"""
def __init__(self, **services):
# Populate the service name registry with a loop service.
self.services = ServiceNameRegistry()
self.register_services(loop=LoopService())

"""Execution management methods."""

def loop(self):
"""Run the main application loop."""
# Use the output service as a context manager.
with self.service("output") as display:
# Start the root Component's loop.
root = self.service("root")
while root.alive:
# Allow registered services to react to the loop.
for service in self.service("loop"):
service.loop()

# Continue looping if necessary.
if root.after_loop().get("relaunch"):
# TODO: Reset kernel and services as needed
return True
# Initialize the service registry.
self.services = ServiceRegistry()
# Register the provided services.
self.register_services(**services)

"""Service registration methods."""

Expand Down
19 changes: 18 additions & 1 deletion src/lib/core/services/loop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
"""A service that contacts other services during the event loop."""

from src.lib.core.kernel import Kernel
from src.lib.core.services.service import ServiceMixin
from src.lib.util.registry import RegistryList

class LoopService(RegistryList, ServiceMixin):
pass
@Kernel.helper
def loop(self):
"""Run the main application loop."""
# Use the output service as a context manager.
with self.service("output") as display:
# Start the root Component's loop.
root = self.service("root")
while root.alive:
# Allow registered services to react to the loop.
for service in self.service("loop"):
if hasattr(service, "loop"):
service.loop()

# Continue looping if necessary.
if root.after_loop().get("relaunch"):
# TODO: Reset kernel and services as needed
return True

0 comments on commit 5cb1253

Please # to comment.