profile/ivi/murphy.git
9 years ago{common,resource}: make sure buffers are null-terminated. upstream v0.0.74
Jan Ekström [Thu, 8 Jan 2015 15:29:04 +0000 (17:29 +0200)]
{common,resource}: make sure buffers are null-terminated.

These were found by Coverity, and technically they are correct.
Thus explicit null termination is added or strncpy is used.

9 years agocommon: use decltype to approximate typeof for C++. v0.0.70 v0.0.72 v0.0.73
Krisztian Litkey [Tue, 16 Dec 2014 19:05:03 +0000 (21:05 +0200)]
common: use decltype to approximate typeof for C++.

decltype looks good enough to approximate some usage of the
very handy gcc-compatible typeof extension. It does not seem
to be good enough to cover all cases (one known cas where it
breaks down is mrp_list_entry).

9 years agocommon: more C++-friendly bitmask handling. v0.0.69
Krisztian Litkey [Mon, 15 Dec 2014 09:11:47 +0000 (11:11 +0200)]
common: more C++-friendly bitmask handling.

9 years agocommon: reject gracefully async events on the global (NULL) bus.
Krisztian Litkey [Mon, 15 Dec 2014 09:10:48 +0000 (11:10 +0200)]
common: reject gracefully async events on the global (NULL) bus.

9 years agomask-test: get rid of a warning on 32-bit systems.
Krisztian Litkey [Fri, 12 Dec 2014 17:02:49 +0000 (19:02 +0200)]
mask-test: get rid of a warning on 32-bit systems.

9 years agomurphy-db: fix issues detected by coverity v0.0.68
Janos Kovacs [Fri, 21 Nov 2014 16:15:57 +0000 (18:15 +0200)]
murphy-db: fix issues detected by coverity

9 years agolua-transport: use mrp_lua_error with a return whenever possible.
Krisztian Litkey [Fri, 12 Dec 2014 15:35:53 +0000 (17:35 +0200)]
lua-transport: use mrp_lua_error with a return whenever possible.

9 years agocore: fix a few incorrect mrp_debug usages.
Krisztian Litkey [Thu, 11 Dec 2014 12:12:33 +0000 (14:12 +0200)]
core: fix a few incorrect mrp_debug usages.

9 years agocommon: fix a few incorrect mrp_debug usages.
Krisztian Litkey [Thu, 11 Dec 2014 12:12:11 +0000 (14:12 +0200)]
common: fix a few incorrect mrp_debug usages.

9 years agocommon: annotate mrp_debug_msg as printf-like.
Krisztian Litkey [Thu, 11 Dec 2014 12:11:13 +0000 (14:11 +0200)]
common: annotate mrp_debug_msg as printf-like.

9 years agocommon: allow printf-like formatted assert messages.
Krisztian Litkey [Thu, 11 Dec 2014 11:59:42 +0000 (13:59 +0200)]
common: allow printf-like formatted assert messages.

9 years agolua-event: adjusted to event infra changes, added explicit start/stop.
Krisztian Litkey [Wed, 10 Dec 2014 12:15:15 +0000 (14:15 +0200)]
lua-event: adjusted to event infra changes, added explicit start/stop.

Updated to use the revamped event infrastructure. Added explicit
methods for starting/stopping watches. Added oneshot member to be
more in line with timers and deferred callbacks. Minor stylistical
changes to be more in line with the rest of the Lua bindings.

Emitting events from Lua with data attached is not implemented yet...

9 years agolua-utils: allow and handle 64- and 32-bit array size members.
Krisztian Litkey [Wed, 10 Dec 2014 22:11:21 +0000 (00:11 +0200)]
lua-utils: allow and handle 64- and 32-bit array size members.

9 years agocommon: event infrastructure overhaul, lifted from core to common.
Krisztian Litkey [Tue, 9 Dec 2014 18:38:29 +0000 (20:38 +0200)]
common: event infrastructure overhaul, lifted from core to common.

This patch litfs the original event publish/subscribe code from
core to common and attempts to fix some of its shortcomings.

The patch also introduces events busses to provide an abstraction
for logically grouping related or similar events together. Arbitrary
number of busses can be created dynamically. Subscription and event
delivery (emitting) is always done on a particular bus. There is
a default global (the NULL) bus which is always availablei.
This is the easiest to use for backward-compatibility for code which
used to generate or subscribe to some events but did not have direct
access to the mainloop.

