Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1270381
  • 博文数量: 287
  • 博客积分: 11000
  • 博客等级: 上将
  • 技术积分: 3833
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-16 08:43
文章分类
文章存档

2013年(15)

2012年(17)

2011年(17)

2010年(135)

2009年(85)

2008年(18)

分类: 系统运维

2010-06-04 16:19:30

Register Activation Group Exit Procedure Here's a message that I posted to the iSeries Network RPG forum back in May. It was in reply to someone who wanted to run procedures when a service program was activated or deactivated (much like a constructor/destructor in OO languages.) As far as I know, there's no way to run a procedure during the activation phase. Here's how I approach the problem: I have a subprocedure that gets called first by every exported subprocedure. I use a global field to determine if it's been called before, and if so, it does not run again. I also tend to register a cleanup procedure with CEE4RAGE. Though, ending the activation group should theoretically clean everything up for me, I like to do it explicitly. I like to be in control! :) The following code should help illustrate what I'm talking about: H NOMAIN D Initialized s 1N inz(*off) *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Initialization routine *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P InzSrvPgm B D InzSrvPgm PI D CEE4RAGE PR D procedure * procptr const D feedback 12A options(*omit) /free if (Initialized); return; endif; // .. open files here ... // .. other initializations ... CEE4RAGE(%paddr(EndSrvPgm): *OMIT); Initialized = *ON; return; /end-free P e *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * EndSrvPgm(): This is called automatically when the activation * group ends. (which is when the srvpgm is removed * from memory.) * * Note that this must be exported so that CEE4RAGE can call it. * * InzSrvPgm() registers this procedure with the CEE4RAGE() API *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P EndSrvPgm B export D EndSrvPgm PI D AgMark 10U 0 options(*nopass) D Reason 10U 0 options(*nopass) D Result 10U 0 options(*nopass) D UserRC 10U 0 options(*nopass) /free // ... terminate any helper processes // ... shut down any persistent APIs // ... close files. // ... deallocate memory. Initialized = *OFF; return; /end-free P E *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Every exported procedure (besides EndSrvPgm) starts by calling * the InzSrvPgm() subprocedure *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P SomeProc B export D SomeProc PI 10I 0 D SomeParm 123A const /free InzSrvPgm(); // ... perform function of subproc here ... return data; /end-free P E *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Every exported procedure (besides EndSrvPgm) starts by calling * the InzSrvPgm() subprocedure *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P AnotherProc B export D AnotherProc PI 10I 0 D AnotherParm 321A const /free InzSrvPgm(); // ... perform function of subproc here ... return data; /end-free P E Thanks to Scott Klement
阅读(718) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~