ExtrSvcs-SERVICEStructure.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="SERVICE_Structure" role="nobrk">
  5. <title>SERVICE Structure<indexterm>
  6. <primary>SERVICE Structure</primary>
  7. </indexterm></title>
  8. <para><emphasis>servicename </emphasis><emphasis role="bold">:= SERVICE [ :
  9. </emphasis><emphasis>defaultkeywords</emphasis><emphasis role="bold">
  10. ]</emphasis><emphasis role="bold"> </emphasis><emphasis></emphasis></para>
  11. <para><emphasis> prototype </emphasis>:
  12. <emphasis>keywordlist</emphasis>;<emphasis role="bold"> </emphasis></para>
  13. <para><emphasis role="bold">END;</emphasis></para>
  14. <para><informaltable colsep="1" frame="all" rowsep="1">
  15. <tgroup cols="2">
  16. <colspec colwidth="85.30pt" />
  17. <colspec />
  18. <tbody>
  19. <row>
  20. <entry><emphasis>servicename</emphasis></entry>
  21. <entry>The name of the service the SERVICE structure
  22. provides.</entry>
  23. </row>
  24. <row>
  25. <entry><emphasis>defaultkeywords</emphasis></entry>
  26. <entry>Optional. A comma-delimited list of default keywords and
  27. their values shared by all prototypes in the external
  28. service.</entry>
  29. </row>
  30. <row>
  31. <entry><emphasis>prototype</emphasis></entry>
  32. <entry>The ECL name and prototype of a specific function.</entry>
  33. </row>
  34. <row>
  35. <entry><emphasis>keywordlist</emphasis></entry>
  36. <entry>A comma-delimited list of keywords and their values that
  37. tell the ECL compiler how to access the external service.</entry>
  38. </row>
  39. </tbody>
  40. </tgroup>
  41. </informaltable></para>
  42. <para>The <emphasis role="bold">SERVICE </emphasis>structure makes it
  43. possible to create external services to extend the capabilities of ECL to
  44. perform any desired functionality. These external system services are
  45. implemented as exported functions in a .SO (Shared Object). An ECL system
  46. service .SO can contain one or more services and (possibly) a single .SO
  47. initialization routine.</para>
  48. <para>Example:</para>
  49. <programlisting> email := SERVICE
  50. simpleSend( STRING address,
  51. STRING template,
  52. STRING subject) : LIBRARY='ecl2cw',
  53. INITFUNCTION='initEcl2Cw';
  54. END;
  55. MyAttr := COUNT(Trades): FAILURE(email.simpleSend('help@ln_risk.com',
  56. 'FailTemplate',
  57. 'COUNT failure'));
  58. //An example of a SERVICE function returning a structured record
  59. NameRecord := RECORD
  60. STRING5 title;
  61. STRING20 fname;
  62. STRING20 mname;
  63. STRING20 lname;
  64. STRING5 name_suffix;
  65. STRING3 name_score;
  66. END;
  67. LocalAddrCleanLib := SERVICE
  68. NameRecord dt(CONST STRING name, CONST STRING server = 'x')
  69. : c,entrypoint='aclCleanPerson73',pure;
  70. END;
  71. MyRecord := RECORD
  72. UNSIGNED id;
  73. STRING uncleanedName;
  74. NameRecord Name;
  75. END;
  76. x := DATASET('x', MyRecord, THOR);
  77. myRecord t(myRecord L) := TRANSFORM
  78. SELF.Name := LocalAddrCleanLib.dt(L.uncleanedName);
  79. SELF := L;
  80. END;
  81. y := PROJECT(x, t(LEFT));
  82. OUTPUT(y);
  83. //The following two examples define the same functions:
  84. TestServices1 := SERVICE
  85. member(CONST STRING src)
  86. : holertl,library='test',entrypoint='member',ctxmethod;
  87. takesContext1(CONST STRING src)
  88. : holertl,library='test',entrypoint='takesContext1',context;
  89. takesContext2()
  90. : holertl,library='test',entrypoint='takesContext2',context;
  91. STRING takesContext3()
  92. : holertl,library='test',entrypoint='takesContext3',context;
  93. END;
  94. //this form demonstrates the use of default keywords
  95. TestServices2 := SERVICE : holert,library='test'
  96. member(CONST STRING src) : entrypoint='member',ctxmethod;
  97. takesContext1(CONST STRING src) : entrypoint='takesContext1',context;
  98. takesContext2() : entrypoint='takesContext2',context;
  99. STRING takesContext3() : entrypoint='takesContext3',context;
  100. END;
  101. </programlisting>
  102. <para>See Also: <link linkend="External_Service_Implementation">External Service Implementation</link>, <link linkend="CONST">CONST</link></para>
  103. </sect1>