Events can now be delivered both synchronously and asynchronously.
The event mechanism have been put under the mainloop mainly for this
reason (to automatically associate busses with a mainloop) to support
asynchronous delivery. With synchronous delivery, the event have been
delivered to all subscribers by the time the emitting call returns.
With asynchronous delivery the event will be delivered from a deferred
callback once the mainloop is done processing its pending events. The
global NULL bus is not associated with a mainloop and therefore only
supports synchronous delivery.

Data can now be attached to events in different formats. In addition
to the original mrp_msg_t, we now support JSON (mrp_json_t) and custom
pointers. For mrp_msg_t and JSON, the infrastructure takes care of
properly reference-counting the data in case of asychronous delivery.
For custom data this is not done ATM (although that might change), so
the caller has to make sure the event data is valid during delivery
and properly freed afterwards.

Currently it is not possible to delete event busses or unregister
events.

9 years agocore: added initial Lua bindings for event handling.
Ismo Puustinen [Thu, 4 Dec 2014 13:54:12 +0000 (15:54 +0200)]
core: added initial Lua bindings for event handling.

9 years agoresource: fix a typo in an assert message.
Krisztian Litkey [Tue, 9 Dec 2014 17:13:15 +0000 (19:13 +0200)]
resource: fix a typo in an assert message.

9 years agolua-bindings: added functions for inspecting the environment and identity.
Krisztian Litkey [Sat, 29 Nov 2014 13:28:29 +0000 (15:28 +0200)]
lua-bindings: added functions for inspecting the environment and identity.

Added lua-env.c with simple bindings for getting environment variables,
process ID, user ID, group ID, and user name.

9 years agolua-bindings: teach bitwise to handle more than two arguments.
Krisztian Litkey [Fri, 12 Sep 2014 13:33:42 +0000 (16:33 +0300)]
lua-bindings: teach bitwise to handle more than two arguments.

9 years agomurphy-db: added mql_result_rows_get_row_column_index.
Krisztian Litkey [Thu, 20 Nov 2014 11:16:47 +0000 (13:16 +0200)]
murphy-db: added mql_result_rows_get_row_column_index.

9 years agobuild-sys: symlink src/plugins/domain-control to src/domain-control.
Jan Ekström [Fri, 24 Oct 2014 09:52:31 +0000 (12:52 +0300)]
build-sys: symlink src/plugins/domain-control to src/domain-control.

This fixes a mismatch between how domain-control's header is located
and to which kind of structure it is installed when Murphy is installed.

9 years agoresource: try to free resource attributes upon unregistering the set. v0.0.66 v0.0.67
Krisztian Litkey [Mon, 3 Nov 2014 14:10:37 +0000 (16:10 +0200)]
resource: try to free resource attributes upon unregistering the set.

9 years agodbus{,-sdbus,-libdbus}-transport: fix comparison in check_address().
Jan Ekström [Fri, 7 Nov 2014 13:33:46 +0000 (15:33 +0200)]
dbus{,-sdbus,-libdbus}-transport: fix comparison in check_address().

9 years agoresource: stop a possible nullptr dereference in resource_getfield. v0.0.65
Jan Ekström [Thu, 6 Nov 2014 09:28:46 +0000 (11:28 +0200)]
resource: stop a possible nullptr dereference in resource_getfield.

9 years agoresource: fix a nullptr check typo.
Jan Ekström [Thu, 6 Nov 2014 09:20:41 +0000 (11:20 +0200)]
resource: fix a nullptr check typo.

9 years agoresource-dbus: add available classes to the manager interface.
Jan Ekström [Wed, 2 Jul 2014 07:18:57 +0000 (10:18 +0300)]
resource-dbus: add available classes to the manager interface.

User had to before know the system's available classes before
hand; This fixes a discrepancy between this and other Murphy IPC
protocols, as other protocols provided this information to the
user.

9 years agomm-test: remove useless 0-ness check.
Krisztian Litkey [Thu, 6 Nov 2014 13:14:25 +0000 (15:14 +0200)]
mm-test: remove useless 0-ness check.

9 years agowebsocklib: remove useless NULL-ness check.
Krisztian Litkey [Thu, 6 Nov 2014 13:13:07 +0000 (15:13 +0200)]
websocklib: remove useless NULL-ness check.

9 years agolua-bindings: fix Lua debug record short_src check.
Krisztian Litkey [Thu, 6 Nov 2014 13:10:32 +0000 (15:10 +0200)]
lua-bindings: fix Lua debug record short_src check.

