| 1 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
# |
| 3 |
# NOTE! This copyright does *not* cover user models that use these Nasal |
| 4 |
# services by normal function calls - this is merely considered normal use |
| 5 |
# of the code, and does *not* fall under the heading of "derived work." |
| 6 |
#------------------------------------------------------------------------------- |
| 7 |
# emesary.deb.nas - emesary debug helpers |
| 8 |
# author: Henning Stahlke |
| 9 |
# created: 06/2020 |
| 10 |
#------------------------------------------------------------------------------- |
| 11 |
var _emesaryDebugN = props.getNode("/_debug/emesary/",1); |
| 12 |
var _emesaryDebugEnableN = _emesaryDebugN.getNode("enabled",1); |
| 13 |
_emesaryDebugEnableN.setBoolValue(_emesaryDebugEnableN.getValue()); |
| 14 |
|
| 15 |
var __setup = func { |
| 16 |
var debugRecipient = emesary.Recipient.new("Debug"); |
| 17 |
|
| 18 |
debugRecipient.Receive = func(ntf) { |
| 19 |
_emesaryDebugEnableN.getValue() or return; |
| 20 |
|
| 21 |
if (!isa(ntf, emesary.Notification)) { |
| 22 |
logprint(DEV_ALERT, "debugRecipient: argument is not a emesary.Notification!"); |
| 23 |
return emesary.Transmitter.ReceiptStatus_Fail; |
| 24 |
} |
| 25 |
# ignore FrameNotification as it would flood the log/console at frame rate |
| 26 |
if (ntf.NotificationType != "FrameNotification") { |
| 27 |
print("debugRecipient: type=", ntf.NotificationType, " id=", ntf.Ident); |
| 28 |
debug.dump(keys(ntf)); |
| 29 |
# count notifications |
| 30 |
if (isstr(ntf.NotificationType)) { |
| 31 |
var cnt = _emesaryDebugN.getChild(ntf.NotificationType, 0, 1); |
| 32 |
if (isstr(ntf.Ident)) { |
| 33 |
cnt = cnt.getNode(ntf.Ident, 1); |
| 34 |
} |
| 35 |
if (cnt.getValue() == nil) { |
| 36 |
cnt.setIntValue(0); |
| 37 |
} |
| 38 |
cnt.increment(); |
| 39 |
} |
| 40 |
} |
| 41 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 42 |
} |
| 43 |
|
| 44 |
emesary.GlobalTransmitter.Register(debugRecipient); |
| 45 |
|
| 46 |
# send a test message |
| 47 |
var debugNotification = emesary.Notification.new("debug", "test"); |
| 48 |
emesary.GlobalTransmitter.NotifyAll(debugNotification); |
| 49 |
|
| 50 |
#add monitoring |
| 51 |
var name = emesary._transmitters.getName(); |
| 52 |
emesary._transmitters.addCallback(func (k, v) { |
| 53 |
emesary._transmitters.keys2props(_emesaryDebugN.getNode(name, 1)); |
| 54 |
}); |
| 55 |
emesary._transmitters.keys2props(_emesaryDebugN.getNode(name, 1)); |
| 56 |
} |
| 57 |
|
| 58 |
settimer(__setup,0); |