Commit 89b450a6 authored by claes's avatar claes

Check if database lock is stolen added

parent 5b257ddb
......@@ -97,4 +97,6 @@
080222 cs wb Check that volumeid is in valid range added to directory volume save.
080226 cs wb Popupmenu in palette wasn't implemented in gtk version.
080304 cs wb Plc with GetXp or StoXp references to objects in other volumes caused compilation errors.
080318 cs wb Bugfix in cast. Internal references wasn't updated correctly.
\ No newline at end of file
080318 cs wb Bugfix in cast. Internal references wasn't updated correctly.
080403 cs wb New command 'print/pdf/all' to print all plcpgm's to pdf-files. Also a html file with links to the files is written.
080407 cs wb Stolen database lock detected and save inhibited.
\ No newline at end of file
/*
* Proview $Id: wb_dblock.cpp,v 1.3 2005-09-06 10:43:31 claes Exp $
* Proview $Id: wb_dblock.cpp,v 1.4 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -37,6 +37,17 @@ char *wb_dblock::lockname( char *name)
return fname;
}
char *wb_dblock::lockvname( char *fname)
{
static pwr_tFileName vname;
char *s;
strcpy( vname, fname);
if ( (s = strrchr( vname, '.')))
*s = 0;
return vname;
}
bool wb_dblock::is_locked( char *name, char *user)
{
struct stat info;
......@@ -63,18 +74,40 @@ void wb_dblock::dblock( char *name)
fp << "Unknown" << endl;
fp.close();
wb_lockfile lf( lockname( name));
dcli_file_time( lockname( name), &lf.date);
m_lockfiles.push_back(lf);
}
bool wb_dblock::check( char *name)
{
pwr_tTime t;
for ( int i = 0; i < (int) m_lockfiles.size(); i++) {
if ( strcmp( m_lockfiles[i].fname, lockname(name)) == 0) {
if ( EVEN( dcli_file_time( lockname( name), &t)))
return false;
if (m_lockfiles[i].date.tv_sec == t.tv_sec)
return true;
}
}
return false;
}
void wb_dblock::dbunlock( char *name)
{
pwr_tCmd cmd;
sprintf( cmd, "rm %s", lockname(name));
system( cmd);
for ( int i = 0; i < (int) m_lockfiles.size(); i++) {
if ( strcmp( m_lockfiles[i].fname, lockname(name)) == 0) {
m_lockfiles[i].removed = true;
if ( check( name)) {
system( cmd);
m_lockfiles[i].removed = true;
}
break;
}
}
......@@ -85,8 +118,10 @@ void wb_dblock::dbunlock_all()
pwr_tCmd cmd;
for ( int i = 0; i < (int) m_lockfiles.size(); i++) {
if ( !m_lockfiles[i].removed) {
sprintf( cmd, "rm %s", m_lockfiles[i].fname);
system( cmd);
if ( check( lockvname( m_lockfiles[i].fname))) {
sprintf( cmd, "rm %s", m_lockfiles[i].fname);
system( cmd);
}
}
}
m_lockfiles.clear();
......
/*
* Proview $Id: wb_dblock.h,v 1.3 2005-09-06 10:43:31 claes Exp $
* Proview $Id: wb_dblock.h,v 1.4 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -28,6 +28,7 @@ class wb_lockfile
wb_lockfile( char *name) : removed(false)
{ strcpy( fname, name); }
pwr_tFileName fname;
pwr_tTime date;
bool removed;
};
......@@ -37,12 +38,14 @@ class wb_dblock
static vector<wb_lockfile> m_lockfiles;
static char *lockname( char *name);
static char *lockvname( char *fname);
public:
static bool is_locked( char *name, char *user = 0);
static void dblock( char *name);
static void dbunlock( char *name);
static void dbunlock_all();
static bool check( char *name);
};
#endif
/*
* Proview $Id: wb_erep.cpp,v 1.55 2008-02-05 14:53:12 claes Exp $
* Proview $Id: wb_erep.cpp,v 1.56 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelösund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -1186,3 +1186,21 @@ void wb_erep::resetRefMerep()
vrepref->setMerep( m_merep);
}
bool wb_erep::check_lock( char *name, ldh_eVolDb type)
{
char vname[200];
sprintf( vname, "$pwrp_db/%s", cdh_Low(name));
switch ( type) {
case ldh_eVolDb_Db:
strcat( vname, ".db");
break;
case ldh_eVolDb_Dbms:
strcat( vname, ".dbms");
break;
default:
return true;
}
dcli_translate_filename( vname, vname);
return wb_dblock::check(vname);
}
/*
* Proview $Id: wb_erep.h,v 1.25 2008-02-04 13:34:49 claes Exp $
* Proview $Id: wb_erep.h,v 1.26 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -96,6 +96,7 @@ public:
void resetRefMerep();
bool refMerepOccupied() { return m_ref_merep_occupied;}
void printMethods();
bool check_lock( char *name, ldh_eVolDb type);
static void volumeNameToFilename( pwr_tStatus *sts, char *name, char *filename);
......
/*
* Proview $Id: wb_foe.cpp,v 1.7 2007-12-21 13:18:01 claes Exp $
* Proview $Id: wb_foe.cpp,v 1.8 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -131,9 +131,12 @@ void WFoe::activate_save()
message( "Window saved");
else if ( sts == VLDH__PLCNOTSAVED )
msgbox( "UNABLE TO SAVE \nSave the plcprogram in the hierarchy editor first.");
else if (EVEN(sts))
message( "ERROR COULDN'T SAVE WINDOW");
else if (EVEN(sts)) {
char msg[256];
msg_GetMsg( sts, msg, sizeof(msg));
msgbox( msg);
}
}
// Callback from the menu.
......@@ -1239,8 +1242,11 @@ void WFoe::exit_save( WFoe *foe)
foe->msgbox( "Save the plcprogram in the hierarchy editor first");
return;
}
if (EVEN(sts)) {
foe->message( "ERROR COULDN'T SAVE WINDOW");
else if (EVEN(sts)) {
char msg[256];
msg_GetMsg( sts, msg, sizeof(msg));
foe->msgbox( msg);
return;
}
foe->foe_exit();
......@@ -3604,8 +3610,11 @@ void WFoe::edit_exit_save( WFoe *foe)
foe->enable_ldh_cb();
return;
}
if (EVEN(sts)) {
foe->message( "ERROR COULDN'T SAVE WINDOW");
else if (EVEN(sts)) {
char msg[256];
msg_GetMsg( sts, msg, sizeof(msg));
foe->msgbox( msg);
foe->enable_ldh_cb();
return;
}
......
/*
* Proview $Id: wb_gre.cpp,v 1.7 2007-11-22 08:50:55 claes Exp $
* Proview $Id: wb_gre.cpp,v 1.8 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -2196,7 +2196,7 @@ int WGre::print_pdf_rectangle( float ll_x, float ll_y, float ur_x, float ur_y,
cdh_ToLower( filename, filename);
}
else {
sprintf( filename, "$pwrp_tmp/pssdoc%s.pdf", file_id);
sprintf( filename, "$pwrp_doc/pssdoc%s.pdf", file_id);
}
dcli_translate_filename( filename, filename);
printf( "Export pdf to %s\n", filename);
......
/*
* Proview $Id: wb_ldh.h,v 1.44 2008-02-04 13:34:49 claes Exp $
* Proview $Id: wb_ldh.h,v 1.45 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -102,6 +102,12 @@ typedef enum {
ldh_eVolRep_Ced
} ldh_eVolRep;
typedef enum {
ldh_eVolDb__ = 0,
ldh_eVolDb_Db,
ldh_eVolDb_Dbms
} ldh_eVolDb;
typedef enum {
ldh_eAccess__ = 0,
ldh_eAccess_ReadOnly,
......
/*
* Proview $Id: wb_session.cpp,v 1.26 2008-03-19 07:31:09 claes Exp $
* Proview $Id: wb_session.cpp,v 1.27 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelösund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -1010,6 +1010,12 @@ bool wb_session::disableAttribute( pwr_sAttrRef *arp, pwr_tDisableAttr disable)
bool wb_session::commit()
{
if ( !m_vrep->erep()->check_lock( (char *)m_vrep->name(), m_vrep->dbtype())) {
m_sts = LDH__LOCKSTOLEN;
return false;
}
// Store time in volume object
pwr_tOid oid = pwr_cNOid;
pwr_tTime time;
......
/*
* Proview $Id: wb_utl.cpp,v 1.8 2008-02-04 13:34:49 claes Exp $
* Proview $Id: wb_utl.cpp,v 1.9 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -605,6 +605,22 @@ static int crr_crossref(
);
static bool is_focodeobject( ldh_tSesContext ldhses,
pwr_tCid cid)
{
pwr_sGraphPlcNode *graphbody;
pwr_tCid bodyclass;
pwr_tStatus sts;
int size;
sts = ldh_GetClassBody( ldhses, cid, "GraphPlcNode", &bodyclass,
(char **)&graphbody, &size);
if ( EVEN(sts)) return false;
if ( graphbody->compmethod == 58)
return true;
return false;
}
/*************************************************************************
......@@ -629,7 +645,8 @@ int wb_utl::print_plc(
ldh_tWBContext ldhwb,
char *plcstring,
int document,
int overview
int overview,
int pdf
)
{
int sts;
......@@ -648,7 +665,7 @@ int wb_utl::print_plc(
/* Print the plc */
printf( "Plcpgm %s\n", plcstring);
sts = print_document( plc, ldhses, ldhwb, document, overview);
sts = print_document( plc, ldhses, ldhwb, document, overview, pdf, 0);
return sts;
}
......@@ -675,7 +692,8 @@ int wb_utl::print_plc_hier (
char *fromname,
int document,
int overview,
int all
int all,
int pdf
)
{
int sts, size;
......@@ -689,6 +707,7 @@ int wb_utl::print_plc_hier (
pwr_tObjid fromobjdid;
int from;
int from_found;
FILE *plclink;
/* Get class */
class_vect[0] = pwr_cClass_plc;
......@@ -714,6 +733,32 @@ int wb_utl::print_plc_hier (
else
from = 0;
if ( pdf && all && !from) {
// Open a html file with links to pdf files
pwr_tFileName fname = "$pwrp_tmp/plc.html";
ldh_sSessInfo info;
pwr_tObjName vname;
sts = ldh_GetSessionInfo( ldhses, &info);
if ( EVEN(sts)) return sts;
sts = ldh_VolumeIdToName( ldh_SessionToWB(ldhses), info.Vid, vname, sizeof(vname), &size);
if ( EVEN(sts)) return sts;
sprintf( fname, "$pwrp_doc/plcdoc_%s.html", cdh_Low( vname));
dcli_translate_filename( fname, fname);
plclink = fopen( fname, "w");
fprintf( plclink, "<html>\n <head>\n <title>Plc code</title>\n <style type=\"text/css\">\n\
h2 {font-family: sans-serif; font-size: 16pt; font-weight: bold; color: #5263aa; text-align: left; text-decoration: none;}\n\
a:link {font-family: sans-serif; font-size: 11pt; font-weight: bold; color: #5263aa; text-align: left; text-decoration: none;}\n\
a:visited {font-family: sans-serif; font-size: 11pt; font-weight: bold; color: #5263aa; text-align: left; text-decoration: none;}\n\
a:hover {font-family: sans-serif; font-size: 11pt; font-weight: bold; color: #3561ff; text-align: left; text-decoration: none;}\n\
</style>\n </head>\n <body>\n");
fprintf( plclink, " <h2>Plc Documentation Volume %s</h2>\n", vname);
}
plcpgmcount = 0;
plcpgmlist = 0;
sts = trv_get_objects_hier_class_name( ldhses, hierobjdid, classp, NULL,
......@@ -743,13 +788,18 @@ int wb_utl::print_plc_hier (
printf( "Plcpgm %s\n", plcname);
sts = print_document( list_ptr->objid,
ldhses, ldhwb, document, overview);
ldhses, ldhwb, document, overview, pdf, plclink);
if ( EVEN(sts)) return sts;
list_ptr = list_ptr->next;
}
utl_objidlist_free( plcpgmlist);
if ( plclink) {
fprintf( plclink, " </body>\n</html>\n");
fclose( plclink);
}
return FOE__SUCCESS;
}
......@@ -776,7 +826,9 @@ int wb_utl::print_document (
ldh_tSesContext ldhses,
ldh_tWBContext ldhwb,
unsigned long document,
unsigned long overview
unsigned long overview,
int pdf,
FILE *plclink
)
{
int sts, size;
......@@ -817,21 +869,40 @@ int wb_utl::print_document (
&foe, 0, ldh_eAccess_ReadOnly);
if ( EVEN(sts)) return sts;
if ( document) {
/* Print the documents */
sts = foe->print_document();
if ( pdf) {
sts = foe->print_pdf_overview();
if ( EVEN(sts)) return sts;
if ( plclink) {
pwr_tOName name;
pwr_tOid w;
sts = ldh_ObjidToName( ldhses, plc, ldh_eName_Hierarchy,
name, sizeof( name), &size);
if ( ODD(sts))
sts = ldh_GetChild( ldhses, plc, &w);
if ( ODD(sts))
fprintf( plclink, "<a target=\"_blank\" href=\"pssdoc%s.pdf\">%s</a><br>\n", vldh_IdToStr( 0, w), name);
}
}
else {
if ( document) {
/* Print the documents */
sts = foe->print_document();
if ( EVEN(sts)) return sts;
}
if ( overview) {
sts = foe->print_overview();
if ( EVEN(sts)) return sts;
if ( overview) {
sts = foe->print_overview();
if ( EVEN(sts)) return sts;
}
}
windlist_ptr = windlist;
windlist_ptr++;
for ( j = 1; j < (int) wind_count; j++) {
/* Get parent in ldh and find him in vldh */
sts = ldh_GetParent( ldhses, *windlist_ptr, &nodeobjdid);
if ( EVEN(sts)) return sts;
......@@ -840,6 +911,27 @@ int wb_utl::print_document (
sts = ldh_GetParent( ldhses, nodeobjdid, &parwindobjdid);
if ( EVEN(sts)) return sts;
/* Don't print FoCode objects */
pwr_tCid cid;
pwr_tOid p = nodeobjdid;
bool next = false;
sts = ldh_GetObjectClass( ldhses, p, &cid);
while ( cid != pwr_cClass_plc) {
if ( is_focodeobject( ldhses, cid)) {
next = true;
break;
}
sts = ldh_GetParent( ldhses, p, &p);
if ( EVEN(sts)) break;
sts = ldh_GetObjectClass( ldhses, p, &cid);
if ( EVEN(sts)) break;
}
if ( next) {
windlist_ptr++;
continue;
}
sts = vldh_get_wind_objdid( parwindobjdid, &parentwind);
if ( EVEN(sts)) return sts;
......@@ -865,14 +957,47 @@ int wb_utl::print_document (
ldh_eAccess_ReadOnly, foe_eFuncAccess_Edit);
/* Print the documents */
if ( document) {
sts = foe->print_document();
if ( pdf) {
sts = foe->print_pdf_overview();
if ( EVEN(sts)) return sts;
if ( plclink) {
pwr_tOName name;
pwr_tOid w, p;
int indent;
pwr_tCid cid = 0;
p = node->ln.oid;
for ( indent = 0; cid != pwr_cClass_plc; indent++) {
sts = ldh_GetParent( ldhses, p, &p);
if ( EVEN(sts)) break;
sts = ldh_GetObjectClass( ldhses, p, &cid);
if ( EVEN(sts)) break;
}
indent = indent/2;
sts = ldh_ObjidToName( ldhses, node->ln.oid, ldh_eName_Object,
name, sizeof( name), &size);
if ( ODD(sts))
sts = ldh_GetChild( ldhses, node->ln.oid, &w);
if ( ODD(sts)) {
for ( int i = 0; i < indent; i++)
fprintf( plclink, "&nbsp;&nbsp;&nbsp;");
fprintf( plclink, "&nbsp;<a target=\"_blank\" href=\"pssdoc%s.pdf\">%s</a><br>\n", vldh_IdToStr( 0, w), name);
}
}
}
else {
if ( document) {
sts = foe->print_document();
if ( EVEN(sts)) return sts;
}
if ( overview) {
sts = foe->print_overview();
if ( EVEN(sts)) return sts;
if ( overview) {
sts = foe->print_overview();
if ( EVEN(sts)) return sts;
}
}
windlist_ptr++;
......@@ -882,7 +1007,7 @@ int wb_utl::print_document (
for ( j = 0; j < (int)wind_count; j++) {
windlist_ptr--;
sts = vldh_get_wind_objdid( *windlist_ptr, &parentwind);
if ( EVEN(sts)) return sts;
if ( EVEN(sts)) continue;
((WFoe *)parentwind->hw.foe)->quit();
}
......
/*
* Proview $Id: wb_utl.h,v 1.10 2007-10-15 12:15:04 claes Exp $
* Proview $Id: wb_utl.h,v 1.11 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -17,6 +17,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdio.h>
#ifndef wb_utl_h
#define wb_utl_h
......@@ -44,10 +46,10 @@ class wb_utl {
int map_window, ldh_eAccess access,
foe_eFuncAccess function_access) {return 0;}
int print_plc( ldh_tSesContext ldhses, ldh_tWBContext ldhwb,
char *plcstring, int document, int overview);
char *plcstring, int document, int overview, int pdf);
int print_plc_hier( ldh_tSesContext ldhses, ldh_tWBContext ldhwb,
char *hiername, char *fromname, int document,
int overview, int all);
int overview, int all, int pdf);
int redraw_plc( ldh_tSesContext ldhses, ldh_tWBContext ldhwb,
char *plcstring);
int redraw_plc_hier( ldh_tSesContext ldhses,
......@@ -55,7 +57,7 @@ class wb_utl {
char *fromname, int all);
int print_document( pwr_tOid Objdid, ldh_tSesContext ldhses,
ldh_tWBContext ldhwb, unsigned long document,
unsigned long overview);
unsigned long overview, int pdf, FILE *plclink);
int redraw_windows( pwr_tObjid Objdid, ldh_tSesContext ldhses,
ldh_tWBContext ldhwb);
};
......
/*
* Proview $Id: wb_vrep.h,v 1.29 2007-12-21 13:18:01 claes Exp $
* Proview $Id: wb_vrep.h,v 1.30 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -63,6 +63,7 @@ public:
virtual wb_vrep *ref() = 0;
virtual ldh_eVolRep type() const = 0;
virtual ldh_eVolDb dbtype() { return ldh_eVolDb__;}
virtual wb_erep *erep() = 0;
virtual wb_vrep *next() = 0;
......
/*
* Proview $Id: wb_vrepced.h,v 1.3 2007-12-21 13:18:01 claes Exp $
* Proview $Id: wb_vrepced.h,v 1.4 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -53,6 +53,7 @@ public:
~wb_vrepced();
virtual ldh_eVolRep type() const { return ldh_eVolRep_Ced;}
virtual ldh_eVolDb dbtype() { return m_vrep->dbtype();}
pwr_tVid vid() const { return m_vid;}
pwr_tCid cid() const { return m_cid;}
......
/*
* Proview $Id: wb_vrepdb.h,v 1.38 2007-12-21 13:18:01 claes Exp $
* Proview $Id: wb_vrepdb.h,v 1.39 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -98,6 +98,7 @@ public:
virtual wb_vrep *ref();
virtual ldh_eVolRep type() const { return ldh_eVolRep_Db;}
virtual ldh_eVolDb dbtype() { return ldh_eVolDb_Db;}
virtual wb_erep *erep();
virtual wb_merep *merep() const;
......
/*
* Proview $Id: wb_vrepdbms.h,v 1.6 2008-02-04 13:34:49 claes Exp $
* Proview $Id: wb_vrepdbms.h,v 1.7 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2007 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -99,6 +99,7 @@ public:
virtual wb_vrep *ref();
virtual ldh_eVolRep type() const { return ldh_eVolRep_Dbms;}
virtual ldh_eVolDb dbtype() { return ldh_eVolDb_Dbms;}
virtual wb_erep *erep();
virtual wb_merep *merep() const;
......
/*
* Proview $Id: wb_wtt.cpp,v 1.37 2008-02-27 06:35:43 claes Exp $
* Proview $Id: wb_wtt.cpp,v 1.38 2008-04-07 14:53:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -410,6 +410,11 @@ void Wtt::save_cb( void *ctx)
sts = ldh_SaveSession( wtt->ldhses);
if ( EVEN(sts)) {
wtt->message( 'E', wnav_get_message( sts));
if ( !wtt->focused_wnav)
wtt->set_focus_default();
wtt->focused_wnav->wow->DisplayError( "Save Error", wnav_get_message(sts));
return;
}
......@@ -549,6 +554,15 @@ void Wtt::close_ok( Wtt *wtt)
// Save and close ldh session
sts = wtt->set_noedit( wtt_eNoEdit_Save, wtt_eNoEdit_DetachVolume);
if ( EVEN(sts)) {
wtt->message( 'E', wnav_get_message( sts));
if ( !wtt->focused_wnav)
wtt->set_focus_default();
wtt->focused_wnav->wow->DisplayError( "Save Error", wnav_get_message(sts));
return;
}
delete wtt;
}
......@@ -665,14 +679,14 @@ int Wtt::set_noedit( wtt_eNoEditMode save, wtt_eNoEditVolMode detach)
sts = ldh_RevertSession( ldhses);
if ( EVEN(sts)) {
message( 'E', wnav_get_message( sts));
return 0;
return sts;
}
}
if ( detach == wtt_eNoEdit_KeepVolume) {
sts = ldh_CloseSession( ldhses);
if ( EVEN(sts)) {
message( 'E', wnav_get_message( sts));
return 0;
return sts;
}
sts = ldh_OpenSession (
......
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