Hello App: mgmtHello.py
Contents
mgmtHello.py
#
# mgmtHello.cpp - handle a management request sent by supervisor for the hello channel
# Copyright (c) 2024 HanoverSoft
# Written by Anthony V. Edwards
# 820 Churchill Drive, Chapel Hill, NC 27517
# ave@hanoversoft.net
# While the Hello app is running, the Supervisor app can query its state,
# collect metrics, and possibly adjust some parameters. This is done here
# through the MgmtClient class interface, which is part of MAE.
import os
import sys
mae_python_path= '/usr/mae/python'
if 'MAE_PYTHON' in os.environ:
mae_python_path= os.environ['MAE_PYTHON']
from MAETask import MAETask
import HelloCache
def getHelloCacheSize() -> str:
Get dynamic values
@return number of active HelloApp records in cache
size= HelloCache.cache.activeRecords()
return size
def setHelloCacheSize(param) -> bool:
Set new values
@param param - key/value pairs of variables to set however, only "value" is supported
newSize= param.getInt("value")
# compress the array - get rid of gaps
HelloCache.cache.optimize()
# Resize as instructed
HelloCache.cache.setSize(newSize)
return True
When an admin user has a privileged UI interface, this method will handle the UI event.
Note: When UI controls require a callback, make sure cbdata["sysadmin"]="T" so the
MgmtClient.handleInputResponse() is called instead of the app's.
@param device - the connection back to the user's device
@param param - key/value pairs to handle a UI response
pass
When an operator user has a privileged UI interface, this method will handle the UI event.
Note: When UI controls require a callback, make sure cbdata["sysadmin"]="T" so our
MgmtClient.handleInputResponse() is called instead of the app's.
@param device - the connection back to the user's device
@param param - key/value pairs to handle a UI response
pass
Handle user interactions for the admin or operator user.
@param device - the connection back to the user's device
@param cbtag - callback tag / action to take
@param cbdata - callback data associated with action
@param response - user selection or text input
# Note: we don't have an admin or operator special interface, so just
# route it back to the app's input response handler.
MAETask.handleInputResponse(MAETask.getAppId(), device, cbtag, cbdata, response)
Initialize our management parameters that can be get & set by supervisor.
@param channel - the channel name to initialize (relevant if the app supports muiltiple channels)
# GET parameters - Values that can be queried
MAETask.mgmt.addGetParameter ("", "appname", MAETask.getName()) # our name
# list of categories to query; for each item in list, there's *_max, *_size
MAETask.mgmt.addGetParameter ("cache", "list", HelloCache.CacheList)
# the number of active sessions
MAETask.mgmt.addGetParameter ("cache", "User_size", getHelloCacheSize)
# the maximum number of active sessions allowed
MAETask.mgmt.addGetParameter ("cache", "User_max", HelloCache.HelloCache_max)
# SET parameters - Values that can be changed
# change the maximum number of active sessions allowed
MAETask.mgmt.addSetParameter ("cache", "User_max", setHelloCacheSize)