Hello App: hellopy.mreg
Contents
hellopy.mreg
* hellopy.mreg - MAE message registration for "hello" channel (Python version)
*
* Copyright (c) 2024 HanoverSoft
* Written by Anthony V. Edwards
* 820 Churchill Drive, Chapel Hill, NC 27517
* ave@hanoversoft.net
*
* A MAE app is expected to handle messages/events from multiple users or multiple instances.
* This file directs MAE as to how you want those messages/events handled.
* Each message/event has an id that is used to pull up the appropriate instance of HelloApp.
* An instance of HelloApp is handy for maintaining session data.
* If you don't want to maintain session data, explicitly set appclass to nothing.
*
* This file contains directives for the genmae tool to generate msgHello.cpp, which contains code to
* 1) initial setup by integrating with MAE daemons (e.g. usergw and guibroker for the UI)
* 2) respond to messages/events from MAE, such as user menu selection
* 3) handle API calls (the simple Hello app does not define any API calls) from other MAE apps - asynchronous events
* 4) handle RPC calls (the simple Hello app does not define any API calls) from other MAE apps - synchronous events
* 5) respond to user input controls such as pull-down selection, text responses, etc.
* 6) process other files (such as .cpp or .ui files) that may contain more directives (in comments)
* Comments in this file are included in generated file output, so commenting well here means commenting well elsewhere.
*
* To generate msgHello.py, use
* genmae hellopy.mreg -msgpy msgHello.py
* To generate Python method dummy code for callbacks from this file, which is
* useful for creating/modifying HelloApp.py, use
* genmae hellopy.mreg -cbpy
* If we define #api/#msg blocks for an API for other MAE apps to use, we
* generate the Python source code using
* genmae hellopy.mreg -apipy
* To generate wiki documentation on message handling performed here, we use
* genmae hellopy.mreg -wiki
* which is used in our Hello app documentation stored in /usr/mae/html/doc/hellopy.wiki
* To convert a .ui file into fully proper .html (removing genmae clues), use
* genformcode genformcode html helloPrompt.ui ../../html/record/helloPrompt.html
# Our app's primary class file, so we have ready access to our context
# (Use #apiinclude for API files.)
from HelloApp import HelloApp
import HelloCache
# We communicate within MAE using our own unique channel name 'hello'
#channel=hello
# Internally, we use the HelloApp class to manage session instances
#appclass=HelloApp
# We maintain a cache of multiple sessions in the HelloCache vector
#appcache=HelloCache
# This is the code to locate our instance of HelloApp in the cache
# Or exit out if there's an error.
#idcode
# Track user-specific state (if needed)
user_id= device.getUserId()
pos= HelloCache.findPos(user_id)
if pos < 0 and user_id > 0:
# a new connection - add to cache
newUser= HelloApp(user_id)
# remember our path to the user
newUser.setDevice(device)
# add this user to our in-memory cache
pos= HelloCache.add(user_id, newUser)
if pos < 0:
# We don't have a match for this device
msg= "Unknown device (Uid=" + str(user_id) + ",Conn="+str(device.getConnectionId())+",App="+device.getAppMode()+",tag="+device.getRegion()+") for " + request
MAETask.log (msg)
MAETask.mgmt.incrementInputErrorCount()
return
# any connection-specific data
instance= HelloCache.getitem(pos)
# Here's a code block for any code that should be executed before the message is processed
#msgprecode
# Here's a code block for any code that should be executed after the message is processed
#msgpostcode
/** Initiate a new user session.
* @param param - inbound variables from UserDevice::run() (if any)
*/
#userstart userstart(param)
######## Declare the app menus
# We tell guibroker what our menus are. Before the user reaches us, guibroker
# renders hello.html and populates the page with these menu options.
# As the user clicks on a menu option, we receive the message (#msg) associated
# with that menu option. When we receive that message, MAE calls the method we
# are here associating with the menu. It's menu registration & callback.
# Here's the menu option Display->From DB, which queries the DB to determine the user's name, then says hello
#menu "Display" "From DB"
#msg "fromdb" menu_Display_FromDB()
# Here's the menu option Display->Clear, which sends us the message clrdisp, which in turn calls menu_Display_Clear()
#menu "Display" "Clear"
#msg "clrdisp" menu_Display_Clear()
# Here's the menu option Display->Help, which sends us the message help, which in turn calls menu_Display_Help()
#menu "Display" "Help"
#msg "help" menu_Display_Help()
# Here's how the user quits: menu option Display->Quit
#menu "Display" "Quit"
#msg "quit" menu_Display_Quit()
# Read and process these .ui files to extract out more directives.
# Note that you won't see directives in the .ui file; the genformcode program
# is needed generate them for genmae (which happens implicitly).
# Although only a .ui file is specified here, you can also specify a .cpp file
# which is handy when your .cpp code is generating buttons or text input areas
# and you want to configure callbacks right there (in the comments).
#process "helloPrompt.ui"