Commit 1bd0476e authored by claes's avatar claes

New styleguide for applications

parent a7081253
<html>
<head>
<link rel="stylesheet" type="text/css" href="pcss.css">
<title>Application styleguide</title>
</head>
<body>
<h2 id="mainmenu">Simple c++ application example </h2>
<xmp>
//
// A simple application
// ra_appl is a subclass to rt_appl and implements the virtual
// functions open(), close(), and scan().
//
#include "pwr.h"
#include "rt_appl.h"
class ra_appl : public rt_appl {
public:
ra_appl() : rt_appl( "ra_appl", errh_eAnix_appl1) {}
void open();
void close();
void scan();
};
void ra_appl::open()
{
// Link to database objects
}
void ra_appl::close()
{
// Unlink to database objects
}
void ra_appl::scan()
{
// Do something
}
int main()
{
ra_appl appl;
appl.init();
appl.register_appl( "Noder-node-MyAppl");
appl.mainloop();
}
</xmp>
<h2 id="mainmenu">Advanced c++ application example </h2>
<xmp>
//
// Example of a proview application program
//
#include "pwr.h"
#include "rt_gdh.h"
#include "rt_errh.h"
#include "rt_aproc.h"
#include "rt_pwr_msg.h"
#include "rt_qcom_msg.h"
#include "rt_ini_event.h"
#include "co_error.h"
class MyAppl {
public:
MyAppl() {}
void init( qcom_sQid *qid);
void open();
void close();
void scan();
float scantime() { return 1.0;}
};
void MyAppl::init( qcom_sQid *qid)
{
qcom_sQid qini;
qcom_sQattr qAttr;
pwr_tStatus sts;
// Init error and status logger with a unic application index per node.
errh_Init( "rs_appl", errh_eAnix_appl1);
errh_SetStatus( PWR__APPLSTARTUP);
// Init database
sts = gdh_Init("rs_appl");
if ( EVEN(sts)) {
errh_Fatal( "gdh_Init, %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(sts);
}
// Create a queue to receive stop and restart events
if (!qcom_Init(&sts, 0, "rs_appl")) {
errh_Fatal("qcom_Init, %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(sts);
}
qAttr.type = qcom_eQtype_private;
qAttr.quota = 100;
if (!qcom_CreateQ(&sts, qid, &qAttr, "events")) {
errh_Fatal("qcom_CreateQ, %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(sts);
}
qini = qcom_cQini;
if (!qcom_Bind(&sts, qid, &qini)) {
errh_Fatal("qcom_Bind(Qini), %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(-1);
}
}
void MyAppl::open()
{
pwr_tOid oid;
pwr_tStatus sts;
// Get configuration object
sts = gdh_NameToObjid( "Noder-Node-MyAppl", &oid);
if ( EVEN(sts)) throw co_error(sts);
aproc_RegisterObject( oid);
// Link to database objects
}
void MyAppl::close()
{
// Unlink to database objects
}
void MyAppl::scan()
{
aproc_TimeStamp();
// Do something
}
int main()
{
pwr_tStatus sts;
MyAppl appl;
int tmo;
char mp[2000];
qcom_sQid qid = qcom_cNQid;
qcom_sGet get;
int swap = 0;
bool first_scan = true;
appl.init( &qid);
try {
appl.open();
}
catch ( co_error& e) {
errh_Error( (char *)e.what().c_str());
errh_Fatal( "rs_appl aborting");
errh_SetStatus( PWR__APPLTERM);
exit(0);
}
aproc_TimeStamp();
errh_SetStatus( PWR__ARUN);
first_scan = true;
for (;;) {
if ( first_scan) {
tmo = (int) (appl.scantime() * 1000 - 1);
}
get.maxSize = sizeof(mp);
get.data = mp;
qcom_Get( &sts, &qid, &get, tmo);
if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
if ( !swap)
appl.scan();
}
else {
ini_mEvent new_event;
qcom_sEvent *ep = (qcom_sEvent*) get.data;
new_event.m = ep->mask;
if (new_event.b.oldPlcStop && !swap) {
errh_SetStatus( PWR__APPLRESTART);
swap = 1;
appl.close();
} else if (new_event.b.swapDone && swap) {
swap = 0;
appl.open();
errh_SetStatus( PWR__ARUN);
} else if (new_event.b.terminate) {
exit(0);
}
}
first_scan = false;
}
}
</xmp>
</body>
</html>
<html>
<head>
<title>Application Styleguide</title>
</head>
<frameset rows="90,*" frameborder="0">
<frame name="I1" frameborder="0" noresize scrolling="no" src="applstyle_h.html"></frame>
<frame name="I2" frameborder="0" noresize scrolling="yes" src="applstyle.html"></frame>
</frameset>
</html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="pcss.css">
<title>Proview</title>
</head>
<body id="pagetitle" bgcolor="black">
<table id="pagetitle" border="0" width="100%" nowrap cellpadding="1" cellspacing="0">
<tr>
<td width = "100">
<a href="index.html" target="_top"><img src="ugglablack.gif" border="0" width="92" height="89" align="middle" alt="Proview main page"></a></td>
<td>Application Styleguide</td>
<td width = "70">
<a href="dev_index.html" target="_top"><font size = 2>>> home </font></a>
</td></tr></table>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment