Commit 4bec0202 authored by claes's avatar claes

Termination event from rt_ini

parent 032f57ba
......@@ -33,7 +33,7 @@ JNIEXPORT void JNICALL Java_jpwr_rt_Mh_initIDs
Mh_id = (*env)->FindClass( env, "jpwr/rt/Mh");
if(Mh_id == NULL)
{
printf("null");
printf("jpwr_rt_mh.c: couldnt find jpwr/rt/Mh class\n");
}
//hmta pekare till staticmetoden messReceived
Mh_messReceived_id = (*env)->GetStaticMethodID( env, Mh_id, "messReceived",
......@@ -181,9 +181,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Mh_outunitConnect
user.oix = (*env)->CallIntMethod( env, objid_obj, PwrtObjid_getOix);
user.vid = (*env)->CallIntMethod( env, objid_obj, PwrtObjid_getVid);
// Wait for mh has flagged initizated qqq vad r detta
mh_UtilWaitForMh();
//gr connect
sts = mh_OutunitConnect(
user,
......
......@@ -5,6 +5,12 @@
#include "co_time.h"
#include "co_cdh_msg.h"
#include "rt_qcom_msg.h"
#include "rt_errh.h"
#include "rt_pwr_msg.h"
#include "rt_ini_event.h"
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createQ
(JNIEnv *env, jobject object, jint qix, jint nid, jstring jname)
......@@ -34,7 +40,7 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createQ
qid.nid = nid;
qcom_CreateQ( &sts, &qid, &attr, cstr);
(*env)->ReleaseStringUTFChars( env, jname, cstr);
printf( "Create que, qix %d, nid %d, sts %d\n", qid.qix, qid.nid, sts);
//printf( "Create que, qix %d, nid %d, sts %d\n", qid.qix, qid.nid, sts);
jsts = (jint) sts;
return_obj = (*env)->NewObject( env, qcomrCreateQ_id,
qcomrCreateQ_cid, qid.qix, qid.nid, jsts);
......@@ -47,6 +53,164 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createQ
return return_obj;
}
/*
* Class: jpwr_rt_Qcom
* Method: createIniEventQ
* Signature: ()Ljpwr/rt/QcomrCreateQ;
*/
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createIniEventQ
(JNIEnv *env, jobject object, jstring jname)
{
jclass qcomrCreateQ_id;
jmethodID qcomrCreateQ_cid;
jobject return_obj;
jint jsts;
qcom_sQid qid;
qcom_sQattr qAttr;
qcom_sQid qini;
int sts;
char *cstr;
const char *name;
qcomrCreateQ_id = (*env)->FindClass( env, "jpwr/rt/QcomrCreateQ");
qcomrCreateQ_cid = (*env)->GetMethodID( env, qcomrCreateQ_id,
"<init>", "(III)V");
name = (*env)->GetStringUTFChars( env, jname, 0);
cstr = (char *)name;
//printf("%s\n", cstr);
// Create a queue to receive stop and restart events
if (!qcom_Init(&sts, 0, cstr)) {
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, cstr)) {
errh_Fatal("qcom_CreateQ, %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(sts);
}
(*env)->ReleaseStringUTFChars( env, jname, cstr);
//printf( "Create que, qix %d, nid %d, sts %d\n", qid.qix, qid.nid, sts);
jsts = (jint) sts;
return_obj = (*env)->NewObject( env, qcomrCreateQ_id,
qcomrCreateQ_cid, qid.qix, qid.nid, jsts);
qini = qcom_cQini;
if (!qcom_Bind(&sts, &qid, &qini)) {
errh_Fatal("qcom_Bind(Qini), %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(-1);
}
return return_obj;
}
/*
* Class: jpwr_rt_Qcom
* Method: getIniEvent
* Signature: (III)Ljpwr/rt/QcomrGetIniEvent;
*/
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getIniEvent
(JNIEnv *env, jobject object, jint qix, jint nid, jint timeoutTime)
{
jclass qcomrGetIniEvent_id;
jmethodID qcomrGetIniEvent_cid;
jobject return_obj;
jint jsts;
jboolean jterminate = FALSE;
jboolean jswapInit = FALSE;
jboolean jswapDone = FALSE;
jboolean jtimeout = FALSE;
qcom_sQid qid;
int sts;
int tmo = timeoutTime;
pwr_tBoolean terminate = FALSE;
pwr_tBoolean swapInit = FALSE;
pwr_tBoolean swapDone = FALSE;
pwr_tBoolean timeout = FALSE;
char mp[2000];
qcom_sGet get;
ini_mEvent new_event;
qcom_sEvent *ep;
qcomrGetIniEvent_id = (*env)->FindClass( env, "jpwr/rt/QcomrGetIniEvent");
qcomrGetIniEvent_cid = (*env)->GetMethodID( env, qcomrGetIniEvent_id,
"<init>", "(ZZZZI)V");
qid.qix = qix;
qid.nid = nid;
get.maxSize = sizeof(mp);
get.data = mp;
qcom_Get( &sts, &qid, &get, tmo);
if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
timeout = TRUE;
}
else {
ep = (qcom_sEvent*) get.data;
new_event.m = ep->mask;
if (new_event.b.swapInit) {
errh_SetStatus( PWR__APPLRESTART);
swapInit = TRUE;
}
else if (new_event.b.swapDone) {
swapDone = TRUE;
errh_SetStatus( PWR__ARUN);
}
else if (new_event.b.terminate) {
terminate = TRUE;
}
}
jsts = (jint) 1;
jterminate = (jboolean) terminate;
jswapInit = (jboolean) swapInit;
jswapDone = (jboolean) swapDone;
jtimeout = (jboolean) timeout;
return_obj = (*env)->NewObject( env, qcomrGetIniEvent_id,
qcomrGetIniEvent_cid,
jterminate,
jswapInit,
jswapDone,
jtimeout,
jsts);
return return_obj;
}
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getString
(JNIEnv *env, jobject object, jint qix, jint nid)
{
......@@ -71,7 +235,7 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getString
qcom_Get( &sts, &qid, &get, 0);
if ( ODD(sts))
{
printf("Qcom_get: Received data: %s\n", (char *)get.data);
//printf("Qcom_get: Received data: %s\n", (char *)get.data);
jdata = (*env)->NewStringUTF( env, (char *)get.data);
......
......@@ -17,11 +17,19 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createQ
/*
* Class: jpwr_rt_Qcom
* Method: getString
* Signature: (II)Ljpwr/rt/CdhrString;
* Method: createIniEventQ
* Signature: (Ljava/lang/String;)Ljpwr/rt/QcomrCreateQ;
*/
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getString
(JNIEnv *, jobject, jint, jint);
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createIniEventQ
(JNIEnv *, jobject, jstring);
/*
* Class: jpwr_rt_Qcom
* Method: getIniEvent
* Signature: (III)Ljpwr/rt/QcomrGetIniEvent;
*/
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getIniEvent
(JNIEnv *, jobject, jint, jint, jint);
/*
* Class: jpwr_rt_Qcom
......@@ -31,6 +39,14 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getString
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_putString
(JNIEnv *, jobject, jint, jint, jstring);
/*
* Class: jpwr_rt_Qcom
* Method: getString
* Signature: (II)Ljpwr/rt/CdhrString;
*/
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getString
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
......
......@@ -129,6 +129,7 @@ public class GdhServer
GdhServer gdhServer = new GdhServer();
gdhServer.openServerSocket();
System.out.println("GdhServer exiting");
System.exit(0);
}
......@@ -206,11 +207,12 @@ public class GdhServer
try
{
serverSocket = new ServerSocket(PORT);
serverSocket.setSoTimeout(1000);
}
catch(IOException e)
{
errh.fatal("Could not listen on port " + PORT);
System.exit(1);
return;
}
gdh = new Gdh((Object)null);
......@@ -225,7 +227,16 @@ public class GdhServer
}
errh.setStatus( Errh.PWR__SRUN);
Qcom qcom = new Qcom();
QcomrCreateQ qque = qcom.createIniEventQ("GdhServer");
if(qque.evenSts())
{
System.out.println("Gdhser");
errh.fatal("GdhSever couldn create EventQue");
return;
}
QcomrGetIniEvent qrGetIniEv;
while(true)
{
Socket cliSocket = null;
......@@ -235,10 +246,28 @@ public class GdhServer
cliSocket = serverSocket.accept();
}
catch(InterruptedIOException e)
{
qrGetIniEv = qcom.getIniEvent(qque.qix, qque.nid, 0);
if(qrGetIniEv.timeout)
continue;
else if(qrGetIniEv.terminate)
{
System.out.println("GdhServer received killmess from QCom");
return;
}
else
{
//Do nothing for the moment
//But in the future we should reinitialize if swap
continue;
}
}
catch(IOException e)
{
errh.error("Accept failed.");
// System.exit(1);
continue;
}
if(threadCount <= maxConnections)
......
......@@ -69,7 +69,18 @@ public class MhServer
MhServer mhServer = new MhServer();
mhServer.openServerSocket();
for(int i=0;i < mhServer.mhThread.length;i++)
{
mhServer.mhThread[i] = null;
}
try{
mhServer.finalize();
}
catch(Throwable e) {
}
mhServer = null;
System.out.println("MhServer exiting");
System.exit(0);
}
......@@ -131,6 +142,7 @@ public class MhServer
cdhrMaxAlarms = gdh.getObjectInfoInt(maxAlarmsAttr);
cdhrMaxEvents = gdh.getObjectInfoInt(maxEventsAttr);
cdhrMaxCon = gdh.getObjectInfoInt(maxConAttr);
System.out.println( "MaxNoOfAlarms: " + cdhrStringUser.str + " " + cdhrMaxAlarms.value + " " + cdhrMaxAlarms.evenSts());
if(cdhrMaxCon.evenSts())
{
return cdhrMaxCon.getSts();
......@@ -184,7 +196,9 @@ public class MhServer
try
{
serverSocket = new ServerSocket(PORT);
serverSocket.setSoTimeout(1000);
}
catch(IOException e)
{
System.out.println("IOException i openServerSocket");
......@@ -217,13 +231,25 @@ public class MhServer
errh.setStatus( Errh.PWR__SRVTERM);
return;
}
MhSendThread mhSendThread = new MhSendThread(mh);
errh.setStatus( Errh.PWR__SRUN);
Qcom qcom = new Qcom();
QcomrCreateQ qque = qcom.createIniEventQ("MhServer");
if(qque.evenSts())
{
System.out.println("MH:Error during qreateque");
errh.fatal("MH:Error during qcom.createIniEventQ");
return;
}
QcomrGetIniEvent qrGetIniEv;
while(keepRunning)
{
Socket cliSocket = null;
......@@ -235,11 +261,33 @@ public class MhServer
}
cliSocket = serverSocket.accept();
}
catch(InterruptedIOException e)
{
qrGetIniEv = qcom.getIniEvent(qque.qix, qque.nid, 0);
if(qrGetIniEv.timeout)
{
//do nothing
continue;
}
else if(qrGetIniEv.terminate)
{
//Time to die
System.out.println("MhServer received killmess from QCom");
return;
}
else
{
//All other messages is qurrently ignored
//But perhaps we should reinitialize when we get
//swapdone
continue;
}
}
catch(IOException e)
{
errh.error("Accept failed.");
// System.exit(1);
continue;
}
if(log)
......
......@@ -21,6 +21,8 @@ public class Qcom {
}
public native QcomrCreateQ createQ( int qix, int nid, String name);
public native QcomrCreateQ createIniEventQ(String name);
public native QcomrGetIniEvent getIniEvent(int qix, int nid, int timeoutTime);
private native PwrtStatus putString( int qix, int nid, String data);
public native CdhrString getString( int qix, int nid);
}
......@@ -57,6 +57,9 @@
#include "co_dcli.h"
#include "rt_pwr_msg.h"
#include "rt_aproc.h"
#include "rt_qcom.h"
#include "rt_qcom_msg.h"
#include "rt_ini_event.h"
#define check4a(sts,str) if((sts)==-1)perror(str)
......@@ -1353,6 +1356,7 @@ int main ()
pwr_tStatus sts;
pwr_tInt32 sts4a;
pwr_tUInt32 c;
qcom_sQid my_q = qcom_cNQid;
errh_Init("pwr_bck", errh_eAnix_bck);
errh_SetStatus( PWR__SRVSTARTUP);
......@@ -1370,6 +1374,18 @@ int main ()
}
errh_SetStatus( PWR__SRUN);
if (!qcom_Init(&sts, NULL, "pwr_bck")) {
errh_Fatal("qcom_Init, %m", sts);
errh_SetStatus( PWR__SRVTERM);
exit(sts);
}
if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) {
errh_Fatal("qcom_CreateQ, %m", sts);
errh_SetStatus( PWR__SRVTERM);
exit(sts);
}
for (;;) {
#ifdef OS_ELN
ker$clear_event(NULL, bck_forced_activation);
......@@ -1380,8 +1396,11 @@ int main ()
sts = sys$waitfr(BCK_ACTIVATE);
if (EVEN(sts)) lib$signal(sts); /* BUG */
#else
while(1)
pause();
while(1) {
qcom_WaitAnd(&sts, &my_q, &qcom_cQini, ini_mEvent_terminate, qcom_cTmoEternal);
// pause();
exit(0);
}
#endif
/* We were activated from the outer world. Trigger */
......
......@@ -9,6 +9,9 @@
#include "twolist.h"
#include "rt_aproc.h"
#include "rt_pwr_msg.h"
#include "rt_ini_event.h"
#include "rt_qcom.h"
#include "rt_qcom_msg.h"
#define Log_Error(a, b) errh_Error("%s\n%m",b, a)
#define Log(b) errh_Info(b)
......@@ -46,7 +49,9 @@ int
main ()
{
pwr_tUInt32 sts;
pwr_tObjid oid;
pwr_tObjid oid;
qcom_sQid my_q = qcom_cNQid;
qcom_sGet get;
pwr_tBoolean firstTime = TRUE;
pwr_tUInt32 nrOfEvents = 0;
......@@ -62,6 +67,19 @@ main ()
If_Error_Log_Exit(sts, "gdh_Init");
Init();
/* Create queue for receival of events */
if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) {
errh_Fatal("qcom_CreateQ, %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(sts);
}
if (!qcom_Bind(&sts, &my_q, &qcom_cQini)) {
errh_Fatal("qcom_Bind(Qini), %m", sts);
errh_SetStatus( PWR__APPLTERM);
exit(-1);
}
oid.vid = lHelCB.Nid;
oid.oix = pwr_cNVolumeId;
......@@ -91,6 +109,23 @@ main ()
Log_Error(sts, "mh_OutunitReceive");
Store(&firstTime, &nrOfEvents, &nrOfKeys);
get.data = NULL;
qcom_Get(&sts, &my_q, &get, 0);
if (sts != QCOM__TMO && sts != QCOM__QEMPTY) {
if (get.type.b == qcom_eBtype_event) {
qcom_sEvent *ep = (qcom_sEvent*) get.data;
ini_mEvent new_event;
if (get.type.s == qcom_cIini) {
new_event.m = ep->mask;
if (new_event.b.terminate) {
errh_SetStatus( PWR__APPLTERM);
exit(0);
}
}
}
qcom_Free(&sts, get.data);
}
aproc_TimeStamp();
}
}
......
#ifndef rt_dsfast_h
#define rt_dsfast_h
using namespace std;
#include <string.h>
#include <vector>
extern "C" {
......
......@@ -1855,6 +1855,29 @@ ini_ProcStart (
errh_LogError(&cp->log, "Error starting %s, %m", pp->id, *sts);
}
void
ini_ProcPrio (
pwr_tStatus *status,
ini_sContext *cp,
ini_sProc *pp
)
{
char set[100];
pwr_dStatus(sts, status, INI__SUCCESS);
if (pp->flags.b.running)
return;
if (pp->flags.b.run) {
#if defined(OS_LINUX)
sprintf(set, "rt_prio -rp %d %d", pp->proc.p_prio, pp->proc.pid);
system(set);
#endif
}
}
void
ini_ProcIter (
pwr_tStatus *status,
......
......@@ -182,6 +182,7 @@ void ini_ProcIter (pwr_tStatus*, ini_sContext*, int,
void (*func) (pwr_tStatus*, ini_sContext*, ini_sProc*));
void ini_ProcLoad (pwr_tStatus*, ini_sContext*, ini_sProc*);
void ini_ProcStart (pwr_tStatus*, ini_sContext*, ini_sProc*);
void ini_ProcPrio (pwr_tStatus*, ini_sContext*, ini_sProc*);
void ini_ProcTable (pwr_tStatus*, ini_sContext*);
void ini_ProcWait (pwr_tStatus*, ini_sContext*);
pwr_tBoolean ini_RebuildNode (pwr_tStatus*, ini_sContext*);
......
......@@ -182,6 +182,7 @@ start (
ini_ProcTable(&sts, cp);
ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcLoad);
ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcStart);
ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcPrio);
net_Connect(&sts, &gdbroot->my_aid, &gdbroot->my_qid, NULL, "pwr_ini");
/*if (!qcom_Init(&sts, 0)) {*/
......@@ -435,7 +436,38 @@ terminate (
qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_oldPlcStop);
qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, ini_mEvent_oldPlcStopDone, qcom_cTmoEternal);
return sts;
qcom_Exit(NULL);
/* Kill programs which until now doesn't handle qcom */
/*
for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; pp = lst_Succ(NULL, pl, &pl)) {
if (strncmp("pwr_webmonmh", pp->proc.name, 12) == 0) {
kill(pp->proc.pid, SIGKILL);
}
else if (strncmp("pwr_webmon", pp->proc.name, 10) == 0) {
kill(pp->proc.pid, SIGKILL);
}
}
*/
/* Now sleep for a while */
sleep(2);
/* Unlink shared memory and semaphores */
gdb_UnlinkDb();
qdb_UnlinkDb();
/* Destroy message handler semaphore */
mh_UtilDestroyEvent();
#if defined(OS_LINUX)
/* Unlink errlog mwessage queue */
errl_Unlink();
#endif
exit(1);
}
static int
......@@ -904,7 +936,7 @@ static void ini_errl_cb( void *userdata, char *str, char severity, pwr_tStatus s
if ( anix == 0 || !cp->np) return;
if ( anix >= sizeof(cp->np->ProcStatus)/sizeof(cp->np->ProcStatus[0])) {
printf ( "Init: undefind anix %d\n", anix);
printf ( "Init: undefined anix %d\n", anix);
return;
}
......
......@@ -29,8 +29,9 @@
#include "rt_subc.h"
#include "rt_net.h"
#include "rt_pwr_msg.h"
#include "rt_ini_event.h"
static void event (qcom_sGet *get);
static void init(qcom_sQid *qid);
static void lockMountServers(gdb_sNode *np);
static gdb_sNode *node(net_sMessage *mp);
......@@ -126,6 +127,12 @@ init (
}
*myQid = qcom_cQnacp;
if (!qcom_Bind(&sts, myQid, &qcom_cQini)) {
errh_Fatal("qcom_Bind, %m", sts);
errh_SetStatus( PWR__SRVTERM);
exit(-1);
}
/* Activate all subscriptions that were requested before we started! */
gdb_ScopeLock {
......@@ -158,7 +165,12 @@ receive (
continue;
}
if (get->type.b != net_cMsgClass) {
if (get->type.b == qcom_eBtype_event) {
event(get);
qcom_Free(&sts, mp);
}
else if (get->type.b != net_cMsgClass) {
errh_Error("Received bad message, type: <%d>, subtype: <%d>", get->type.b, get->type.s);
qcom_Free(&sts, mp);
continue;
......@@ -168,6 +180,23 @@ receive (
}
}
static void
event (
qcom_sGet *get
)
{
qcom_sEvent *ep = (qcom_sEvent*) get->data;
ini_mEvent new_event;
if (get->type.s != qcom_cIini)
return;
new_event.m = ep->mask;
if (new_event.b.terminate) {
exit(0);
}
}
/* Check message node identity and return pointer to node. */
static gdb_sNode *
......
......@@ -316,6 +316,9 @@ main (int argc, char *argv[])
qcom_sQid qid = qdb_cQexport;
qcom_sQid neth_qid;
qcom_sQid my_q = qcom_cNQid;
/* Vnta en stund ... */
// sleep(5);
errh_Init("pwr_qmon", errh_eAnix_qmon);
errh_SetStatus( PWR__SRVSTARTUP);
......@@ -394,9 +397,9 @@ main (int argc, char *argv[])
errh_SetStatus( PWR__SRUN);
qcom_WaitAnd(&sts, &my_q, &qcom_cQini, ini_mEvent_terminate, qcom_cTmoEternal);
// qcom_WaitAnd(&sts, &my_q, &qcom_cQini, ini_mEvent_terminate, qcom_cTmoEternal);
// sts = thread_Wait(NULL); /* Wait forever */
sts = thread_Wait(NULL); /* Wait forever */
errh_SetStatus( PWR__SRVTERM);
errh_Info("pwr_qmon says: I will soon die, %m", sts);
......
......@@ -132,7 +132,7 @@ int main (
qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInitDone);
qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcStart, qcom_cTmoEternal);
proc_SetPriority(pp->PlcProcess->Prio);
// proc_SetPriority(pp->PlcProcess->Prio);
set_values(pp);
start_threads(pp);
time_Uptime(&sts, &pp->PlcProcess->StartTime, NULL);
......
......@@ -129,6 +129,7 @@ public class GdhServer
GdhServer gdhServer = new GdhServer();
gdhServer.openServerSocket();
System.out.println("GdhServer exiting");
System.exit(0);
}
......@@ -206,11 +207,12 @@ public class GdhServer
try
{
serverSocket = new ServerSocket(PORT);
serverSocket.setSoTimeout(1000);
}
catch(IOException e)
{
errh.fatal("Could not listen on port " + PORT);
System.exit(1);
return;
}
gdh = new Gdh((Object)null);
......@@ -225,7 +227,16 @@ public class GdhServer
}
errh.setStatus( Errh.PWR__SRUN);
Qcom qcom = new Qcom();
QcomrCreateQ qque = qcom.createIniEventQ("GdhServer");
if(qque.evenSts())
{
System.out.println("Gdhser");
errh.fatal("GdhSever couldn create EventQue");
return;
}
QcomrGetIniEvent qrGetIniEv;
while(true)
{
Socket cliSocket = null;
......@@ -235,10 +246,28 @@ public class GdhServer
cliSocket = serverSocket.accept();
}
catch(InterruptedIOException e)
{
qrGetIniEv = qcom.getIniEvent(qque.qix, qque.nid, 0);
if(qrGetIniEv.timeout)
continue;
else if(qrGetIniEv.terminate)
{
System.out.println("GdhServer received killmess from QCom");
return;
}
else
{
//Do nothing for the moment
//But in the future we should reinitialize if swap
continue;
}
}
catch(IOException e)
{
errh.error("Accept failed.");
// System.exit(1);
continue;
}
if(threadCount <= maxConnections)
......
......@@ -69,7 +69,18 @@ public class MhServer
MhServer mhServer = new MhServer();
mhServer.openServerSocket();
for(int i=0;i < mhServer.mhThread.length;i++)
{
mhServer.mhThread[i] = null;
}
try{
mhServer.finalize();
}
catch(Throwable e) {
}
mhServer = null;
System.out.println("MhServer exiting");
System.exit(0);
}
......@@ -131,6 +142,7 @@ public class MhServer
cdhrMaxAlarms = gdh.getObjectInfoInt(maxAlarmsAttr);
cdhrMaxEvents = gdh.getObjectInfoInt(maxEventsAttr);
cdhrMaxCon = gdh.getObjectInfoInt(maxConAttr);
System.out.println( "MaxNoOfAlarms: " + cdhrStringUser.str + " " + cdhrMaxAlarms.value + " " + cdhrMaxAlarms.evenSts());
if(cdhrMaxCon.evenSts())
{
return cdhrMaxCon.getSts();
......@@ -184,7 +196,9 @@ public class MhServer
try
{
serverSocket = new ServerSocket(PORT);
serverSocket.setSoTimeout(1000);
}
catch(IOException e)
{
System.out.println("IOException i openServerSocket");
......@@ -217,13 +231,25 @@ public class MhServer
errh.setStatus( Errh.PWR__SRVTERM);
return;
}
MhSendThread mhSendThread = new MhSendThread(mh);
errh.setStatus( Errh.PWR__SRUN);
Qcom qcom = new Qcom();
QcomrCreateQ qque = qcom.createIniEventQ("MhServer");
if(qque.evenSts())
{
System.out.println("MH:Error during qreateque");
errh.fatal("MH:Error during qcom.createIniEventQ");
return;
}
QcomrGetIniEvent qrGetIniEv;
while(keepRunning)
{
Socket cliSocket = null;
......@@ -235,11 +261,33 @@ public class MhServer
}
cliSocket = serverSocket.accept();
}
catch(InterruptedIOException e)
{
qrGetIniEv = qcom.getIniEvent(qque.qix, qque.nid, 0);
if(qrGetIniEv.timeout)
{
//do nothing
continue;
}
else if(qrGetIniEv.terminate)
{
//Time to die
System.out.println("MhServer received killmess from QCom");
return;
}
else
{
//All other messages is qurrently ignored
//But perhaps we should reinitialize when we get
//swapdone
continue;
}
}
catch(IOException e)
{
errh.error("Accept failed.");
// System.exit(1);
continue;
}
if(log)
......
......@@ -21,6 +21,8 @@ public class Qcom {
}
public native QcomrCreateQ createQ( int qix, int nid, String name);
public native QcomrCreateQ createIniEventQ(String name);
public native QcomrGetIniEvent getIniEvent(int qix, int nid, int timeoutTime);
private native PwrtStatus putString( int qix, int nid, String data);
public native CdhrString getString( int qix, int nid);
}
......@@ -16,6 +16,7 @@ local_java_sources = \
CliTable.java \
Cli.java \
QcomrCreateQ.java \
QcomrGetIniEvent.java \
Qcom.java \
Errh.java \
RtUtilities.java \
......
......@@ -29,6 +29,7 @@ static mqd_t mqid = (mqd_t)-1;
static int logFile = -1;
static int newLogFile = 1;
static int term = -1;
static pthread_t tid = 0;
static int yday = -1;
static pwr_tBoolean logToStdout = FALSE;
static void (*errl_log_cb)( void *, char *, char, pwr_tStatus, int, int) = 0;
......@@ -46,7 +47,6 @@ errl_Init (
)
{
pthread_mutexattr_t mutexattr;
pthread_t tid;
pthread_attr_t pthreadattr;
struct mq_attr mqattr;
mode_t mode;
......@@ -115,6 +115,19 @@ errl_Init (
return;
}
void
errl_Unlink ()
{
char name[64];
char *busid = getenv(pwr_dEnvBusId);
pthread_cancel(tid);
sprintf(name, "%s_%s", LOG_QUEUE_NAME, busid ? busid : "");
/* We don't care about return status */
mq_unlink(name);
}
void
errl_SetFile (
const char *logFileName)
{
......
......@@ -65,18 +65,24 @@ proc_SetPriority (
int prio
)
{
struct sched_param param;
int rc;
// struct sched_param param;
// int rc;
int pid;
char set[100];
pwr_tStatus sts = PROC__SUCCESS;
rc = sched_getparam((pid_t)0, &param);
if (rc != 0)
return errno_GetStatus();
param.sched_priority = prio;
rc = sched_setscheduler((pid_t)0, SCHED_RR, &param);
if (rc != 0)
return errno_GetStatus();
return sts;
pid = getpid();
// rc = sched_getparam((pid_t)0, &param);
// if (rc != 0)
// return errno_GetStatus();
// param.sched_priority = prio;
// rc = sched_setscheduler((pid_t)0, SCHED_RR, &param);
// if (rc != 0)
// return errno_GetStatus();
sprintf(set, "rt_prio -rp %d %d", prio, pid);
// system(set);
return sts;
}
pwr_tStatus
......
......@@ -37,7 +37,6 @@ qos_WaitQue (
{
pwr_tDeltaTime dtime;
sigset_t newset;
sigset_t oldset;
siginfo_t info;
int ok;
pwr_tBoolean signal = FALSE;
......@@ -52,7 +51,6 @@ qos_WaitQue (
sigemptyset(&newset);
sigaddset(&newset, qdb_cSigMsg);
sigprocmask(SIG_BLOCK, &newset, &oldset);
// qp->lock.pid = BUILDPID(getpid(), pthread_self());
// I think that each thread has it's own pid in Linux. ML
......@@ -87,7 +85,6 @@ qos_WaitQue (
signal = TRUE;
}
sigprocmask(SIG_SETMASK, &oldset, NULL);
return signal;
}
......
......@@ -48,7 +48,7 @@ sem_t *posix_sem_open(const char *name, int oflag, ...)
return(sem_t*)-1;
}
close(fd);
key = ftok(name, 0);
key = ftok(name, 'P');
if (key < 0) {
return(sem_t*)-1;
}
......@@ -198,7 +198,7 @@ int posix_sem_trywait(sem_t *sem)
int posix_sem_unlink(const char *name)
{
int key, semid;
key = ftok(name, 0);
key = ftok(name, 'P');
if (key < 0) {
return -1;
}
......
......@@ -29,4 +29,8 @@ void errl_Init (const char *termname,
void errl_SetTerm (const char *termname);
void errl_SetFile (const char *filename);
#if defined OS_LINUX
void errl_Unlink ();
#endif
#endif
......@@ -20,6 +20,9 @@
#elif defined(OS_LINUX)
# include <sys/file.h>
# include <sys/stat.h>
# include <sys/ipc.h>
# include <sys/shm.h>
# include "rt_semaphore.h"
#endif
#include "pwr.h"
......@@ -244,6 +247,9 @@ unlinkPool(
int fd;
int flags = O_RDWR;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
key_t key;
int shm_id;
struct shmid_ds ds;
char *str = getenv(pwr_dEnvBusId);
char segname[128];
......@@ -266,11 +272,15 @@ unlinkPool(
#if defined OS_LYNX
shm_unlink(segname);
#else
key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660);
shmctl(shm_id, IPC_RMID, &ds);
unlink(segname);
#endif
for (i = 1; TRUE; i++) {
sprintf(segname, "%s%04d_%.3s", name, i, busid);
sprintf(segname, "%.11s%04d_%.3s", name, i, busid);
#if defined OS_LYNX
fd = shm_open(segname, flags, mode);
#else
......@@ -285,6 +295,10 @@ unlinkPool(
#if defined OS_LYNX
shm_unlink(segname);
#else
key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660);
shmctl(shm_id, IPC_RMID, &ds);
unlink(segname);
#endif
......@@ -796,6 +810,47 @@ gdb_CreateDb (
return gdbroot;
}
/* This routine unlinks the object and node database and
removes database lock.
It should only be called by the init program. */
void
gdb_UnlinkDb ()
{
char segname[128];
char busid[8];
char *str = getenv(pwr_dEnvBusId);
key_t key;
int shm_id;
struct shmid_ds ds;
#if defined OS_LYNX || defined OS_LINUX
/* Unlink pool. */
unlinkPool(gdb_cNamePool);
unlinkPool(gdb_cNameRtdb);
/* Remove database lock. */
strncpy(busid, (str ? str : "XXX"), 3);
busid[3] = '\0';
sprintf(segname, "%s_%.3s", gdb_cNameDbLock, busid);
#if defined OS_LYNX
shm_unlink(segname);
#else
key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660);
shmctl(shm_id, IPC_RMID, &ds);
posix_sem_unlink(segname);
unlink(segname);
#endif
#endif
}
/* Allocate an object header and initiate
the global part of the header. */
......
......@@ -1190,6 +1190,10 @@ gdb_CreateDb (
gdb_sInit *ip
);
void
gdb_UnlinkDb (
);
gdb_sObject *
gdb_LoadObject (
pwr_tStatus *sts,
......
......@@ -8,6 +8,11 @@
This include file defines the global datastructures and
data entities in GDH. Also, the GDH entry points are defined. */
#if defined __cplusplus
extern "C" {
#endif
/**
*@example gdh_examples.c
*/
......@@ -619,4 +624,7 @@ gdh_SetCache (
/** @} */
/** @} */
#if defined __cplusplus
}
#endif
#endif
......@@ -528,6 +528,7 @@ qcom_Init (
FUNCTION_DESCRIPTOR f_dsc;
#elif defined OS_LINUX || defined OS_LYNX
struct sigaction sa;
sigset_t ss;
#endif
pwr_dStatus (sts, status, QCOM__SUCCESS);
......@@ -597,6 +598,9 @@ qcom_Init (
sigemptyset(&sa.sa_mask);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigemptyset(&ss);
sigaddset(&ss, qdb_cSigMsg);
sigprocmask(SIG_BLOCK, &ss, NULL);
#elif defined OS_VMS
atexit(exitHandler);
......
......@@ -20,6 +20,17 @@
# include <signal.h>
#endif
#if defined (OS_LYNX)
# include <sys/mman.h>
#elif defined(OS_LINUX)
# include <sys/file.h>
# include <sys/stat.h>
# include <sys/ipc.h>
# include <sys/shm.h>
# include "rt_semaphore.h"
#endif
#include <errno.h>
#include "pwr.h"
#include "co_time.h"
......@@ -737,6 +748,116 @@ qdb_CreateDb (
return qdb;
}
#if defined OS_LYNX || defined OS_LINUX
/*
* A fix which unlinks all segments for the given name.
*/
static void
unlinkPool(
const char *name
){
int i;
int fd;
int flags = O_RDWR;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
key_t key;
int shm_id;
struct shmid_ds ds;
char *str = getenv(pwr_dEnvBusId);
char segname[128];
char busid[8];
strncpy(busid, (str ? str : "XXX"), 3);
busid[3] = '\0';
sprintf(segname, "%s_%.3s", name, busid);
#if defined OS_LYNX
fd = shm_open(segname, flags, mode);
#else
fd = open(segname, flags, mode);
#endif
if (fd != -1) {
close(fd);
#if defined OS_LYNX
shm_unlink(segname);
#else
key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660);
shmctl(shm_id, IPC_RMID, &ds);
unlink(segname);
#endif
for (i = 1; TRUE; i++) {
sprintf(segname, "%.11s%04d_%.3s", name, i, busid);
#if defined OS_LYNX
fd = shm_open(segname, flags, mode);
#else
fd = open(segname, flags, mode);
#endif
if (fd == -1)
break;
close(fd);
#if defined OS_LYNX
shm_unlink(segname);
#else
key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660);
shmctl(shm_id, IPC_RMID, &ds);
unlink(segname);
#endif
}
}
}
#endif
/* This routine unlinks QCOM database and
removes database lock.
It should only be called by the init program. */
void
qdb_UnlinkDb ()
{
char segname[128];
char busid[8];
char *str = getenv(pwr_dEnvBusId);
key_t key;
int shm_id;
struct shmid_ds ds;
#if defined OS_LYNX || defined OS_LINUX
/* Unlink pool. */
unlinkPool(qdb_cNamePool);
/* Remove database lock. */
strncpy(busid, (str ? str : "XXX"), 3);
busid[3] = '\0';
sprintf(segname, "%s_%.3s", qdb_cNameDbLock, busid);
#if defined OS_LYNX
shm_unlink(segname);
#else
key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660);
shmctl(shm_id, IPC_RMID, &ds);
posix_sem_unlink(segname);
unlink(segname);
#endif
#endif
}
qdb_sLocal *
qdb_MapDb (
pwr_tStatus *status
......
......@@ -728,6 +728,7 @@ qdb_sBuffer* qdb_CopyBuffer (pwr_tStatus*, qdb_sBuffer*);
void* qdb_CopyBufferData (pwr_tStatus*, qdb_sBuffer*, qcom_sGet*);
qdb_sBuffer* qdb_DetachBuffer (pwr_tStatus*, qdb_sBuffer*);
qdb_sLocal* qdb_CreateDb (pwr_tStatus*, qdb_sInit*);
void qdb_UnlinkDb ();
qdb_sQlock* qdb_CreateQlock (pwr_tStatus*, qdb_sQue*);
void qdb_DeleteQlock (pwr_tStatus*, qdb_sQue*);
qdb_sBuffer* qdb_Deque (pwr_tStatus*, qdb_sQue*, int);
......
......@@ -575,7 +575,7 @@ thread_SetPrio (
return ERRNO__SUCCESS;
}
#elif defined OS_LINUX || defined OS_LYNX
#elif defined OS_LYNX
{
struct sched_param par;
pthread_t id;
......@@ -590,6 +590,29 @@ thread_SetPrio (
return errno_Status(pthread_setschedparam(id, SCHED_FIFO, &par));
}
#elif defined OS_LINUX
{
int pid, policy;
pthread_t tid;
char set[100];
struct sched_param par;
pwr_tStatus sts = THREAD__SUCCESS;
/* Set priority and scheduling mechanism for thread. */
/* -f equals SCHED_FIFO */
pid = getpid();
tid = pthread_self();
prio = MIN(sched_get_priority_max(SCHED_FIFO),
sched_get_priority_min(SCHED_FIFO) + prio);
// sprintf(set, "/home/rk8584/sched/nptlrt -fp %i %i", prio, tid);
// system(set);
par.sched_priority = prio;
pthread_setschedparam(tid, SCHED_FIFO, &par);
pthread_getschedparam(tid, &policy, &par);
errh_Info("My policy: %s, prio: %d" , policy != SCHED_OTHER ? "RT" : "OTHER", par.sched_priority);
return sts;
}
#else
# error Not defined for this platform !
#endif
......
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