9 years agocore: fix thinko that turned purge_deleted into dead-code.
Krisztian Litkey [Thu, 6 Nov 2014 13:04:38 +0000 (15:04 +0200)]
core: fix thinko that turned purge_deleted into dead-code.

9 years agocommon: don't doubly close epollfd on error path.
Krisztian Litkey [Thu, 6 Nov 2014 12:58:44 +0000 (14:58 +0200)]
common: don't doubly close epollfd on error path.

9 years agolibdbus: always va_end(ap) on errors before bailing out.
Krisztian Litkey [Thu, 6 Nov 2014 12:52:31 +0000 (14:52 +0200)]
libdbus: always va_end(ap) on errors before bailing out.

9 years agocommon: always va_end(ap) on error before bailing out.
Krisztian Litkey [Thu, 6 Nov 2014 12:40:47 +0000 (14:40 +0200)]
common: always va_end(ap) on error before bailing out.

9 years agostrm-transport: fail if setting cloexec, reuseaddr, or nonblocking fails.
Krisztian Litkey [Thu, 6 Nov 2014 12:00:16 +0000 (14:00 +0200)]
strm-transport: fail if setting cloexec, reuseaddr, or nonblocking fails.

9 years agodomain-control: make ractive int since it is used as one, not a bool.
Krisztian Litkey [Thu, 6 Nov 2014 11:51:11 +0000 (13:51 +0200)]
domain-control: make ractive int since it is used as one, not a bool.

9 years agomm-test: poison with <= 255 value.
Krisztian Litkey [Thu, 6 Nov 2014 11:48:02 +0000 (13:48 +0200)]
mm-test: poison with <= 255 value.

9 years agodbus-libdbus-transport: make sure address buffer is not overflown.
Krisztian Litkey [Thu, 6 Nov 2014 11:38:08 +0000 (13:38 +0200)]
dbus-libdbus-transport: make sure address buffer is not overflown.

9 years agocore: don't leak RTLD_LOCAL-ly opened handles for core plugins.
Krisztian Litkey [Thu, 6 Nov 2014 10:58:46 +0000 (12:58 +0200)]
core: don't leak RTLD_LOCAL-ly opened handles for core plugins.

9 years agomurphy-db: don't leak result columns created in trigger column_event_callbacks.
Krisztian Litkey [Thu, 6 Nov 2014 10:53:14 +0000 (12:53 +0200)]
murphy-db: don't leak result columns created in trigger column_event_callbacks.

9 years agocommon/strm-transport: uninitialized variable fix.
Krisztian Litkey [Thu, 6 Nov 2014 09:23:50 +0000 (11:23 +0200)]
common/strm-transport: uninitialized variable fix.

9 years agodomain-control/test-client: let client subscribe to audio_playback tables. v0.0.64
Krisztian Litkey [Tue, 4 Nov 2014 14:12:12 +0000 (16:12 +0200)]
domain-control/test-client: let client subscribe to audio_playback tables.

9 years agodomain-control: enforce full initial client notification.
Krisztian Litkey [Tue, 4 Nov 2014 14:02:08 +0000 (16:02 +0200)]
domain-control: enforce full initial client notification.

9 years agodomain-control: subscribe properly for column changes.
Krisztian Litkey [Tue, 4 Nov 2014 14:01:19 +0000 (16:01 +0200)]
domain-control: subscribe properly for column changes.

9 years agoresource: added a few debug printouts.
Krisztian Litkey [Tue, 4 Nov 2014 13:51:51 +0000 (15:51 +0200)]
resource: added a few debug printouts.

9 years agocommon: replace 2-case switch with an if-else.
Krisztian Litkey [Sat, 1 Nov 2014 13:34:01 +0000 (15:34 +0200)]
common: replace 2-case switch with an if-else.

9 years agoresource-backend: move 'emit event' messages to mrp_debug().
Ismo Puustinen [Tue, 4 Nov 2014 09:13:18 +0000 (11:13 +0200)]
resource-backend: move 'emit event' messages to mrp_debug().

9 years agoresource-lua: removed 'data' parameter from resource callbacks.
Ismo Puustinen [Tue, 4 Nov 2014 09:12:35 +0000 (11:12 +0200)]
resource-lua: removed 'data' parameter from resource callbacks.

9 years agoconfig: test case for lua resource API.
Ismo Puustinen [Mon, 3 Nov 2014 14:19:30 +0000 (16:19 +0200)]
config: test case for lua resource API.

