Permalink
Browse files

rename application calls to gen-* calls

  • Loading branch information...
1 parent 5c4e618 commit 5c6d1844817b928e3bdc57640d1d567a2b1adcf5 @ericbmerritt committed May 2, 2012
Showing with 25 additions and 5 deletions.
  1. +25 −5 src/joxa/otp/application.jxa
@@ -6,27 +6,47 @@
(require erlang joxa.otp)
(use (joxa.core :only (try/1 unless/2))))
-(defn+ start-supervisor (sup-name)
+(defn+ gen-sup-call (sup-name)
;; Start a simple top level supervisor with the usual
;; defaults. *NOTE* that this function either returns a pid or
;; *throws* an exception with the error returned by start sup. You
;; should take this into account when calling this function.
(let (start-sup (erlang/make_fun sup-name :start_link 0))
- (case start-sup
+ (case (start-sup)
({:ok pid}
pid)
(err
(erlang/throw err)))))
-(defmacro+ start-function (sup-name)
+(defmacro+ gen-start (sup-name)
;; This macro defines a start function that creates the common
;; 'start top level supervisor' call that exists in most
;; applications.
(let (start-type (joxa.core/gensym "application")
start-args (joxa.core/gensym "application"))
`(defn+ start (~start-type ~start-args)
(try
- {:ok (joxa.opt.application ~sup-name)}
+ {:ok (joxa.otp.application ~sup-name)}
(catch
({:throw error}
- error))))))
+ error))))))
+
+(defmacro+ gen-stop ()
+ ;; Generate a default stop function for an application
+ (let (state (joxa.core/gensym "application"))
+ `(defn+ stop (~state)
+ :ok)))
+
+(defmacro+ gen-application (sup-name)
+ ;; Generate an entire application body
+ `(do
+ (gen-start sup-name)
+ (gen-stop))
+)
+
+(defmacro+ application (module-name)
+ ;; Ensure that the `module-name` implements the `application`
+ ;; behaviour
+ (unless (joxa.otp/implements-behaviour? module-name :application)
+ (erlang/throw {:does-not-implement-application module-name}))
+ [])

0 comments on commit 5c6d184

Please sign in to comment.