在 COBOL 中調用 CORBA 服務

2009-01-01

使用以下工具與平台:

  • 作業系統: Linux
  • COBOL 編譯器: OpenCOBOL
  • 範例程式: JobRequestClient.cob.
  • CORBA: Mico
  • COBOL 擴充模組 C 編譯器: gcc

範例 CORBA 服務有 3 個功能, 分別是:

  1. 取得 CORBA服務器主機之日期時間.
  2. 取得 CORBA服務器主機之系統識別.
  3. 取得 CORBA服務器主機之效能報告.
  4. 在此萬用架構下, 當然可以提供更多系統服務功能.

以下是 範例程式 JobRequestClient.cob 內容:

000010*>
000020 IDENTIFICATION DIVISION.
000030 PROGRAM-ID.   JobRequestClient.
000040 ENVIRONMENT    DIVISION.
000050 CONFIGURATION  SECTION.
000060 DATA DIVISION.
000070 WORKING-STORAGE SECTION.
000071 01 BIND-ADDR.
000072     10 URI PIC X(32).
000073     10 FILLER PIC X VALUE X’00’.
000075 01 CALL-PARAM.
000076     10 JOB-ID USAGE BINARY-LONG.
000078     10 JOB-PARAM PIC X(32).
000079 01 CALL-RTN.
000080     10 JOB-RTN-NUM USAGE BINARY-LONG.
000082     10 JOB-RTN PIC X(8192).
000086
000092 PROCEDURE DIVISION.
000102   ACCEPT URI FROM COMMAND-LINE.
000103
000111   CALL “OpenJobService_COBOL" USING
000112       BY REFERENCE BIND-ADDR
000113       BY REFERENCE JOB-RTN
000114       BY VALUE FUNCTION LENGTH(JOB-RTN)
000115       RETURNING JOB-RTN-NUM.
000116
000118   IF JOB-RTN-NUM < 1 THEN
000119      PERFORM SHOW-RTN
000120      STOP RUN
000121   END-IF.
000122
000123   PERFORM GET-TIME.
000124   PERFORM GET-SYS-INFO.
000130   PERFORM GET-VMSTAT.
000133
000134   CALL “CloseJobService" RETURNING JOB-RTN-NUM.
000135
000136   STOP RUN.
000138 GET-TIME.
000139   MOVE 0 TO JOB-ID.
000140   MOVE X’00’ TO JOB-PARAM.
000141
000142   CALL “DoJobService_COBOL" USING
000143       BY VALUE JOB-ID
000144       BY REFERENCE JOB-PARAM
000145       BY REFERENCE JOB-RTN
000146       BY VALUE FUNCTION LENGTH(JOB-RTN)
000147       RETURNING JOB-RTN-NUM.
000148
000150   PERFORM SHOW-RTN.
000151
000152 GET-SYS-INFO.
000153   MOVE 1 TO JOB-ID.
000154   MOVE X’00’ TO JOB-PARAM.
000155
000156   CALL “DoJobService_COBOL" USING
000157       BY VALUE JOB-ID
000158       BY REFERENCE JOB-PARAM
000159       BY REFERENCE JOB-RTN
000160       BY VALUE FUNCTION LENGTH(JOB-RTN)
000161       RETURNING JOB-RTN-NUM.
000162
000164   PERFORM SHOW-RTN.
000165
000166 GET-VMSTAT.
000167   MOVE 2 TO JOB-ID.
000168   MOVE X’00’ TO JOB-PARAM.
000169
000170   CALL “DoJobService_COBOL" USING
000171       BY VALUE JOB-ID
000172       BY REFERENCE JOB-PARAM
000173       BY REFERENCE JOB-RTN
000174       BY VALUE FUNCTION LENGTH(JOB-RTN)
000175       RETURNING JOB-RTN-NUM.
000176
000178   PERFORM SHOW-RTN.
000179
000180 SHOW-RTN.
000181   CALL “DISPLAY" USING
000182       BY VALUE JOB-RTN-NUM
000183       BY REFERENCE JOB-RTN
000184       BY VALUE FUNCTION LENGTH(JOB-RTN).
000185
000190 END PROGRAM JobRequestClient.

其中以下是 CORBA 請求端介面:

  • OpenJobService_COBOL
  • DoJobService_COBOL
  • CloseJobService

其中以下是 COBOL 擴充函數:

  • DISPLAY

執行輸出如下:

2009-05-17 00:49:53

Linux power 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux

procs ———–memory———- —swap– —–io—- -system– —-cpu—-
r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa
3  0      0 898508 697296 1552224    0    0    11    17  106  376  4  1 95  0

廣告
%d 位部落客按了讚: