Sign up here and you can log into the forum!

Info: WDTVExt Live addons (WDLXTV 0.4.2.1+ ONLY!!)

This is the place to inquire about general WDTVExt plugin development, tips, and how-to's.

Info: WDTVExt Live addons (WDLXTV 0.4.2.1+ ONLY!!)   

Postby recliq » Fri Jun 25, 2010 4:48 am

I start this thread to keep you informed of the additional functions we added to WDTVExt Live in /wdtvext/js/extra.js.
Functions in extra.js are functions which are often used in plugin development and hence it makes no sense to rewrite them over and over again.
I hope these will be helpfull and save some time here and there.

I want to strongly encourage all wdtvext developers to use these functions!
Reasons:
1) They are used by all internal plugins and have been proven quite stable/error resistant
2) Keep your code as simple as possible
3) Why reinvent the wheel again?


There are at least two functions which i would like to make mandatory:
addExtraContent() and addExtraContentFile()
Not using these will lead to display problems as soon as two or more plugins try to add extra content to the same page!


Changed behaviour/parameters in WDLXTV >= 0.4.2.6
Blue text indicates that this feature was added/changed in later releases (>=0.4.2.6). They can NOT be used with older WDLXTV versions!


New functions in WDLXTV >= 0.4.7.0
Blue text indicates that this feature was added/changed in later releases (>=0.4.7.0). They can NOT be used with older WDLXTV versions!


Debug()
Log debug output to /tmp/dmaosd.log using different log levels
usage:
1) create a new Debug object inside your plugin base method:
Code: Select all
this.debug = new Debug()

2) set debug options
Code: Select all
this.debug.Enable = true              // (default: false)
this.debug.Level = 5                  // (default: 0)
this.debug.Prefix = "DebugLog:"       // (default: DEBUG:)

3) log some output at loglevel 2 (will show if this.debug.Level >= 2)
Code: Select all
this.debug.Log("some log output", 2)

will show:
Code: Select all
DebugLog: some log output

UPDATE: In WDLXTV >v0.4.2.2 all the following functions accept another parameter for the debug level.
Debug level can be
0 (default - no output) to
4 (very verbose)
If second parameter is omitted, debug is 0.


getConfigSetting(setting [, debug])
Obtain value from /conf/config:setting !! NOTE: always returns lowercase result !!
usage:
Code: Select all
var value = getConfigSetting("NTP")

returns the config values for 'NTP' from /conf/config

addExtraContent(page, extraContent [, debug]) and addExtraContentFile(page, file [, debug])
Add extra content to page.extraContent in a 'multi-plugin-compatible' way, either direct or from file
usage:
add your content like this from now on:
Code: Select all
var extraContent = <wrapper>....</wrapper>;
addExtraContent(page, extraContent)

or add your content from file:
Code: Select all
addExtraContentFile(page, this.rootPath + "mycontent.xml")


executeCmd(command [, debug])
Let's you execute shell commands and retrieve the output as array
usage:
1) define your shell command (you can ommit this and give the command as argument to the function)
Code: Select all
var cmd = "echo 'Hello world!'"

2) execute the function and load the result into another variable
Code: Select all
var result = executeCmd(cmd)

3) parse the output, eg print first line of result to log
Code: Select all
traceln("cmd result: " + result[0])



New functions (0.4.7.0+)

sysCmd(cmd [, debug])
This is similar to executeCmd() but uses system() instead of File() and allows to get
stdout, stderr and exit code from the shell command. It's slower than executeCmd() so
you should use this only when needed.

The usage is a bit different than executeCmd(), see example below.
sysCmd() returns an object with the following properties (if present):

.input (string) - this is your command
.stdout (array) - this is the stdout output of your command
.stderr (array) - this is the stderr output of your command
.exit (integer) - this is the exit code of your command (if != 0)
.error (string) - this is the error message returned from system()

Example:
Code: Select all
var cmd = new sysCmd("ls -al", 3);
if (cmd.stdout) {
   traceln(cmd.stdout.join("\n"));
}


SQLite([db] [, options])
This is a little wrapper for sqlite3. It provides three functions:
- query(query [, options])
returns an array conainting arrays. (see example below)

- do(query [, options])
returns true or false

- file(file [, options])
returns true or false

options are passed as sqlite3 commandline options (sqlite3 --help)

Example:
create_table.sql:
Code: Select all
BEGIN TRANSACTION;
DROP TABLE IF EXISTS mytable;
CREATE TABLE mytable(
  id INTEGER NOT NULL primary key autoincrement,
  name VARCHAR(64) DEFAULT '',
);
CREATE INDEX idx_mediamark_hash on mediamark(hash);
INSERT INTO mytable (name) VALUES ('Joe');
INSERT INTO mytable (name) VALUES ('Tom');
COMMIT;


mytable:
Code: Select all
  id | name
-------------
   1 | Joe
   2 | Tom


Example:
Code: Select all
this.sql = new SQLite("/root/mydatabase.db");
this.sql.debug = 3;
if (this.sql.file("create_table.sql")) {
  var lines = this.sql.query("SELECT id, name from mytable");
}

Result:
lines == [["1", "Joe"], ["2", "Tom"]];
lines[0][0] == 1
lines[1][1] == Tom


addWEC(file)
This function installs a WEC plugin and returns true on success and false otherwise.

Example:
Code: Select all
if(addWEC(this.rootPath + "MyPlugin_wec.php")) {
  traceln("added WEC plugin.");
} else {
  traceln("failed to add WEC plugin!");
}



I will try to keep this updated and once new wdlxtv version is released we should move this to public area ;) moved.
Last edited by recliq on Mon Apr 11, 2011 11:29 am, edited 3 times in total.
Reason: updated new fuctions
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Return to WDTVExt Development

Who is online

Users browsing this forum: No registered users and 1 guest