9 years agoresource-lua: memory handling fixes.
Ismo Puustinen [Mon, 3 Nov 2014 14:19:17 +0000 (16:19 +0200)]
resource-lua: memory handling fixes.

9 years agocommon: added mrp_normalize_path to file-utils.
Krisztian Litkey [Sat, 1 Nov 2014 08:42:54 +0000 (10:42 +0200)]
common: added mrp_normalize_path to file-utils.

9 years agocommon: added mrp_mkdir to file-utils.
Krisztian Litkey [Fri, 31 Oct 2014 19:54:28 +0000 (21:54 +0200)]
common: added mrp_mkdir to file-utils.

9 years agocommon: add debug printout for epoll. v0.0.63
Krisztian Litkey [Thu, 30 Oct 2014 23:59:10 +0000 (01:59 +0200)]
common: add debug printout for epoll.

9 years agomainloop: use 0 poll timeout if we have enabled deferred callbacks.
Krisztian Litkey [Thu, 30 Oct 2014 23:48:15 +0000 (01:48 +0200)]
mainloop: use 0 poll timeout if we have enabled deferred callbacks.

9 years agocommon: added pulse-subloop.[hc], a pulse subloop implementation.
Krisztian Litkey [Thu, 30 Oct 2014 22:27:50 +0000 (00:27 +0200)]
common: added pulse-subloop.[hc], a pulse subloop implementation.

9 years agocommon: force O_NONBLOCK on for listening stream transports.
Krisztian Litkey [Thu, 30 Oct 2014 13:01:28 +0000 (15:01 +0200)]
common: force O_NONBLOCK on for listening stream transports.

Without this, a transport user could drive the mainloop stuck
blocking in an accept by calling mrp_transport_accept on a
(stream) transport without pending connections. To prevent
this we always force the socket to non-blocking mode when
it is either explicitly listened on, or if the transport
adopts an fd (typically from socket-based activation) and
it is marked as listening.

9 years agocommon: try to reject connection if accept fails in stream transport.
Krisztian Litkey [Thu, 30 Oct 2014 11:34:23 +0000 (13:34 +0200)]
common: try to reject connection if accept fails in stream transport.

Try hard to reject incoming connection if accept fails. If we fail
to reject altogether, close the transport and emit a closed event
with an error.

9 years agocommon: added socket-utils.[hc], mrp_reject_connection.
Krisztian Litkey [Thu, 30 Oct 2014 11:32:58 +0000 (13:32 +0200)]
common: added socket-utils.[hc], mrp_reject_connection.

9 years agoresource-native: disconnect, destroy transport when connection is closed.
Jan Ekström [Thu, 30 Oct 2014 09:06:28 +0000 (11:06 +0200)]
resource-native: disconnect, destroy transport when connection is closed.

9 years agoresource-c: added test app for trying context creations.
Ismo Puustinen [Thu, 30 Oct 2014 08:30:26 +0000 (10:30 +0200)]
resource-c: added test app for trying context creations.

9 years agoplugin-lua: explicitly restore Lua stack across resolver scriptlet runs.
Krisztian Litkey [Tue, 28 Oct 2014 12:52:50 +0000 (14:52 +0200)]
plugin-lua: explicitly restore Lua stack across resolver scriptlet runs.

9 years agolua-log: explicitly restore Lua stack across function calls.
Krisztian Litkey [Tue, 28 Oct 2014 12:51:09 +0000 (14:51 +0200)]
lua-log: explicitly restore Lua stack across function calls.

9 years agolua-resource: explicitly restore Lua stack across callbacks.
Krisztian Litkey [Tue, 28 Oct 2014 12:50:43 +0000 (14:50 +0200)]
lua-resource: explicitly restore Lua stack across callbacks.

9 years agolua-transport: explicitly restore Lua stack across callbacks.
Krisztian Litkey [Tue, 28 Oct 2014 12:48:34 +0000 (14:48 +0200)]
lua-transport: explicitly restore Lua stack across callbacks.

9 years agolua-sighandler: explicitly restore Lua stack across callbacks.
Krisztian Litkey [Tue, 28 Oct 2014 12:48:34 +0000 (14:48 +0200)]
lua-sighandler: explicitly restore Lua stack across callbacks.

9 years agolua-timer: explicitly restore Lua stack across callbacks.
Krisztian Litkey [Tue, 28 Oct 2014 12:48:34 +0000 (14:48 +0200)]
lua-timer: explicitly restore Lua stack across callbacks.

9 years agolua-deferred: explicitly restore Lua stack across callbacks.
Krisztian Litkey [Tue, 28 Oct 2014 12:48:34 +0000 (14:48 +0200)]
lua-deferred: explicitly restore Lua stack across callbacks.

9 years agolua-console: explicitly restore Lua stack across callbacks.
Krisztian Litkey [Tue, 28 Oct 2014 12:48:34 +0000 (14:48 +0200)]
lua-console: explicitly restore Lua stack across callbacks.

9 years agodomain-control: switched to resolver-aware trigger-driven notification logic.
Krisztian Litkey [Mon, 27 Oct 2014 16:27:50 +0000 (18:27 +0200)]
domain-control: switched to resolver-aware trigger-driven notification logic.

Switched client notification logic from table stamp-based to
trigger-driven. Also block client updates if/while ruleset-
resolution is active. Schedule an extra update when resolution
is finished.

Resolver-activity is tracked by subscribing to start/done/fail
events emitted by the resolver and calculating started but un-
finished events.

9 years agomurphy-db: emit transaction depth/ID in transaction trigger events.
Krisztian Litkey [Mon, 27 Oct 2014 18:23:26 +0000 (20:23 +0200)]
murphy-db: emit transaction depth/ID in transaction trigger events.

9 years agomurphy-db: don't leak result rows created in trigger row_event_callbacks. v0.0.61
Krisztian Litkey [Sun, 26 Oct 2014 18:00:05 +0000 (20:00 +0200)]
murphy-db: don't leak result rows created in trigger row_event_callbacks.

This patch does fix certain memory leaks, but to be honest I'm not
entirely sure if the fix needs to be put behind some extra checks
to not cause trouble by overzealous freeing on other code pathes.
Needs eyeballing from someone more initiated...

9 years agodomain-control: fixed a few compiler warnings.
Krisztian Litkey [Sun, 26 Oct 2014 15:32:46 +0000 (17:32 +0200)]
domain-control: fixed a few compiler warnings.

9 years agosample-config: better timer/deferred/sighandler tests.
Krisztian Litkey [Sun, 26 Oct 2014 15:04:48 +0000 (17:04 +0200)]
sample-config: better timer/deferred/sighandler tests.

9 years agolua-deferred: fixes, explicit enable/disable, removed 'data' member.
Krisztian Litkey [Sun, 26 Oct 2014 13:16:27 +0000 (15:16 +0200)]
lua-deferred: fixes, explicit enable/disable, removed 'data' member.

Added support for explicitly enabling/disabling deferred callbacks.
Removed 'userdata'-like data member as pointless. Since Lua deferred
callback is an extensible object, one can set data as an extended
Lua attribute just as well. No need to special-case it out...

Deferred callbacks are now automatically disabled if invoking the
associated callback fails.

9 years agolua-sighandler: fixes, explicit enable/disable, removed 'data' member.
Krisztian Litkey [Sun, 26 Oct 2014 13:14:42 +0000 (15:14 +0200)]
lua-sighandler: fixes, explicit enable/disable, removed 'data' member.

Added support for explicitly enabling/disabling signal handlers.
Removed 'userdata'-like data member as pointless. Since Lua
sighander is an extensible object, one can set data as an extended
Lua attribute just as well. No need to special-case it out...

Signal handlers are now automatically disabled if invoking the
associated callback fails.

9 years agolua-timer: fixes, explicit start/stop, removed 'data' member.
Krisztian Litkey [Sat, 25 Oct 2014 17:25:52 +0000 (20:25 +0300)]
lua-timer: fixes, explicit start/stop, removed 'data' member.

Added support for explicitly stopping and starting an otherwise
fully functional timer (IOW both interval and callback set). Also
removed the userdata-like 'data' members as pointless. Since Lua
timer is an extensible object, one can set data as an extended
Lua attribute just as well. No need to special-case it out...

Removed all attempts to self-destruct the object by explicitly
calling mrp_lua_destroy_object as Lua timer is now marked dynamic.

Timers are now automatically disabled if invoking the callback
fails.

9 years agolua-utils: exttbl and reftbl cleanup fixes, call user destructor earlier.
Krisztian Litkey [Sun, 26 Oct 2014 12:42:25 +0000 (14:42 +0200)]
lua-utils: exttbl and reftbl cleanup fixes, call user destructor earlier.

Fix bad exttbl cleanup thinko (exttbl is an ordinary table, not
a table of references). Change reftbl cleanup to simply remove
our reference to reftbl. Also moved invoking the user-provided
destructor a bit earlier before reftbl and extbl are cleaned up.

