add json-rpc method in an addon ?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
flagadajones Offline
Junior Member
Posts: 3
Joined: Jun 2012
Reputation: 0
Post: #1
Hi,

I'll start an addon development and i search if it's possible in addon to develop a json-rpc method ? If the answer is Yes, is it possible to add the method in the answer of the JSONRPC.introspect method ?


thanks
find quote
garbear Offline
Team-XBMC Developer
Posts: 426
Joined: Dec 2010
Reputation: 16
Location: gangsta's paradise
Post: #2
Not currently possible. What kind of idea did you have in mind?

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first
find quote
flagadajones Offline
Junior Member
Posts: 3
Joined: Jun 2012
Reputation: 0
Post: #3
I want to create an addon which communicate with an hardware module (like arduino) and use XBMC as IR relay between an android phone (in wifi mode ) and my Audio/Video amplificator.

android --- send remote command via JSON-RPC --> xbmc ---- send IR command via Arduino ---> audio/video ampli
find quote
garbear Offline
Team-XBMC Developer
Posts: 426
Joined: Dec 2010
Reputation: 16
Location: gangsta's paradise
Post: #4
My best guess effort would be:

Code:
# defined in Key.h
ACTION_VOLUME_UP = 88
ACTION_VOLUME_DOWN = 89

class VolumeMonitorDialog(xbmcgui.WindowXMLDialog):
    def onAction(self, action):
        actionID = action.getId()
        if actionID == ACTION_VOLUME_UP:
            # Volume up
        if actionID == ACTION_VOLUME_DOWN:
            # Volume down

When you call the dialog's doModal() it will start receiving actions. Caveat: Only as long as the dialog is open.

The best way to intercept these events in the background would be a service addon that extends xbmc.Monitor (see PR#856). You would then need to use C++ to code an onAction() method for xbmc.Monitor.

If you talk with Montellese and Amet, they might suggest a better way than enhancing xbmc.Monitor, and they'd most likely have some insight as to why this currently isn't possible.

Regards,
Garrett

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first
find quote
garbear Offline
Team-XBMC Developer
Posts: 426
Joined: Dec 2010
Reputation: 16
Location: gangsta's paradise
Post: #5
My best guess effort above was a pretty crappy solution Smile Here's two much better options:

1. The resource-hog, delay volume change method: notice the sad face Sad
Basically, change a property (like volume) with your remote and poll that value with a service addon
Code:
class ExitMonitor(xbmc.Monitor):
    def onAbortRequested(self):
        sys.exit()

def getVolume():
    query = '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": "volume", "id": 1}' # Probably wrong
    result = xbmc.executeJSONRPC(query)
    # etc

monitor = ExitMonitor()
volume = getVolume()

while (True):
    newVolume = getVolume()
    if volume != newVolume:
        # like a g6
    volume = newVolume
    xbmc.sleep(X) # lag vs system load



2. The "hardcore" option. plain and simple, chicks dig guys who compile their own XBMC
Apply a patch: github.com/garbear/xbmc/commit/dffd96e
Compile XBMC
Code:
class VolumeMonitor(xbmc.Monitor):
    def onVolumeChanged(self, volume):
        volume = int(volume) # Too lazy to convert in C++
        # get high like planes
    
    def onAbortRequested(self):
        sys.exit()

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first
(This post was last modified: 2012-07-11 07:24 by garbear.)
find quote