/docs/yolk.lyx

http://github.com/ThomasLocke/yolk · Unknown · 7590 lines · 5787 code · 1803 blank · 0 comment · 0 complexity · 8005ac7db6ca7f09b6666c4d96179f72 MD5 · raw file

Large files are truncated click here to view the full file

  1. #LyX 2.0 created this file. For more info see http://www.lyx.org/
  2. \lyxformat 413
  3. \begin_document
  4. \begin_header
  5. \textclass article
  6. \use_default_options true
  7. \maintain_unincluded_children false
  8. \language english
  9. \language_package default
  10. \inputencoding auto
  11. \fontencoding global
  12. \font_roman default
  13. \font_sans helvet
  14. \font_typewriter default
  15. \font_default_family sfdefault
  16. \use_non_tex_fonts false
  17. \font_sc false
  18. \font_osf false
  19. \font_sf_scale 100
  20. \font_tt_scale 100
  21. \graphics default
  22. \default_output_format default
  23. \output_sync 0
  24. \bibtex_command default
  25. \index_command default
  26. \paperfontsize 12
  27. \spacing single
  28. \use_hyperref false
  29. \papersize a4paper
  30. \use_geometry true
  31. \use_amsmath 1
  32. \use_esint 1
  33. \use_mhchem 1
  34. \use_mathdots 1
  35. \cite_engine basic
  36. \use_bibtopic false
  37. \use_indices false
  38. \paperorientation portrait
  39. \suppress_date false
  40. \use_refstyle 0
  41. \index Index
  42. \shortcut idx
  43. \color #008000
  44. \end_index
  45. \leftmargin 2cm
  46. \topmargin 2cm
  47. \rightmargin 2cm
  48. \bottommargin 2cm
  49. \secnumdepth 3
  50. \tocdepth 3
  51. \paragraph_separation skip
  52. \defskip medskip
  53. \quotes_language english
  54. \papercolumns 1
  55. \papersides 1
  56. \paperpagestyle default
  57. \tracking_changes false
  58. \output_changes false
  59. \html_math_output 0
  60. \html_css_as_file 0
  61. \html_be_strict false
  62. \end_header
  63. \begin_body
  64. \begin_layout Title
  65. Yolk Manual
  66. \end_layout
  67. \begin_layout Date
  68. Revised December 11th.
  69. 2012
  70. \end_layout
  71. \begin_layout Standard
  72. \begin_inset Newpage newpage
  73. \end_inset
  74. \end_layout
  75. \begin_layout Standard
  76. \begin_inset CommandInset toc
  77. LatexCommand tableofcontents
  78. \end_inset
  79. \end_layout
  80. \begin_layout Standard
  81. \begin_inset Newpage newpage
  82. \end_inset
  83. \end_layout
  84. \begin_layout Part
  85. General Information
  86. \end_layout
  87. \begin_layout Section
  88. Copyright and License
  89. \end_layout
  90. \begin_layout Standard
  91. This document is copyright (C) 2010-, Thomas ¸cke.
  92. You may copy this document, in whole or in part, in any form or by any
  93. means, as is or with alterations, provided that (1) alterations are clearly
  94. marked as alterations and (2) this copyright notice is included unmodified
  95. in any copy.
  96. \end_layout
  97. \begin_layout Standard
  98. Yolk is GPLv3 software.
  99. You should have received a copy of the GNU General Public License and a
  100. copy of the GCC Runtime Library Exception along with this program; see
  101. the files COPYING3 and COPYING.RUNTIME respectively.
  102. If not, see
  103. \begin_inset CommandInset href
  104. LatexCommand href
  105. name "http://www.gnu.org/licenses/"
  106. target "http://www.gnu.org/licenses/"
  107. \end_inset
  108. .
  109. \end_layout
  110. \begin_layout Section
  111. What is Yolk?
  112. \end_layout
  113. \begin_layout Standard
  114. Yolk is a collection of packages that aim to help build solid web-applications
  115. using Ada.
  116. Yolk itself doesn't do a whole lot that can't be accomplished simply by
  117. using
  118. \begin_inset CommandInset href
  119. LatexCommand href
  120. name "AWS"
  121. target "http://libre.adacore.com/libre/tools/aws/"
  122. \end_inset
  123. and the
  124. \begin_inset CommandInset href
  125. LatexCommand href
  126. name "GNAT Component Collection (GNATcoll)"
  127. target "http://libre.adacore.com/libre/tools/gnat-component-collection/"
  128. \end_inset
  129. , but it does make the job of building complete web-applications a bit simpler.
  130. Things like changing user for the running application, catching POSIX signals
  131. such as SIGKILL, sending log data to syslogd, adding basic static content
  132. handlers, creating and starting/stopping an AWS powered HTTP server and
  133. building Atom syndication XML are all made a bit easier with Yolk.
  134. \end_layout
  135. \begin_layout Standard
  136. A Yolk application is in reality an AWS application, with some sugar added,
  137. so you're not really building a Yolk web-application, as much as you're
  138. building an AWS web-application.
  139. What I'm getting at, is that you need to understand how to use AWS, in
  140. order for Yolk to make any kind of sense.
  141. What you get when using Yolk is the little things that AWS does not readily
  142. provide.
  143. \end_layout
  144. \begin_layout Subsection
  145. The Yolk demo application
  146. \end_layout
  147. \begin_layout Standard
  148. Reading this manual will of course (I hope!) help you understand how to
  149. use Yolk, but please consider taking a closer look at the Yolk demo application
  150. to get a feel for how Yolk is actually used.
  151. The demo is heavily commented, so it should be fairly easy to understand
  152. what's going on.
  153. The demo application is also very suitable as a foundation for other AWS/Yolk
  154. applications.
  155. \end_layout
  156. \begin_layout Standard
  157. It is much easier to show how to use Yolk, than it is to write down all
  158. possible usage scenarios.
  159. With the combination of this manual, the Yolk source files and the demo
  160. application, you should be able to make full use of the Yolk packages in
  161. your own applications.
  162. \end_layout
  163. \begin_layout Subsection
  164. The source code
  165. \end_layout
  166. \begin_layout Standard
  167. The Yolk source code is the best documentation there is.
  168. This document is never going to be as comprehensive as the actual source,
  169. so I'll strongly suggest having the source code available as you read this
  170. document.
  171. What you will find in this document are short descriptions of what a package
  172. is meant to do and perhaps small usage examples, not a complete rundown
  173. of every type and procedure in a package.
  174. \end_layout
  175. \begin_layout Subsection
  176. Building and installing Yolk
  177. \end_layout
  178. \begin_layout Standard
  179. See the README and INSTALL files.
  180. These are found in the Yolk root directory.
  181. \end_layout
  182. \begin_layout Subsection
  183. The files Yolk depend upon
  184. \end_layout
  185. \begin_layout Standard
  186. When you read this document and the Yolk source code, you'll notice that
  187. quite a few packages depend on various files being available at specified
  188. locations.
  189. This is for example the case with the
  190. \emph on
  191. Yolk.Whoops
  192. \emph default
  193. package that expects its template file to be found at the path
  194. \emph on
  195. templates/system/500.tmpl
  196. \end_layout
  197. \begin_layout Standard
  198. All such
  199. \begin_inset Quotes eld
  200. \end_inset
  201. dependencies
  202. \begin_inset Quotes erd
  203. \end_inset
  204. will of course be noted accordingly as we go along, but instead of forgetting
  205. one or more in your own application, I'd much rather encourage using the
  206. demo application as a foundation for your own applications, since all these
  207. fixed paths and files has been properly added to the demo.
  208. \end_layout
  209. \begin_layout Standard
  210. I also recommend compiling and running the demo, to make sure your Yolk
  211. install is working as intended.
  212. Just read the
  213. \emph on
  214. demo/README
  215. \emph default
  216. and
  217. \emph on
  218. demo/INSTALL
  219. \emph default
  220. files for instructions on how to get it up and running.
  221. \end_layout
  222. \begin_layout Subsection
  223. The Yolk packages naming
  224. \end_layout
  225. \begin_layout Standard
  226. The Yolk packages are pretty diverse, ranging from process control to sending
  227. email.
  228. I've tried naming them as sensibly as possible, in the hope that the package
  229. names alone give away their function.
  230. If I've failed, well, you're just going to have to refer to this document
  231. or take a look at the source for yourself.
  232. \end_layout
  233. \begin_layout Standard
  234. \begin_inset Newpage newpage
  235. \end_inset
  236. \end_layout
  237. \begin_layout Part
  238. The Yolk Packages
  239. \end_layout
  240. \begin_layout Section
  241. Yolk
  242. \end_layout
  243. \begin_layout Standard
  244. The Yolk main package currently only contain only a few things: The Yolk
  245. \emph on
  246. Version
  247. \emph default
  248. string, a
  249. \emph on
  250. Config_File
  251. \emph default
  252. function to get the location of the configuration file and a
  253. \emph on
  254. PID_File
  255. \emph default
  256. function to get the location of the PID file.
  257. These are used in a few places, for example in the
  258. \emph on
  259. directory.tmpl
  260. \emph default
  261. template file (the version string), in the
  262. \emph on
  263. Yolk.Configuration
  264. \emph default
  265. package (the
  266. \emph on
  267. Config_File
  268. \emph default
  269. function) and in the
  270. \emph on
  271. Yolk.Process_Control
  272. \emph default
  273. package (the
  274. \emph on
  275. PID_File
  276. \emph default
  277. function).
  278. \end_layout
  279. \begin_layout Standard
  280. All Yolk applications accepts two commandline arguments:
  281. \end_layout
  282. \begin_layout Itemize
  283. \emph on
  284. --yolk-config-file
  285. \emph default
  286. : Defines the location of the configuration file.
  287. If empty or not set, then use the default location
  288. \emph on
  289. configuration/config.ini
  290. \emph default
  291. .
  292. \end_layout
  293. \begin_layout Itemize
  294. \emph on
  295. --pid-file
  296. \emph default
  297. : Defines the location of the PID file.
  298. If empty or not set, then don't write a PID file.
  299. Note that if you use the
  300. \emph on
  301. extras/rc.yolk
  302. \emph default
  303. script to control your application, then this is handled for you transparently.
  304. \end_layout
  305. \begin_layout Section
  306. Yolk.Cache.Discrete_Keys
  307. \end_layout
  308. \begin_layout Standard
  309. If a piece of data doesn't change very often and it is expensive to build,
  310. then caching it might be worthwhile.
  311. Instead of going to a file or database on every hit, you simply go to the
  312. cache and grab the latest version from there.
  313. This is
  314. \series bold
  315. \emph on
  316. very
  317. \series default
  318. \emph default
  319. fast, at the cost of some memory.
  320. \end_layout
  321. \begin_layout Standard
  322. If you know exactly what you want to cache, the
  323. \emph on
  324. Yolk.Cache.Discrete_Keys
  325. \emph default
  326. package might be just what you need.
  327. \end_layout
  328. \begin_layout Subsection
  329. The generic formal parameters
  330. \end_layout
  331. \begin_layout Standard
  332. These are:
  333. \end_layout
  334. \begin_layout Standard
  335. \begin_inset Box Frameless
  336. position "t"
  337. hor_pos "c"
  338. has_inner_box 1
  339. inner_pos "t"
  340. use_parbox 0
  341. use_makebox 0
  342. width "100col%"
  343. special "none"
  344. height "1in"
  345. height_special "totalheight"
  346. status open
  347. \begin_layout Plain Layout
  348. \begin_inset listings
  349. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  350. inline false
  351. status open
  352. \begin_layout Plain Layout
  353. generic
  354. \end_layout
  355. \begin_layout Plain Layout
  356. type Key_Type is (<>);
  357. \end_layout
  358. \begin_layout Plain Layout
  359. type Element_Type is private;
  360. \end_layout
  361. \begin_layout Plain Layout
  362. Max_Element_Age : Duration := 3600.0;
  363. \end_layout
  364. \begin_layout Plain Layout
  365. package Yolk.Cache.Discrete_Keys is
  366. \end_layout
  367. \begin_layout Plain Layout
  368. ...
  369. \end_layout
  370. \end_inset
  371. \end_layout
  372. \end_inset
  373. \end_layout
  374. \begin_layout Standard
  375. The
  376. \emph on
  377. Max_Element_Age
  378. \emph default
  379. defaults to one hour.
  380. You should obviously set this to whatever suits your needs.
  381. This timer is used for all content in the cache.
  382. You cannot set this individually for each element.
  383. \end_layout
  384. \begin_layout Subsection
  385. Instantiation
  386. \end_layout
  387. \begin_layout Standard
  388. If for example we have two different sets of data (Foo and Bar) that are
  389. expensive to build, we can instantiate a
  390. \emph on
  391. Discrete_Keys
  392. \emph default
  393. package to handle this:
  394. \end_layout
  395. \begin_layout Standard
  396. \begin_inset Box Frameless
  397. position "t"
  398. hor_pos "c"
  399. has_inner_box 1
  400. inner_pos "t"
  401. use_parbox 0
  402. use_makebox 0
  403. width "100col%"
  404. special "none"
  405. height "1in"
  406. height_special "totalheight"
  407. status open
  408. \begin_layout Plain Layout
  409. \begin_inset listings
  410. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  411. inline false
  412. status open
  413. \begin_layout Plain Layout
  414. type Cache_Keys is (Foo, Bar);
  415. \end_layout
  416. \begin_layout Plain Layout
  417. package My_Cache is new Yolk.Cache.Discrete_Keys
  418. \end_layout
  419. \begin_layout Plain Layout
  420. (Key_Type => Cache_Keys,
  421. \end_layout
  422. \begin_layout Plain Layout
  423. Element_Type => Unbounded_String);
  424. \end_layout
  425. \end_inset
  426. \end_layout
  427. \end_inset
  428. \end_layout
  429. \begin_layout Standard
  430. And that is all.
  431. We now have a
  432. \emph on
  433. My_Cache
  434. \emph default
  435. object that can hold two objects:
  436. \emph on
  437. Foo
  438. \emph default
  439. and
  440. \emph on
  441. Bar
  442. \emph default
  443. .
  444. These are of the type
  445. \emph on
  446. Unbounded_String
  447. \emph default
  448. and they have a
  449. \emph on
  450. Max_Element_Age
  451. \emph default
  452. of 3600.0 seconds.
  453. \end_layout
  454. \begin_layout Subsection
  455. Writing to the cache
  456. \end_layout
  457. \begin_layout Standard
  458. Before we can read something from the cache, we must first write something
  459. to it:
  460. \end_layout
  461. \begin_layout Standard
  462. \begin_inset Box Frameless
  463. position "t"
  464. hor_pos "c"
  465. has_inner_box 1
  466. inner_pos "t"
  467. use_parbox 0
  468. use_makebox 0
  469. width "100col%"
  470. special "none"
  471. height "1in"
  472. height_special "totalheight"
  473. status open
  474. \begin_layout Plain Layout
  475. \begin_inset listings
  476. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  477. inline false
  478. status open
  479. \begin_layout Plain Layout
  480. declare
  481. \end_layout
  482. \begin_layout Plain Layout
  483. Foo_Value : Unbounded_String := To_Unbounded_String ("Foo");
  484. \end_layout
  485. \begin_layout Plain Layout
  486. begin
  487. \end_layout
  488. \begin_layout Plain Layout
  489. My_Cache.Write (Key => Foo,
  490. \end_layout
  491. \begin_layout Plain Layout
  492. Value => Foo_Value);
  493. \end_layout
  494. \begin_layout Plain Layout
  495. end;
  496. \end_layout
  497. \end_inset
  498. \end_layout
  499. \end_inset
  500. \end_layout
  501. \begin_layout Standard
  502. That is all it takes:
  503. \begin_inset Quotes eld
  504. \end_inset
  505. Foo
  506. \begin_inset Quotes erd
  507. \end_inset
  508. is now safely tucked away in the
  509. \emph on
  510. My_Cache
  511. \emph default
  512. object, and will be so for 3600.0 seconds.
  513. Calling
  514. \emph on
  515. Write
  516. \emph default
  517. with the
  518. \emph on
  519. Foo
  520. \emph default
  521. key will always overwrite earlier written
  522. \emph on
  523. Foo
  524. \emph default
  525. elements, no matter their age.
  526. \end_layout
  527. \begin_layout Subsection
  528. Reading from the cache
  529. \end_layout
  530. \begin_layout Standard
  531. A cache obviously only makes sense if you intend to read from it.
  532. In our case we want to get our hands on the previously written
  533. \begin_inset Quotes eld
  534. \end_inset
  535. Foo
  536. \begin_inset Quotes erd
  537. \end_inset
  538. value:
  539. \end_layout
  540. \begin_layout Standard
  541. \begin_inset Box Frameless
  542. position "t"
  543. hor_pos "c"
  544. has_inner_box 1
  545. inner_pos "t"
  546. use_parbox 0
  547. use_makebox 0
  548. width "100col%"
  549. special "none"
  550. height "1in"
  551. height_special "totalheight"
  552. status open
  553. \begin_layout Plain Layout
  554. \begin_inset listings
  555. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  556. inline false
  557. status open
  558. \begin_layout Plain Layout
  559. declare
  560. \end_layout
  561. \begin_layout Plain Layout
  562. Valid : Boolean := False;
  563. \end_layout
  564. \begin_layout Plain Layout
  565. Value : Unbounded_String;
  566. \end_layout
  567. \begin_layout Plain Layout
  568. begin
  569. \end_layout
  570. \begin_layout Plain Layout
  571. My_Cache.Read (Key => Foo,
  572. \end_layout
  573. \begin_layout Plain Layout
  574. Is_Valid => Valid,
  575. \end_layout
  576. \begin_layout Plain Layout
  577. Value => Value);
  578. \end_layout
  579. \begin_layout Plain Layout
  580. if Valid then
  581. \end_layout
  582. \begin_layout Plain Layout
  583. -- do something interesting with the data
  584. \end_layout
  585. \begin_layout Plain Layout
  586. else
  587. \end_layout
  588. \begin_layout Plain Layout
  589. -- the Foo data is invalid.
  590. \end_layout
  591. \begin_layout Plain Layout
  592. end if;
  593. \end_layout
  594. \begin_layout Plain Layout
  595. end;
  596. \end_layout
  597. \end_inset
  598. \end_layout
  599. \end_inset
  600. \end_layout
  601. \begin_layout Standard
  602. In order for an element to be valid (the
  603. \emph on
  604. Is_Valid
  605. \emph default
  606. parameter is true), it must:
  607. \end_layout
  608. \begin_layout Enumerate
  609. have been added to the cache in the first place
  610. \end_layout
  611. \begin_layout Enumerate
  612. be younger than
  613. \emph on
  614. Max_Element_Age
  615. \end_layout
  616. \begin_layout Standard
  617. If
  618. \emph on
  619. Is_Valid
  620. \emph default
  621. is
  622. \emph on
  623. False
  624. \emph default
  625. , then
  626. \emph on
  627. Value
  628. \emph default
  629. is undefined.
  630. Note that if
  631. \emph on
  632. Is_Valid
  633. \emph default
  634. is
  635. \emph on
  636. False
  637. \emph default
  638. then
  639. \emph on
  640. Key
  641. \emph default
  642. is removed from the cache, if it exists.
  643. \end_layout
  644. \begin_layout Subsection
  645. Checking if a key is valid
  646. \end_layout
  647. \begin_layout Standard
  648. If you need to check whether a specific key exists in the cache and is valid,
  649. then you must use the
  650. \emph on
  651. Is_Valid
  652. \emph default
  653. function.
  654. \end_layout
  655. \begin_layout Standard
  656. \begin_inset Box Frameless
  657. position "t"
  658. hor_pos "c"
  659. has_inner_box 1
  660. inner_pos "t"
  661. use_parbox 0
  662. use_makebox 0
  663. width "100col%"
  664. special "none"
  665. height "1in"
  666. height_special "totalheight"
  667. status open
  668. \begin_layout Plain Layout
  669. \begin_inset listings
  670. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  671. inline false
  672. status open
  673. \begin_layout Plain Layout
  674. if My_Cache.Is_Valid (Foo) then
  675. \end_layout
  676. \begin_layout Plain Layout
  677. -- Foo is good!
  678. \end_layout
  679. \begin_layout Plain Layout
  680. else
  681. \end_layout
  682. \begin_layout Plain Layout
  683. -- Foo is bad!
  684. \end_layout
  685. \begin_layout Plain Layout
  686. end if;
  687. \end_layout
  688. \end_inset
  689. \end_layout
  690. \end_inset
  691. \end_layout
  692. \begin_layout Standard
  693. This follows the same rules as the
  694. \emph on
  695. Is_Valid
  696. \emph default
  697. parameter for the
  698. \emph on
  699. Read
  700. \emph default
  701. procedure.
  702. \end_layout
  703. \begin_layout Subsection
  704. Clearing keys and the entire cache
  705. \end_layout
  706. \begin_layout Standard
  707. For clearing of keys and the entire cache we have, naturally, two
  708. \emph on
  709. Clear
  710. \emph default
  711. procedures:
  712. \end_layout
  713. \begin_layout Standard
  714. \begin_inset Box Frameless
  715. position "t"
  716. hor_pos "c"
  717. has_inner_box 1
  718. inner_pos "t"
  719. use_parbox 0
  720. use_makebox 0
  721. width "100col%"
  722. special "none"
  723. height "1in"
  724. height_special "totalheight"
  725. status open
  726. \begin_layout Plain Layout
  727. \begin_inset listings
  728. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  729. inline false
  730. status open
  731. \begin_layout Plain Layout
  732. -- First we clear the Foo key
  733. \end_layout
  734. \begin_layout Plain Layout
  735. My_Cache.Clear (Key => Foo);
  736. \end_layout
  737. \begin_layout Plain Layout
  738. \end_layout
  739. \begin_layout Plain Layout
  740. -- And then we clear the entire cache
  741. \end_layout
  742. \begin_layout Plain Layout
  743. My_Cache.Clear;
  744. \end_layout
  745. \end_inset
  746. \end_layout
  747. \end_inset
  748. \end_layout
  749. \begin_layout Standard
  750. And that's all it takes.
  751. \end_layout
  752. \begin_layout Subsection
  753. Cleanup - Getting rid of stale elements
  754. \end_layout
  755. \begin_layout Standard
  756. Calling Cleanup will delete all stale elements from the cache:
  757. \end_layout
  758. \begin_layout Standard
  759. \begin_inset Box Frameless
  760. position "t"
  761. hor_pos "c"
  762. has_inner_box 1
  763. inner_pos "t"
  764. use_parbox 0
  765. use_makebox 0
  766. width "100col%"
  767. special "none"
  768. height "1in"
  769. height_special "totalheight"
  770. status open
  771. \begin_layout Plain Layout
  772. \begin_inset listings
  773. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  774. inline false
  775. status open
  776. \begin_layout Plain Layout
  777. My_Cache.Cleanup;
  778. \end_layout
  779. \end_inset
  780. \end_layout
  781. \end_inset
  782. \end_layout
  783. \begin_layout Standard
  784. Note that this is potentially a very expensive operation if the cache is
  785. large, as the entire cache is iterated and every element tested for its
  786. age.
  787. Use with care.
  788. \end_layout
  789. \begin_layout Section
  790. Yolk.Cache.String_Keys
  791. \end_layout
  792. \begin_layout Standard
  793. This package is almost similar to the
  794. \emph on
  795. Yolk.Cache.Discrete_Keys
  796. \emph default
  797. package.
  798. The biggest difference is that where the
  799. \emph on
  800. Discrete_Keys
  801. \emph default
  802. cache package requires that you define a type for the keys, this package
  803. use regular
  804. \emph on
  805. String
  806. \emph default
  807. as keys.
  808. \end_layout
  809. \begin_layout Standard
  810. The implications of this difference between the two cache packages are subtle.
  811. Both have the same
  812. \emph on
  813. Read
  814. \emph default
  815. ,
  816. \emph on
  817. Write
  818. \emph default
  819. ,
  820. \emph on
  821. Is_Valid
  822. \emph default
  823. and
  824. \emph on
  825. Clear
  826. \emph default
  827. procedures and functions, so in that sense the two packages are the same.
  828. The biggest difference lies in the available generic formal parameters
  829. and the functionality of the
  830. \emph on
  831. Cleanup
  832. \emph default
  833. procedure.
  834. \end_layout
  835. \begin_layout Subsection
  836. The generic formal parameters
  837. \end_layout
  838. \begin_layout Standard
  839. These are:
  840. \end_layout
  841. \begin_layout Standard
  842. \begin_inset Box Frameless
  843. position "t"
  844. hor_pos "c"
  845. has_inner_box 1
  846. inner_pos "t"
  847. use_parbox 0
  848. use_makebox 0
  849. width "100col%"
  850. special "none"
  851. height "1in"
  852. height_special "totalheight"
  853. status open
  854. \begin_layout Plain Layout
  855. \begin_inset listings
  856. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  857. inline false
  858. status open
  859. \begin_layout Plain Layout
  860. generic
  861. \end_layout
  862. \begin_layout Plain Layout
  863. type Element_Type is private;
  864. \end_layout
  865. \begin_layout Plain Layout
  866. Cleanup_Size : Positive := 200;
  867. \end_layout
  868. \begin_layout Plain Layout
  869. Cleanup_On_Write : Boolean := True;
  870. \end_layout
  871. \begin_layout Plain Layout
  872. Max_Element_Age : Duration := 3600.0;
  873. \end_layout
  874. \begin_layout Plain Layout
  875. Reserved_Capacity : Positive := 100;
  876. \end_layout
  877. \begin_layout Plain Layout
  878. package Yolk.Cache.Discrete_Keys is
  879. \end_layout
  880. \begin_layout Plain Layout
  881. ...
  882. \end_layout
  883. \end_inset
  884. \end_layout
  885. \end_inset
  886. \end_layout
  887. \begin_layout Standard
  888. When the amount of elements in the cache >=
  889. \emph on
  890. Cleanup_Size
  891. \emph default
  892. , then the
  893. \emph on
  894. Cleanup
  895. \emph default
  896. procedure is called by
  897. \emph on
  898. Write
  899. \emph default
  900. , if
  901. \emph on
  902. Cleanup_On_Write
  903. \emph default
  904. is set to Boolean
  905. \emph on
  906. True
  907. \emph default
  908. .
  909. \emph on
  910. Cleanup_Size
  911. \emph default
  912. is a sort of failsafe for this cache package.
  913. Since we can't know for sure what is being added (we don't know the keys
  914. beforehand), we need to make sure it doesn't gobble up all available resources.
  915. Set this number high enough that it'll never tricker under normal circumstances
  916. , but low enough that it'll prevent resource exhaustion in case of errors.
  917. \end_layout
  918. \begin_layout Standard
  919. The
  920. \emph on
  921. Max_Element_Age
  922. \emph default
  923. defaults to one hour.
  924. You should obviously set this to whatever suits your needs.
  925. This timer is used for all content in the cache.
  926. You cannot set this individually for each element.
  927. \end_layout
  928. \begin_layout Standard
  929. \emph on
  930. Reserved_Capacity
  931. \emph default
  932. should be set as close as possible to the expected final size of the cache.
  933. If your best guestimate is 200 elements in the cache, then set this to
  934. 200.
  935. Note that this setting has no bearing on the actual size of the cache.
  936. The cache will happily grow beyond the
  937. \emph on
  938. Reserved_Capacity
  939. \emph default
  940. value.
  941. \end_layout
  942. \begin_layout Subsection
  943. Instantiation
  944. \end_layout
  945. \begin_layout Standard
  946. Instantiating
  947. \emph on
  948. String_Keys
  949. \emph default
  950. is done like this:
  951. \end_layout
  952. \begin_layout Standard
  953. \begin_inset Box Frameless
  954. position "t"
  955. hor_pos "c"
  956. has_inner_box 1
  957. inner_pos "t"
  958. use_parbox 0
  959. use_makebox 0
  960. width "100col%"
  961. special "none"
  962. height "1in"
  963. height_special "totalheight"
  964. status open
  965. \begin_layout Plain Layout
  966. \begin_inset listings
  967. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  968. inline false
  969. status open
  970. \begin_layout Plain Layout
  971. package My_Cache is new Yolk.Cache.String_Keys
  972. \end_layout
  973. \begin_layout Plain Layout
  974. (Element_Type => Unbounded_String,
  975. \end_layout
  976. \begin_layout Plain Layout
  977. Reserved_Capacity => 200);
  978. \end_layout
  979. \end_inset
  980. \end_layout
  981. \end_inset
  982. \end_layout
  983. \begin_layout Standard
  984. And that is all.
  985. We now have a
  986. \emph on
  987. My_Cache
  988. \emph default
  989. object that can hold objects of the type
  990. \emph on
  991. Unbounded_String
  992. \emph default
  993. , all of which have a
  994. \emph on
  995. Max_Element_Age
  996. \emph default
  997. of 3600.0 seconds.
  998. Also we've told the cache to set aside at least 200 positions for content.
  999. \end_layout
  1000. \begin_layout Subsection
  1001. Writing to the cache
  1002. \end_layout
  1003. \begin_layout Standard
  1004. Before we can read something from the cache, we must first write something
  1005. to it:
  1006. \end_layout
  1007. \begin_layout Standard
  1008. \begin_inset Box Frameless
  1009. position "t"
  1010. hor_pos "c"
  1011. has_inner_box 1
  1012. inner_pos "t"
  1013. use_parbox 0
  1014. use_makebox 0
  1015. width "100col%"
  1016. special "none"
  1017. height "1in"
  1018. height_special "totalheight"
  1019. status open
  1020. \begin_layout Plain Layout
  1021. \begin_inset listings
  1022. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1023. inline false
  1024. status open
  1025. \begin_layout Plain Layout
  1026. declare
  1027. \end_layout
  1028. \begin_layout Plain Layout
  1029. Value : Unbounded_String := To_Unbounded_String ("42");
  1030. \end_layout
  1031. \begin_layout Plain Layout
  1032. begin
  1033. \end_layout
  1034. \begin_layout Plain Layout
  1035. My_Cache.Write (Key => "Foo",
  1036. \end_layout
  1037. \begin_layout Plain Layout
  1038. Value => Value);
  1039. \end_layout
  1040. \begin_layout Plain Layout
  1041. end;
  1042. \end_layout
  1043. \end_inset
  1044. \end_layout
  1045. \end_inset
  1046. \end_layout
  1047. \begin_layout Standard
  1048. \begin_inset Quotes eld
  1049. \end_inset
  1050. 42
  1051. \begin_inset Quotes erd
  1052. \end_inset
  1053. is now safely tucked away in the
  1054. \emph on
  1055. My_Cache
  1056. \emph default
  1057. object under the key
  1058. \begin_inset Quotes eld
  1059. \end_inset
  1060. Foo
  1061. \begin_inset Quotes erd
  1062. \end_inset
  1063. , and will be so for 3600.0 seconds.
  1064. Calling
  1065. \emph on
  1066. Write
  1067. \emph default
  1068. with the
  1069. \begin_inset Quotes eld
  1070. \end_inset
  1071. Foo
  1072. \begin_inset Quotes erd
  1073. \end_inset
  1074. \emph on
  1075. \emph default
  1076. String will always overwrite earlier written
  1077. \begin_inset Quotes eld
  1078. \end_inset
  1079. Foo
  1080. \begin_inset Quotes erd
  1081. \end_inset
  1082. elements, no matter their age.
  1083. \end_layout
  1084. \begin_layout Subsection
  1085. Reading from the cache
  1086. \end_layout
  1087. \begin_layout Standard
  1088. A cache obviously only makes sense if you intend to read from it.
  1089. In our case we want to get our hands on the previously written
  1090. \begin_inset Quotes eld
  1091. \end_inset
  1092. Foo
  1093. \begin_inset Quotes erd
  1094. \end_inset
  1095. value:
  1096. \end_layout
  1097. \begin_layout Standard
  1098. \begin_inset Box Frameless
  1099. position "t"
  1100. hor_pos "c"
  1101. has_inner_box 1
  1102. inner_pos "t"
  1103. use_parbox 0
  1104. use_makebox 0
  1105. width "100col%"
  1106. special "none"
  1107. height "1in"
  1108. height_special "totalheight"
  1109. status open
  1110. \begin_layout Plain Layout
  1111. \begin_inset listings
  1112. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1113. inline false
  1114. status open
  1115. \begin_layout Plain Layout
  1116. declare
  1117. \end_layout
  1118. \begin_layout Plain Layout
  1119. Valid : Boolean := False;
  1120. \end_layout
  1121. \begin_layout Plain Layout
  1122. Value : Unbounded_String;
  1123. \end_layout
  1124. \begin_layout Plain Layout
  1125. begin
  1126. \end_layout
  1127. \begin_layout Plain Layout
  1128. My_Cache.Read (Key => "Foo",
  1129. \end_layout
  1130. \begin_layout Plain Layout
  1131. Is_Valid => Valid,
  1132. \end_layout
  1133. \begin_layout Plain Layout
  1134. Value => Value);
  1135. \end_layout
  1136. \begin_layout Plain Layout
  1137. if Valid then
  1138. \end_layout
  1139. \begin_layout Plain Layout
  1140. -- do something interesting with the data
  1141. \end_layout
  1142. \begin_layout Plain Layout
  1143. else
  1144. \end_layout
  1145. \begin_layout Plain Layout
  1146. -- the Foo data is invalid.
  1147. \end_layout
  1148. \begin_layout Plain Layout
  1149. end if;
  1150. \end_layout
  1151. \begin_layout Plain Layout
  1152. end;
  1153. \end_layout
  1154. \end_inset
  1155. \end_layout
  1156. \end_inset
  1157. \end_layout
  1158. \begin_layout Standard
  1159. In order for an element to be valid (the
  1160. \emph on
  1161. Is_Valid
  1162. \emph default
  1163. parameter is true), it must:
  1164. \end_layout
  1165. \begin_layout Enumerate
  1166. have been added to the cache in the first place
  1167. \end_layout
  1168. \begin_layout Enumerate
  1169. be younger than
  1170. \emph on
  1171. Max_Element_Age
  1172. \end_layout
  1173. \begin_layout Standard
  1174. If
  1175. \emph on
  1176. Is_Valid
  1177. \emph default
  1178. is
  1179. \emph on
  1180. False
  1181. \emph default
  1182. , then
  1183. \emph on
  1184. Value
  1185. \emph default
  1186. contains undefined garbage.
  1187. Note that if
  1188. \emph on
  1189. Is_Valid
  1190. \emph default
  1191. is
  1192. \emph on
  1193. False
  1194. \emph default
  1195. then
  1196. \emph on
  1197. Key
  1198. \emph default
  1199. is removed from the cache, if it exists.
  1200. \end_layout
  1201. \begin_layout Subsection
  1202. Checking if a key is valid
  1203. \end_layout
  1204. \begin_layout Standard
  1205. If you need to check whether a specific key exists in the cache and is valid,
  1206. then you need to use the
  1207. \emph on
  1208. Is_Valid
  1209. \emph default
  1210. function.
  1211. \end_layout
  1212. \begin_layout Standard
  1213. \begin_inset Box Frameless
  1214. position "t"
  1215. hor_pos "c"
  1216. has_inner_box 1
  1217. inner_pos "t"
  1218. use_parbox 0
  1219. use_makebox 0
  1220. width "100col%"
  1221. special "none"
  1222. height "1in"
  1223. height_special "totalheight"
  1224. status open
  1225. \begin_layout Plain Layout
  1226. \begin_inset listings
  1227. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1228. inline false
  1229. status open
  1230. \begin_layout Plain Layout
  1231. if My_Cache.Is_Valid ("Foo") then
  1232. \end_layout
  1233. \begin_layout Plain Layout
  1234. -- Foo is good!
  1235. \end_layout
  1236. \begin_layout Plain Layout
  1237. else
  1238. \end_layout
  1239. \begin_layout Plain Layout
  1240. -- Foo is bad!
  1241. \end_layout
  1242. \begin_layout Plain Layout
  1243. end if;
  1244. \end_layout
  1245. \end_inset
  1246. \end_layout
  1247. \end_inset
  1248. \end_layout
  1249. \begin_layout Standard
  1250. This follows the same rules as the
  1251. \emph on
  1252. Is_Valid
  1253. \emph default
  1254. parameter for the
  1255. \emph on
  1256. Read
  1257. \emph default
  1258. procedure.
  1259. \end_layout
  1260. \begin_layout Subsection
  1261. Clearing keys and the entire cache
  1262. \end_layout
  1263. \begin_layout Standard
  1264. For clearing of keys and the entire cache we have, naturally, two
  1265. \emph on
  1266. Clear
  1267. \emph default
  1268. procedures:
  1269. \end_layout
  1270. \begin_layout Standard
  1271. \begin_inset Box Frameless
  1272. position "t"
  1273. hor_pos "c"
  1274. has_inner_box 1
  1275. inner_pos "t"
  1276. use_parbox 0
  1277. use_makebox 0
  1278. width "100col%"
  1279. special "none"
  1280. height "1in"
  1281. height_special "totalheight"
  1282. status open
  1283. \begin_layout Plain Layout
  1284. \begin_inset listings
  1285. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1286. inline false
  1287. status open
  1288. \begin_layout Plain Layout
  1289. -- First we clear the Foo key
  1290. \end_layout
  1291. \begin_layout Plain Layout
  1292. My_Cache.Clear (Key => "Foo");
  1293. \end_layout
  1294. \begin_layout Plain Layout
  1295. \end_layout
  1296. \begin_layout Plain Layout
  1297. -- And then we clear the entire cache
  1298. \end_layout
  1299. \begin_layout Plain Layout
  1300. My_Cache.Clear;
  1301. \end_layout
  1302. \end_inset
  1303. \end_layout
  1304. \end_inset
  1305. \end_layout
  1306. \begin_layout Subsection
  1307. How much is in there?
  1308. \end_layout
  1309. \begin_layout Standard
  1310. With the
  1311. \emph on
  1312. Discrete_Keys
  1313. \emph default
  1314. cache we obviously always know the exact amount of keys available, since
  1315. we've defined the keys ourselves.
  1316. This is not the case with the
  1317. \emph on
  1318. String_Keys
  1319. \emph default
  1320. cache, where any
  1321. \emph on
  1322. String
  1323. \emph default
  1324. can be a key.
  1325. If we need to know how many elements that are currently in the cache, we
  1326. call the
  1327. \emph on
  1328. Length
  1329. \emph default
  1330. function:
  1331. \end_layout
  1332. \begin_layout Standard
  1333. \begin_inset Box Frameless
  1334. position "t"
  1335. hor_pos "c"
  1336. has_inner_box 1
  1337. inner_pos "t"
  1338. use_parbox 0
  1339. use_makebox 0
  1340. width "100col%"
  1341. special "none"
  1342. height "1in"
  1343. height_special "totalheight"
  1344. status open
  1345. \begin_layout Plain Layout
  1346. \begin_inset listings
  1347. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1348. inline false
  1349. status open
  1350. \begin_layout Plain Layout
  1351. if My_Cache.Length > 1000 then
  1352. \end_layout
  1353. \begin_layout Plain Layout
  1354. -- Woa! Lots of stuff in the cache..
  1355. \end_layout
  1356. \begin_layout Plain Layout
  1357. end if;
  1358. \end_layout
  1359. \end_inset
  1360. \end_layout
  1361. \end_inset
  1362. \end_layout
  1363. \begin_layout Standard
  1364. Note that
  1365. \emph on
  1366. Length
  1367. \emph default
  1368. count both valid and invalid elements.
  1369. \end_layout
  1370. \begin_layout Subsection
  1371. Cleanup - Keeping cache size in check
  1372. \end_layout
  1373. \begin_layout Standard
  1374. if
  1375. \emph on
  1376. Cleanup_On_Write
  1377. \emph default
  1378. is
  1379. \emph on
  1380. True
  1381. \emph default
  1382. , then
  1383. \emph on
  1384. Cleanup
  1385. \emph default
  1386. is called by
  1387. \emph on
  1388. Write
  1389. \emph default
  1390. whenever the size of the cache reach
  1391. \emph on
  1392. Cleanup_Size
  1393. \emph default
  1394. .
  1395. It is of course also possible to call it manually:
  1396. \end_layout
  1397. \begin_layout Standard
  1398. \begin_inset Box Frameless
  1399. position "t"
  1400. hor_pos "c"
  1401. has_inner_box 1
  1402. inner_pos "t"
  1403. use_parbox 0
  1404. use_makebox 0
  1405. width "100col%"
  1406. special "none"
  1407. height "1in"
  1408. height_special "totalheight"
  1409. status open
  1410. \begin_layout Plain Layout
  1411. \begin_inset listings
  1412. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1413. inline false
  1414. status open
  1415. \begin_layout Plain Layout
  1416. if My_Cache.Length > 1000 then
  1417. \end_layout
  1418. \begin_layout Plain Layout
  1419. My_Cache.Cleanup;
  1420. \end_layout
  1421. \begin_layout Plain Layout
  1422. end if;
  1423. \end_layout
  1424. \end_inset
  1425. \end_layout
  1426. \end_inset
  1427. \end_layout
  1428. \begin_layout Standard
  1429. If you've set
  1430. \emph on
  1431. Cleanup_On_Write
  1432. \emph default
  1433. to Boolean
  1434. \emph on
  1435. False
  1436. \emph default
  1437. and the String keys are coming from outside sources, then you really should
  1438. make sure you call
  1439. \emph on
  1440. Cleanup
  1441. \emph default
  1442. on a regular basis.
  1443. \end_layout
  1444. \begin_layout Section
  1445. Yolk.Command_Line
  1446. \end_layout
  1447. \begin_layout Standard
  1448. This package enables you to fetch the value of a given commandline parameter
  1449. using the
  1450. \emph on
  1451. Get
  1452. \emph default
  1453. function:
  1454. \end_layout
  1455. \begin_layout Standard
  1456. \begin_inset Box Frameless
  1457. position "t"
  1458. hor_pos "c"
  1459. has_inner_box 1
  1460. inner_pos "t"
  1461. use_parbox 0
  1462. use_makebox 0
  1463. width "100col%"
  1464. special "none"
  1465. height "1in"
  1466. height_special "totalheight"
  1467. status open
  1468. \begin_layout Plain Layout
  1469. \begin_inset listings
  1470. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1471. inline false
  1472. status open
  1473. \begin_layout Plain Layout
  1474. function Get
  1475. \end_layout
  1476. \begin_layout Plain Layout
  1477. (Parameter : in String;
  1478. \end_layout
  1479. \begin_layout Plain Layout
  1480. Default : in String := "")
  1481. \end_layout
  1482. \begin_layout Plain Layout
  1483. return String;
  1484. \end_layout
  1485. \end_inset
  1486. \end_layout
  1487. \end_inset
  1488. \end_layout
  1489. \begin_layout Standard
  1490. If
  1491. \emph on
  1492. Parameter
  1493. \emph default
  1494. is found
  1495. \emph on
  1496. Get
  1497. \emph default
  1498. will return the value immediately following
  1499. \emph on
  1500. Parameter.
  1501. \emph default
  1502. If
  1503. \emph on
  1504. Parameter
  1505. \emph default
  1506. isn't found
  1507. \emph on
  1508. Default
  1509. \emph default
  1510. is returned.
  1511. \end_layout
  1512. \begin_layout Section
  1513. Yolk.Config_File_Parser
  1514. \end_layout
  1515. \begin_layout Standard
  1516. This package enables you to access KEY/VALUE pairs in configuration files
  1517. that are written in the style:
  1518. \end_layout
  1519. \begin_layout LyX-Code
  1520. # This is a comment
  1521. \end_layout
  1522. \begin_layout LyX-Code
  1523. -- This is also a comment
  1524. \end_layout
  1525. \begin_layout LyX-Code
  1526. KEY VALUE
  1527. \end_layout
  1528. \begin_layout Standard
  1529. Keys are case-insensitive, so
  1530. \emph on
  1531. FOO
  1532. \emph default
  1533. ,
  1534. \emph on
  1535. foo
  1536. \emph default
  1537. and
  1538. \emph on
  1539. fOo
  1540. \emph default
  1541. are all the same.
  1542. \emph on
  1543. \emph default
  1544. Blank lines and comments are ignored and so is pre/postfixed whitespace.
  1545. It is not necessary to quote values that contain whitespace, to this:
  1546. \end_layout
  1547. \begin_layout LyX-Code
  1548. KEY some value with whitespace
  1549. \end_layout
  1550. \begin_layout Standard
  1551. is perfectly valid, and will return
  1552. \begin_inset Quotes eld
  1553. \end_inset
  1554. \emph on
  1555. some value with whitespace
  1556. \emph default
  1557. \begin_inset Quotes erd
  1558. \end_inset
  1559. when calling
  1560. \emph on
  1561. Get (KEY)
  1562. \emph default
  1563. .
  1564. If VALUE is
  1565. \emph on
  1566. Boolean
  1567. \emph default
  1568. \emph on
  1569. True
  1570. \emph default
  1571. or
  1572. \emph on
  1573. False
  1574. \emph default
  1575. (case-insensitive), then the KEY can be returned as a
  1576. \emph on
  1577. String
  1578. \emph default
  1579. or a
  1580. \emph on
  1581. Boolean
  1582. \emph default
  1583. , depending on the target type.
  1584. If the target type does not match the VALUE and no sensible conversion
  1585. can be made, then a
  1586. \emph on
  1587. Conversion_Error
  1588. \emph default
  1589. exception is raised.
  1590. No dummy values are returned at any time.
  1591. \end_layout
  1592. \begin_layout Standard
  1593. To clear a default value, simply add the key to the configuration file,
  1594. with no value set.
  1595. \end_layout
  1596. \begin_layout Subsection
  1597. The generic formal parameters
  1598. \end_layout
  1599. \begin_layout Standard
  1600. These are:
  1601. \end_layout
  1602. \begin_layout Standard
  1603. \begin_inset Box Frameless
  1604. position "t"
  1605. hor_pos "c"
  1606. has_inner_box 1
  1607. inner_pos "t"
  1608. use_parbox 0
  1609. use_makebox 0
  1610. width "100col%"
  1611. special "none"
  1612. height "1in"
  1613. height_special "totalheight"
  1614. status open
  1615. \begin_layout Plain Layout
  1616. \begin_inset listings
  1617. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1618. inline false
  1619. status open
  1620. \begin_layout Plain Layout
  1621. generic
  1622. \end_layout
  1623. \begin_layout Plain Layout
  1624. use Ada.Strings.Unbounded;
  1625. \end_layout
  1626. \begin_layout Plain Layout
  1627. type Key_Type is (<>);
  1628. \end_layout
  1629. \begin_layout Plain Layout
  1630. type Defaults_Array_Type is array (Key_Type) of Unbounded_String;
  1631. \end_layout
  1632. \begin_layout Plain Layout
  1633. Defaults : in Defaults_Array_Type;
  1634. \end_layout
  1635. \begin_layout Plain Layout
  1636. Config_File : in String;
  1637. \end_layout
  1638. \begin_layout Plain Layout
  1639. package Yolk.Config_File_Parser is
  1640. \end_layout
  1641. \begin_layout Plain Layout
  1642. ...
  1643. \end_layout
  1644. \end_inset
  1645. \end_layout
  1646. \end_inset
  1647. \end_layout
  1648. \begin_layout Standard
  1649. \emph on
  1650. Config_File
  1651. \emph default
  1652. is of course the name and location of the configuration file.
  1653. \end_layout
  1654. \begin_layout Subsection
  1655. Exceptions
  1656. \end_layout
  1657. \begin_layout Standard
  1658. There are 3 different exceptions that can be raised by the
  1659. \emph on
  1660. Yolk.Config_File_Parser
  1661. \emph default
  1662. package.
  1663. These are:
  1664. \end_layout
  1665. \begin_layout Itemize
  1666. \emph on
  1667. Unknown_Key
  1668. \emph default
  1669. .
  1670. This is raised if an unknown key has been found in the configuration file
  1671. given when instantiating the package or when
  1672. \emph on
  1673. Load_File
  1674. \emph default
  1675. is called.
  1676. \end_layout
  1677. \begin_layout Itemize
  1678. \emph on
  1679. Cannot_Open_Config_File
  1680. \emph default
  1681. .
  1682. This is raised when
  1683. \emph on
  1684. Config_File
  1685. \emph default
  1686. cannot be read.
  1687. \end_layout
  1688. \begin_layout Itemize
  1689. \emph on
  1690. Conversion_Error
  1691. \emph default
  1692. .
  1693. This is raised when a value cannot be converted to the target type, ie.
  1694. the value
  1695. \begin_inset Quotes eld
  1696. \end_inset
  1697. 42
  1698. \begin_inset Quotes erd
  1699. \end_inset
  1700. to a
  1701. \emph on
  1702. Boolean
  1703. \emph default
  1704. .
  1705. \end_layout
  1706. \begin_layout Subsection
  1707. Instantiation
  1708. \end_layout
  1709. \begin_layout Standard
  1710. \emph on
  1711. Yolk.Config_File_Parser
  1712. \emph default
  1713. is a generic package, so in order to use it, you have to instantiate it,
  1714. like this:
  1715. \end_layout
  1716. \begin_layout Standard
  1717. \begin_inset Box Frameless
  1718. position "t"
  1719. hor_pos "c"
  1720. has_inner_box 1
  1721. inner_pos "t"
  1722. use_parbox 0
  1723. use_makebox 0
  1724. width "100col%"
  1725. special "none"
  1726. height "1in"
  1727. height_special "totalheight"
  1728. status open
  1729. \begin_layout Plain Layout
  1730. \begin_inset listings
  1731. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1732. inline false
  1733. status open
  1734. \begin_layout Plain Layout
  1735. package My_Configuration is
  1736. \end_layout
  1737. \begin_layout Plain Layout
  1738. \end_layout
  1739. \begin_layout Plain Layout
  1740. type Keys is (Foo, Bar);
  1741. \end_layout
  1742. \begin_layout Plain Layout
  1743. type Defaults_Array is array (Keys) of Unbounded_String;
  1744. \end_layout
  1745. \begin_layout Plain Layout
  1746. \end_layout
  1747. \begin_layout Plain Layout
  1748. Default_Values : constant Defaults_Array :=
  1749. \end_layout
  1750. \begin_layout Plain Layout
  1751. (Foo => To_Unbounded_String ("some foo"),
  1752. \end_layout
  1753. \begin_layout Plain Layout
  1754. Bar => To_Unbounded_String ("some bar"));
  1755. \end_layout
  1756. \begin_layout Plain Layout
  1757. \end_layout
  1758. \begin_layout Plain Layout
  1759. package Config is new Yolk.Config_File_Parser
  1760. \end_layout
  1761. \begin_layout Plain Layout
  1762. (Key_Type => Keys,
  1763. \end_layout
  1764. \begin_layout Plain Layout
  1765. Defaults_Array_Type => Defaults_Array,
  1766. \end_layout
  1767. \begin_layout Plain Layout
  1768. Defaults => Default_Value,
  1769. \end_layout
  1770. \begin_layout Plain Layout
  1771. Config_File => "config.ini");
  1772. \end_layout
  1773. \begin_layout Plain Layout
  1774. \end_layout
  1775. \begin_layout Plain Layout
  1776. end My_Configuration;
  1777. \end_layout
  1778. \end_inset
  1779. \end_layout
  1780. \end_inset
  1781. \end_layout
  1782. \begin_layout Standard
  1783. Here we instantiate the
  1784. \emph on
  1785. Config
  1786. \emph default
  1787. package with
  1788. \emph on
  1789. config.ini
  1790. \emph default
  1791. as the configuration file.
  1792. This means that KEY/VALUE pairs found in this file will overwrite the default
  1793. values set in the
  1794. \emph on
  1795. Default_Values
  1796. \emph default
  1797. array.
  1798. Setting a default value to
  1799. \emph on
  1800. Null_Unbounded_String
  1801. \emph default
  1802. means the value is empty.
  1803. \end_layout
  1804. \begin_layout Standard
  1805. Note that the
  1806. \emph on
  1807. config.ini
  1808. \emph default
  1809. file does not have to contain all the valid keys.
  1810. It is perfectly fine to only add those keys that have non-default values
  1811. to the configuration file.
  1812. \end_layout
  1813. \begin_layout Subsection
  1814. Re-loading configuration files
  1815. \end_layout
  1816. \begin_layout Standard
  1817. With the
  1818. \emph on
  1819. Load_File
  1820. \emph default
  1821. procedure you can re-load a new configuration file into your
  1822. \emph on
  1823. Config
  1824. \emph default
  1825. package:
  1826. \end_layout
  1827. \begin_layout Standard
  1828. \begin_inset Box Frameless
  1829. position "t"
  1830. hor_pos "c"
  1831. has_inner_box 1
  1832. inner_pos "t"
  1833. use_parbox 0
  1834. use_makebox 0
  1835. width "100col%"
  1836. special "none"
  1837. height "1in"
  1838. height_special "totalheight"
  1839. status open
  1840. \begin_layout Plain Layout
  1841. \begin_inset listings
  1842. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1843. inline false
  1844. status open
  1845. \begin_layout Plain Layout
  1846. My_Configuration.Config.Load_File ("new_config.ini");
  1847. \end_layout
  1848. \end_inset
  1849. \end_layout
  1850. \end_inset
  1851. \end_layout
  1852. \begin_layout Standard
  1853. Now the KEY/VALUE pairs of
  1854. \emph on
  1855. new_config.ini
  1856. \emph default
  1857. will overwrite the ones originally found in the
  1858. \emph on
  1859. config.ini
  1860. \emph default
  1861. file the package was instantiated with.
  1862. You can do this as many times as you like.
  1863. Note that you cannot change what KEY's are valid, so if the
  1864. \emph on
  1865. new_config.ini
  1866. \emph default
  1867. file contains unknown keys,
  1868. \emph on
  1869. Load_File
  1870. \emph default
  1871. will raise the
  1872. \emph on
  1873. Unknown_Key
  1874. \emph default
  1875. exception.
  1876. \end_layout
  1877. \begin_layout Subsection
  1878. Getting values
  1879. \end_layout
  1880. \begin_layout Standard
  1881. With instantiation and loading of configuration files out of the way, it
  1882. is now time to get to the configuration values.
  1883. To get the value of the
  1884. \emph on
  1885. Foo
  1886. \emph default
  1887. key, you do:
  1888. \end_layout
  1889. \begin_layout Standard
  1890. \begin_inset Box Frameless
  1891. position "t"
  1892. hor_pos "c"
  1893. has_inner_box 1
  1894. inner_pos "t"
  1895. use_parbox 0
  1896. use_makebox 0
  1897. width "100col%"
  1898. special "none"
  1899. height "1in"
  1900. height_special "totalheight"
  1901. status open
  1902. \begin_layout Plain Layout
  1903. \begin_inset listings
  1904. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1905. inline false
  1906. status open
  1907. \begin_layout Plain Layout
  1908. My_Configuration.Config.Get (Foo);
  1909. \end_layout
  1910. \end_inset
  1911. \end_layout
  1912. \end_inset
  1913. \end_layout
  1914. \begin_layout Standard
  1915. There are Get functions for the following types:
  1916. \end_layout
  1917. \begin_layout Itemize
  1918. \emph on
  1919. Boolean
  1920. \end_layout
  1921. \begin_layout Itemize
  1922. \emph on
  1923. Duration
  1924. \end_layout
  1925. \begin_layout Itemize
  1926. \emph on
  1927. Float
  1928. \end_layout
  1929. \begin_layout Itemize
  1930. \emph on
  1931. Integer
  1932. \end_layout
  1933. \begin_layout Itemize
  1934. \emph on
  1935. String
  1936. \end_layout
  1937. \begin_layout Itemize
  1938. \emph on
  1939. Unbounded_String
  1940. \end_layout
  1941. \begin_layout Standard
  1942. Empty keys simply return an empty
  1943. \emph on
  1944. String
  1945. \emph default
  1946. or a
  1947. \emph on
  1948. Null_Unbounded_String
  1949. \emph default
  1950. , depending on the target type.
  1951. If a key is empty and the target type is not a
  1952. \emph on
  1953. String
  1954. \emph default
  1955. or an
  1956. \emph on
  1957. Unbounded_String
  1958. \emph default
  1959. , then the
  1960. \emph on
  1961. Conversion_Error
  1962. \emph default
  1963. exception is raised.
  1964. \end_layout
  1965. \begin_layout Subsection
  1966. Checking if a KEY has a VALUE
  1967. \end_layout
  1968. \begin_layout Standard
  1969. You can check if a key has a value with the
  1970. \emph on
  1971. Has_Value
  1972. \emph default
  1973. function:
  1974. \end_layout
  1975. \begin_layout Standard
  1976. \begin_inset Box Frameless
  1977. position "t"
  1978. hor_pos "c"
  1979. has_inner_box 1
  1980. inner_pos "t"
  1981. use_parbox 0
  1982. use_makebox 0
  1983. width "100col%"
  1984. special "none"
  1985. height "1in"
  1986. height_special "totalheight"
  1987. status open
  1988. \begin_layout Plain Layout
  1989. \begin_inset listings
  1990. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  1991. inline false
  1992. status open
  1993. \begin_layout Plain Layout
  1994. if Has_Value (Foo) then
  1995. \end_layout
  1996. \begin_layout Plain Layout
  1997. Put_Line ("Foo has a value");
  1998. \end_layout
  1999. \begin_layout Plain Layout
  2000. end if;
  2001. \end_layout
  2002. \end_inset
  2003. \end_layout
  2004. \end_inset
  2005. \end_layout
  2006. \begin_layout Standard
  2007. Basically all this function does is return
  2008. \emph on
  2009. Boolean
  2010. \emph default
  2011. \emph on
  2012. True
  2013. \emph default
  2014. if the value of the given key is not a
  2015. \emph on
  2016. Null_Unbounded_String
  2017. \emph default
  2018. .
  2019. \end_layout
  2020. \begin_layout Section
  2021. Yolk.Configuration
  2022. \end_layout
  2023. \begin_layout Standard
  2024. This package is a bit of an oddball, as all it does is instantiate the
  2025. \emph on
  2026. Yolk.Config_File_Parser
  2027. \emph default
  2028. generic with the default AWS and Yolk configuration values.
  2029. This is used by Yolk internally, but also by the AWS component of your
  2030. application.
  2031. The instantiation looks like this:
  2032. \end_layout
  2033. \begin_layout Standard
  2034. \begin_inset Box Frameless
  2035. position "t"
  2036. hor_pos "c"
  2037. has_inner_box 1
  2038. inner_pos "t"
  2039. use_parbox 0
  2040. use_makebox 0
  2041. width "100col%"
  2042. special "none"
  2043. height "1in"
  2044. height_special "totalheight"
  2045. status open
  2046. \begin_layout Plain Layout
  2047. \begin_inset listings
  2048. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  2049. inline false
  2050. status open
  2051. \begin_layout Plain Layout
  2052. package Config is new Config_File_Parser
  2053. \end_layout
  2054. \begin_layout Plain Layout
  2055. (Key_Type => Keys,
  2056. \end_layout
  2057. \begin_layout Plain Layout
  2058. Defaults_Array_Type => Defaults_Array,
  2059. \end_layout
  2060. \begin_layout Plain Layout
  2061. Defaults => Default_Values,
  2062. \end_layout
  2063. \begin_layout Plain Layout
  2064. Config_File => Config_File);
  2065. \end_layout
  2066. \end_inset
  2067. \end_layout
  2068. \end_inset
  2069. \end_layout
  2070. \begin_layout Standard
  2071. The
  2072. \emph on
  2073. Config_File
  2074. \emph default
  2075. function call return either the default Yolk configuration file (
  2076. \emph on
  2077. configuration/config.ini
  2078. \emph default
  2079. ) or a user specified configuration file given by the
  2080. \emph on
  2081. --yolk-config-file
  2082. \emph default
  2083. command line argument, so
  2084. \emph on
  2085. \emph default
  2086. starting for example the Yolk demo like this:
  2087. \end_layout
  2088. \begin_layout LyX-Code
  2089. ./yolk_demo --yolk-config-file /etc/yolk-config.ini
  2090. \end_layout
  2091. \begin_layout Standard
  2092. will force the demo to look for the
  2093. \emph on
  2094. /etc/yolk-config.ini
  2095. \emph default
  2096. configuration file.
  2097. \end_layout
  2098. \begin_layout Standard
  2099. There's a fully commented
  2100. \emph on
  2101. config.ini.dist
  2102. \emph default
  2103. file available in the
  2104. \emph on
  2105. extras/
  2106. \emph default
  2107. directory.
  2108. I recommend taking a look at the Yolk demo application to see how the
  2109. \emph on
  2110. Yolk.Configuration
  2111. \emph default
  2112. package is used.
  2113. \end_layout
  2114. \begin_layout Subsection
  2115. Get the AWS specific configuration settings
  2116. \end_layout
  2117. \begin_layout Standard
  2118. On some occassions it might be necessary to get the AWS configuration object.
  2119. This can easily be accomplished by calling the
  2120. \emph on
  2121. Get_AWS_Configuration
  2122. \emph default
  2123. function:
  2124. \end_layout
  2125. \begin_layout Standard
  2126. \begin_inset Box Frameless
  2127. position "t"
  2128. hor_pos "c"
  2129. has_inner_box 1
  2130. inner_pos "t"
  2131. use_parbox 0
  2132. use_makebox 0
  2133. width "100col%"
  2134. special "none"
  2135. height "1in"
  2136. height_special "totalheight"
  2137. status open
  2138. \begin_layout Plain Layout
  2139. \begin_inset listings
  2140. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  2141. inline false
  2142. status open
  2143. \begin_layout Plain Layout
  2144. AWS_Config : constant AWS.Config.Object :=
  2145. \end_layout
  2146. \begin_layout Plain Layout
  2147. Yolk.Configuration.Get_AWS_Configuration;
  2148. \end_layout
  2149. \end_inset
  2150. \end_layout
  2151. \end_inset
  2152. \end_layout
  2153. \begin_layout Section
  2154. Yolk.Email
  2155. \end_layout
  2156. \begin_layout Standard
  2157. Using
  2158. \emph on
  2159. Yolk.Email
  2160. \emph default
  2161. and the child package
  2162. \emph on
  2163. Yolk.Email.Composer
  2164. \emph default
  2165. you can build and send more or less any kind of email:
  2166. \end_layout
  2167. \begin_layout Itemize
  2168. Plain text
  2169. \end_layout
  2170. \begin_layout Itemize
  2171. Multipart/Alternative
  2172. \end_layout
  2173. \begin_layout Itemize
  2174. Multipart/Mixed
  2175. \end_layout
  2176. \begin_layout Standard
  2177. The package supports adding multiple SMTP servers, meaning you can add as
  2178. many as you need, and the email will then be send via the first one that
  2179. accepts it.
  2180. \end_layout
  2181. \begin_layout Standard
  2182. The
  2183. \emph on
  2184. Yolk.Email
  2185. \emph default
  2186. package define 4 exceptions and 3 types.
  2187. The facilities for actually constructing and sending the email are found
  2188. in
  2189. \emph on
  2190. Yolk.Email.Composer
  2191. \emph default
  2192. .
  2193. \end_layout
  2194. \begin_layout Subsection
  2195. Exceptions
  2196. \end_layout
  2197. \begin_layout Standard
  2198. These are:
  2199. \end_layout
  2200. \begin_layout Itemize
  2201. \emph on
  2202. Attachment_File_Not_Found
  2203. \emph default
  2204. .
  2205. Is raised if a file attachment is not found at the given path.
  2206. \end_layout
  2207. \begin_layout Itemize
  2208. \emph on
  2209. No_Address_Set
  2210. \emph default
  2211. .
  2212. Is raised if the address component of a To, Reply-To, From, Bcc/Cc header
  2213. is missing.
  2214. \end_layout
  2215. \begin_layout Itemize
  2216. \emph on
  2217. No_Sender_Set_With_Multiple_From
  2218. \emph default
  2219. .
  2220. Is raised when an email contains multiple From headers but no Sender header,
  2221. as per RFC-5322, 3.6.2.
  2222. http://tools.ietf.org/html/rfc5322
  2223. \end_layout
  2224. \begin_layout Itemize
  2225. \emph on
  2226. No_SMTP_Host_Set
  2227. \emph default
  2228. .
  2229. Is raised if the SMTP host list is empty, ie.
  2230. no SMTP host has been set for sending the email.
  2231. \end_layout
  2232. \begin_layout Subsection
  2233. The Yolk.Email types
  2234. \end_layout
  2235. \begin_layout Standard
  2236. When using
  2237. \emph on
  2238. Yolk.Email.Composer
  2239. \emph default
  2240. to build and send emails, three types declared in
  2241. \emph on
  2242. Yolk.Email
  2243. \emph default
  2244. are central:
  2245. \end_layout
  2246. \begin_layout Enumerate
  2247. \emph on
  2248. Character_Set
  2249. \end_layout
  2250. \begin_layout Enumerate
  2251. \emph on
  2252. Recipient_Kind
  2253. \end_layout
  2254. \begin_layout Enumerate
  2255. \emph on
  2256. Structure
  2257. \end_layout
  2258. \begin_layout Standard
  2259. The
  2260. \emph on
  2261. Character_Set
  2262. \emph default
  2263. type define what character set is used when data is added to an email
  2264. \emph on
  2265. Structure
  2266. \emph default
  2267. object.
  2268. For example looking at the
  2269. \emph on
  2270. Yolk.Email.Composer.Add_From
  2271. \emph default
  2272. procedure, we see that the
  2273. \emph on
  2274. Charset
  2275. \emph default
  2276. parameter defaults to
  2277. \emph on
  2278. US_ASCII
  2279. \emph default
  2280. :
  2281. \end_layout
  2282. \begin_layout Standard
  2283. \begin_inset Box Frameless
  2284. position "t"
  2285. hor_pos "c"
  2286. has_inner_box 1
  2287. inner_pos "t"
  2288. use_parbox 0
  2289. use_makebox 0
  2290. width "100col%"
  2291. special "none"
  2292. height "1in"
  2293. height_special "totalheight"
  2294. status open
  2295. \begin_layout Plain Layout
  2296. \begin_inset listings
  2297. lstparams "basicstyle={\small\sffamily},frame=tblr,language=Ada,showstringspaces=false,tabsize=3,xleftmargin=1em,xrightmargin=1em"
  2298. inline false
  2299. status open
  2300. \begin_layout Plain Layout
  2301. procedure Add_From
  2302. \end_layout
  2303. \begin_layout Plain Layout
  2304. (ES : in out Structure;
  2305. \end_layout
  2306. \begin_layout Plain Layout
  2307. Address : in String;
  2308. \end_layout
  2309. \begin_layout Plain Layout
  2310. Name : in String := "";
  2311. \end_layout
  2312. \begin_layout Plain Layout
  2313. Charset : in Character_Set := US_ASCII);
  2314. \end_layout
  2315. \end_inset
  2316. \end_layout
  2317. \end_ins