Explicit cleanup of reftbl (by explicitly looping through reftb
and removing all references found there) reliably triggers an
assert in the Lua garbage-collector. I'm quite puzzled why this
happens. Maybe it has something to do with being called from the
garbage-collector... though I checked the documentation about
finalizers and did not find a word about any limitations what
one would be allowed to do from a finalizers. For the time being
we just drop our reference to reftbl, which should be good enough
as it should remove all references from the table once that is
collected. This needs further head-scratching and eyeballing...

9 years agolua-utils: removed #if 0'd code.
Krisztian Litkey [Sat, 25 Oct 2014 16:52:13 +0000 (19:52 +0300)]
lua-utils: removed #if 0'd code.

9 years agolua-utils: properly release references from refs.priv and refs.ext.
Krisztian Litkey [Sat, 25 Oct 2014 15:30:40 +0000 (18:30 +0300)]
lua-utils: properly release references from refs.priv and refs.ext.

9 years agolua-utils: obey format string for object dumping.
Krisztian Litkey [Sat, 25 Oct 2014 15:28:55 +0000 (18:28 +0300)]
lua-utils: obey format string for object dumping.

9 years agolua-utils: fix a few snprintf-related formatted printing warnings.
Krisztian Litkey [Sat, 25 Oct 2014 11:06:57 +0000 (14:06 +0300)]
lua-utils: fix a few snprintf-related formatted printing warnings.

9 years agotest-plugin: get rid of a compiler warning. v0.0.60
Krisztian Litkey [Sat, 25 Oct 2014 09:26:52 +0000 (12:26 +0300)]
test-plugin: get rid of a compiler warning.

9 years agolua-sighandler: get rid of a compiler warning.
Krisztian Litkey [Sat, 25 Oct 2014 09:26:04 +0000 (12:26 +0300)]
lua-sighandler: get rid of a compiler warning.

9 years agolua-deferred: get rid of a compiler warning.
Krisztian Litkey [Sat, 25 Oct 2014 09:25:51 +0000 (12:25 +0300)]
lua-deferred: get rid of a compiler warning.

9 years agolua-timer: get rid of a compiler warning.
Krisztian Litkey [Sat, 25 Oct 2014 09:25:42 +0000 (12:25 +0300)]
lua-timer: get rid of a compiler warning.

9 years agoresource-lua: plant the necessary funcbridge gettop/settop wrappers.
Krisztian Litkey [Fri, 24 Oct 2014 16:37:44 +0000 (19:37 +0300)]
resource-lua: plant the necessary funcbridge gettop/settop wrappers.

9 years agolua-bindings: clone JSON objects when setting them as Lua JSON members.
Krisztian Litkey [Mon, 20 Oct 2014 14:22:42 +0000 (17:22 +0300)]
lua-bindings: clone JSON objects when setting them as Lua JSON members.

Create a private copy (by cloning) of JSON objects when setting
them as members of a Lua JSON object. Otherwise the same object
would end up being set (and without the necessary extra refcounts)
as members of several Lua JSON objects. This would wreak havoc when
those objects get destroyed, eventually double-freeing a shared
JSON member.

9 years agolua-bindings: mark Lua JSON class to opt-out from implicit self-referencing.
Krisztian Litkey [Thu, 16 Oct 2014 20:35:58 +0000 (23:35 +0300)]
lua-bindings: mark Lua JSON class to opt-out from implicit self-referencing.

JSON Lua objects should definitely not be self-referencing. They are
not going to get explicitly destroyed from C. Rather they should obey
the normal Lua scoping/object lifecycle rules and get garbage-collected
accordingly.

9 years agocommon: added mrp_json_clone for creating a private copy of a JSON object.
Krisztian Litkey [Mon, 20 Oct 2014 15:31:10 +0000 (18:31 +0300)]
common: added mrp_json_clone for creating a private copy of a JSON object.

9 years agolua-utils: add support for dynamically collected Lua objects.
Krisztian Litkey [Thu, 16 Oct 2014 19:33:11 +0000 (22:33 +0300)]
lua-utils: add support for dynamically collected Lua objects.

This patch tries to address a number of limitations in the
Murphy Lua object infrastructure that currently prevents us
from creating Lua objects with expected Lua object lifecycle
characteristics and subject to normal Lua garbage-collection
rules.

