#!/usr/bin/python
#
# jm_server.py
#
# Author: Zex <top_zlynch@yahoo.com>
#

import dbus 
import dbus.service
import dbus.mainloop.glib
import gobject
from basic import * 

class JuiceMachine(dbus.service.FallbackObject):
    """
    JuiceMachine server
    """
    def __init__(self):

        connection = dbus.SessionBus()
        connection_name = dbus.service.BusName(
            JM_SERVICE_NAME, bus = connection)

        dbus.service.Object.__init__(self, connection_name,
            JM_CONFIG_PATH)

    @dbus.service.method(JM_CONFIG_IFACE,
            in_signature = '', out_signature = 's',
            path_keyword = 'path')
    def list(self, path = JM_CONFIG_PATH):
        """
        TODO: Return goods list
        """
        buf = ""
        try:
            with open(NVRAM_DEV, 'rw') as fd:
                buf = fd.read()
        except Exception as e:
            buf = str(e)

        return buf


def start_server():
    """
    Stadrt juicemachine server
    """
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    global loop

    obj = JuiceMachine()
    loop = gobject.MainLoop()
    connection = dbus.StarterBus()

    loop.run()


start_server()

@@ -143,16 +143,29 @@
  gobject
+%0A%0Aimport json
 %0Afrom ba
@@ -545,22 +545,19 @@
 thod(JM_
-CONFIG
+DEV
 _IFACE,%0A
@@ -772,16 +772,16 @@
    try:%0A
-
         
@@ -927,16 +927,427 @@
 rn buf%0A%0A
+    @dbus.service.method(JM_JSON_IFACE,%0A            in_signature = '', out_signature = 's',%0A            path_keyword = 'path')%0A    def list(self, path = JM_CONFIG_PATH):%0A        %22%22%22%0A        TODO: Return goods list%0A        %22%22%22%0A        buf = %22%22%0A        try:%0A            with open(JSON_PATH, 'rw') as fd:%0A                buf = fd.read()%0A        except Exception as e:%0A            buf = str(e)%0A%0A        return buf%0A%0A
 %0Adef sta

add json access iface