This patch is monsterous in size and I already regret having
squashed it beyond what would have been more reasonable. I'm
still reluctant to go through the trouble of splitting it up
again to more self-contained orthogonal chunks, as the patch
only touches lua-utils/objects.[hc]. Instead I sum up here
the logically distincts parts the patch is made of:

1) Introduce dynamic classes and implement their necessary
   behavior. This involves introducing the DYNAMIC flag, as
   well as providing versions of the simple CLASSDEF macros
   that take also a flag as it is expected that many of the
   simple classes will need to be dynamic.

   Implementing the necessary behaviour touches object
   creation, destruction (including userdata destuction),
   and pushing. As part of the necessary changes, dynamic
   objects can not be pushed by reference any more (since
   they do not install global self-references). Therefore,
   objects have been modified so that two Lua objects can
   share a (refcounted) userdata_t (the essence of a Murphy
   Lua object) by adding a layer of indirection. IOW, now
   instead of a userdata_t being directly allocated as a Lua
   (userdata) object on the stack, the corresponding Lua
   (userdata) object now contains a pointer to a reference
   counted userdata_t (Murphy Lua object). Sorry about the
   confusing terminology, for once I'm not the one to be
   blamed... Anyway, now pushing a dynamic object becomes
   merely creating a new Lua object pointing to the same
   userdata_t and increasing the refcount of the latter.
   Popping/destroying simply becomes decreasing the refcount
   and freeing the object when the last reference is gone.
   Dynamic objects are not supposed to be explictly destroyed
   and indeed the explicit destructor will refuse to do
   lifecyclewise anything to dynamic objects. It will print
   an error if th eexplicit destructor is ever called with a
   dynamic object.

   Note that if you use the more recently introduced but
   arguably slightly more complex MRP_LUA_DEFINE_CLASS macros
   to declare your classes, even Lua extensions of your objects
   keep working as before. For classes created with the original
   macros, things might not work as you'd expect (but this
   should be really trivial to fix by switching static objects
   over to the newer explicit extension mechanism/infra).

2) Slight cleanups and fixes to the object-infra/userdata_t.
   userdata has been slightly modified to collect all the
   various references under a single refs structure with luatbl
   replaced by refs.self, exttbl replaced by refs.ext and reftbl
   replaced by refs.priv. The reference and extension table
   cleanup functions have been (hopefully) fixed to properly let
   go of all per-object references upon object destruction.
   MRP_LUA_CLASS_PRIVREFS has been made implicit and removed
   altogether. Hence, all the explicit referencing functions now
   operate on private references on a per object basis.

3) The object create/push/destroy/pop/unref code pathes have
   now been planted with more thorough debug messages for better
   debuggability.

4) Two functions have been added for debug-dumping both static and
   dynamic object instances in a unified format.

Here are a few more words about the various bits this patch is
comprised of...

The patch loosens the assumptions about whether instances of
all Lua classes always need to be implicitly self-referencing.
Since most of our classes and objects are still configuration
objects or Lua scripting extensions to C objects, neither of
wich are supposed to be destroyed from Lua, we default to self-
referencing classes. Instances of such classes always get a
global reference automatically installed, essentially making
them static and preventing garbage collection from taking place
until they are explicitly destroyed (which also removes their
global reference).

With this patch in place, one can now mark a class dyanmic thus
opting out from implicit self-referencing on a per class basis.
This happens by setting the flag MRP_LUA_CLASS_DYNAMIC for the
class definition. Instances of such classes will not auto-
matically create a globally reachable self-reference into the
registry and hence will be subject to more natural Lua object
lifecycle rules. Once all reference to such an object go out of
scope the object will be garbage collected and destroyed.

Added a level of indirection between murphy Lua objects and their
userdata. Instead of userdata being directly allocated by Lua and
being part of the Lua object itself, userdata is now allocated as
a separate reference-counted chunk of memory. A Lua object now is
just metadata plus a pointer to the separately allocated userdata.

Pushing an object instance on the Lua stack now does not require
keeping a Lua reference to the object. Instead, a new Lua object
(Lua userdata) is created, made to point to the existing userdata
and the userdata reference count is increased. The destructor for
userdata_t has been modified to decrease the reference count of
the object and only destroy it when the last reference is gone.

With this new scheme, several Lua (userdata) objects can exist for
the same userdata (Murphy Lua object), each keeping its own reference
in the userdata reference count. The constructor, push and destructor
have been set up to reference count the potentially shared userdata
so that once all Lua instances representing (pointing to) the same
object instance go out of scope and get collected, the object instance
itself is destroyed.

These changes should be completely transparent to all existing object
implementations. Self-referencing objects still keep a global reference
to themselves in the registry just like they used to preventing the
initially created object to ever get out of scope. Self-referencing
objects are still pushed to the Lua stack by reference.

9 years agolua-utils: added mrp_lua_call{stack,trace}.
Krisztian Litkey [Fri, 24 Oct 2014 13:54:51 +0000 (16:54 +0300)]
lua-utils: added mrp_lua_call{stack,trace}.

9 years agocommon: added support for runtime refcounting error detection.
Krisztian Litkey [Thu, 23 Oct 2014 15:37:06 +0000 (18:37 +0300)]
common: added support for runtime refcounting error detection.

Added support for detecting when object references have been
overzelaously dropped below a reference count of zero. Print
an error message with the offending unref that triggered the
condition (wich is of course not necessarily the bug itself).

refcounting error detection can be disabled during compilation.

9 years agocore: added 'debug mm dump' console command for dumping unfreed objects.
Krisztian Litkey [Fri, 17 Oct 2014 16:04:55 +0000 (19:04 +0300)]
core: added 'debug mm dump' console command for dumping unfreed objects.

9 years agodomain-controller: update watch stamp after sending notifications.
Krisztian Litkey [Sat, 25 Oct 2014 10:04:32 +0000 (13:04 +0300)]
domain-controller: update watch stamp after sending notifications.

Update proxy table watch stamps after table changes have been
synced to the corresponding client. Failing to do so causes all
transactions to trigger notifications to all clients regardless
of what they have subscribed to.

9 years agoresource-native: enable json-c/JSON-Glib symbol clash hackaround.
Krisztian Litkey [Fri, 10 Oct 2014 17:13:01 +0000 (20:13 +0300)]
resource-native: enable json-c/JSON-Glib symbol clash hackaround.

resource-api.h is currently the only known location which triggers
the PITA symbol clash. It happens when compiling ico-uxf-homescreen.
It indirectly includes resource-api.h and also uses JSON-Glib for
manipulating JSON objects ending up including both...

9 years agocommon: added json-c/JSON-Glib symbol clash hackaround.
Krisztian Litkey [Fri, 10 Oct 2014 16:54:19 +0000 (19:54 +0300)]
common: added json-c/JSON-Glib symbol clash hackaround.

json-c and JSON-Glib have a symbol clash on json_object_get_type.
With the latest JSON transport mode changes, if someone ends up
directly or indirectly including both our transport.h, and hence
our json.h, as well as JSON-Glib, we'll trigger the symbol clash.

As a workaround if we detect that JSON-Glib has already been
included we'll compile with alternative signatures (void *,
instead of mrp_json_t *) and omit including json.h. Also we
let people give us a warning by defining __JSON_GLIB_DANGER__
that they will or might include JSON-Glib, in which case
we also compile with the alternative signatures. Oh boy...

9 years agocommon: add an explicit transport mode for JSON-based encoding.
Krisztian Litkey [Thu, 2 Oct 2014 08:07:27 +0000 (11:07 +0300)]
common: add an explicit transport mode for JSON-based encoding.

Promoted JSON-based encoding to an explicit transport mode of its
own. Taught the stream- and datagram-transports to talk JSON. The
datagram-transport JSON code is untested. The stream-transport has
been minimally exercised.

The websocket transport has not been flipped over to the dedicated
mode yet. It still runs the transport in custom mode for JSON-
based messaging.

9 years agoresource-lua: fixed call order, memory freeing.
Ismo Puustinen [Mon, 29 Sep 2014 07:19:33 +0000 (10:19 +0300)]
resource-lua: fixed call order, memory freeing.

9 years agoresource-backend: fix a memory leak.
Ismo Puustinen [Mon, 6 Oct 2014 10:31:19 +0000 (13:31 +0300)]
resource-backend: fix a memory leak.

9 years agosample-config: added a sample timer test.
Krisztian Litkey [Thu, 18 Sep 2014 08:23:47 +0000 (11:23 +0300)]
sample-config: added a sample timer test.

9 years agolua-timer: delete timer if callback is set to null/nil.
Krisztian Litkey [Thu, 18 Sep 2014 08:15:22 +0000 (11:15 +0300)]
lua-timer: delete timer if callback is set to null/nil.

9 years agolua-object: always init variable length when iterating object fields.
Ismo Puustinen [Mon, 22 Sep 2014 09:58:41 +0000 (12:58 +0300)]
lua-object: always init variable length when iterating object fields.