Skip to content

Commit 6568d28

Browse files
committed
Add filled templates
1 parent 240ffea commit 6568d28

11 files changed

Lines changed: 784 additions & 13 deletions

File tree

lib/membrane/bin.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ defmodule Membrane.Bin do
9999
100100
The callback won't be invoked, when you have initiated the pad removal,
101101
eg. when you have returned `t:Membrane.Bin.Action.remove_link()` action
102-
which made one of your children's pads be removed.
103-
By default, it does nothing.
102+
which made one of your children's pads be removed. Not having the
103+
callback implemented when a child removes its pad will result in the
104+
bin crashing.
104105
"""
105106
@callback handle_child_pad_removed(
106107
child :: Child.name(),

lib/membrane/core/options_specs.ex

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ defmodule Membrane.Core.OptionsSpecs do
77
alias Membrane.Pad
88

99
@spec options_doc() :: String.t()
10-
def options_doc do
10+
def options_doc() do
1111
"""
1212
Options are defined by a keyword list, where each key is an option name and
1313
is described by another keyword list with following fields:
1414
15-
* `spec:` typespec for value in struct
16-
* `default:` default value for option. If not present, value for this option
17-
will have to be provided each time options struct is created
18-
* `inspector:` function converting fields' value to a string. Used when
19-
creating documentation instead of `inspect/1`, eg. `inspector: &Membrane.Time.inspect/1`
20-
* `description:` string describing an option. It will be used for generating the docs
15+
* `spec:` Specification of the type the values of this option can have.
16+
* `default:` Default value for option. If not present, value for this option
17+
will have to be provided each time options struct is created.
18+
* `inspector:` Function converting fields' value to a string. Used when
19+
creating documentation instead of `inspect/1`, eg. `inspector: &Membrane.Time.inspect/1`.
20+
* `description:` String describing the option. It will be used for generating the docs.
2121
"""
2222
end
2323

@@ -55,6 +55,21 @@ defmodule Membrane.Core.OptionsSpecs do
5555
end
5656
end
5757

58+
@spec pad_options_doc() :: String.t()
59+
def pad_options_doc() do
60+
"""
61+
Pad options are defined by a keyword list, where each key is an option name and
62+
is described by another keyword list with following fields:
63+
64+
* `spec:` Specification of the type the values of this option can have.
65+
* `default:` Default value for option. If not present, value for this option
66+
will have to be provided each time options the pad is created.
67+
* `inspector:` Function converting fields' value to a string. Used when
68+
creating documentation instead of `inspect/1`, eg. `inspector: &Membrane.Time.inspect/1`.
69+
* `description:` String describing the option. It will be used for generating the docs.
70+
"""
71+
end
72+
5873
@spec def_pad_options(Pad.name(), nil | Keyword.t()) :: {Macro.t(), Macro.t()}
5974
def def_pad_options(_pad_name, []) do
6075
no_code =

lib/membrane/pad.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule Membrane.Pad do
1212

1313
use Bunch
1414

15+
alias Membrane.Core.OptionsSpecs
1516
alias Membrane.Buffer
1617

1718
@availability_values [:always, :on_request]
@@ -120,6 +121,8 @@ defmodule Membrane.Pad do
120121
121122
Demand unit is derived from the first element inside the bin linked to the
122123
given input.
124+
125+
#{OptionsSpecs.pad_options_doc()}
123126
"""
124127
@type bin_spec ::
125128
{name(),
@@ -130,6 +133,8 @@ defmodule Membrane.Pad do
130133

131134
@typedoc """
132135
Describes how a pad should be declared inside an element.
136+
137+
#{OptionsSpecs.pad_options_doc()}
133138
"""
134139
@type element_spec ::
135140
{name(),

lib/membrane/pipeline.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ defmodule Membrane.Pipeline do
147147
148148
The callback won't be invoked, when you have initiated the pad removal,
149149
eg. when you have returned `t:Membrane.Pipeline.Action.remove_link()`
150-
action which made one of your children's pads be removed.
151-
By default, it does nothing.
150+
action which made one of your children's pads be removed. Not having the
151+
callback implemented when a child removes its pad will result in the
152+
pipeline crashing.
152153
"""
153154
@callback handle_child_pad_removed(
154155
child :: Child.name(),

lib/mix/tasks/membrane_gen.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
use Mix.Task
88

9-
@switches [ path: :string ]
9+
@switches [path: :string]
1010

1111
@impl true
1212
def run(argv) do

templates/bin.ex

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,143 @@
11
defmodule Membrane.TemplateBin do
22
@moduledoc """
3-
Template bin
3+
This is a generated template for a Bin. Uncomment the snippets as necessary.
44
"""
55
use Membrane.Bin
66

7+
# def_input_pad :input,
8+
# accepted_format: _any,
9+
# availability: :on_request | :always,
10+
# max_instances: positive integer,
11+
# options: [
12+
# Same structure as in def_options/1
13+
# ]
714

15+
# def_output_pad :output,
16+
# accepted_format: _any,
17+
# availability: :on_request | :always,
18+
# max_instances: positive integer,
19+
# options: [
20+
# Same structure as in def_options/1
21+
# ]
22+
23+
# def_options some_option: [
24+
# spec: typespec of the option,
25+
# default: default value,
26+
# inspector: function converting fields' value to a string for documentation purposes (optional),
27+
# description: """
28+
# Desription of the option.
29+
# """
30+
# ]
31+
32+
defmodule State do
33+
# Using this struct is not strictly necessary, but it's considered a good practice
34+
# and is strongly encouraged. Having a state with static fields with defined
35+
# typespecs adds robustness to the codebase and can prevent many bugs.
36+
@moduledoc false
37+
38+
# When you add new fields to the struct remember to add them to this spec too.
39+
@type t :: %__MODULE__{}
40+
41+
defstruct []
42+
end
43+
44+
# ----------------------------------------------
45+
# --- CALLBACKS WITH DEFAULT IMPLEMENTATIONS ---
46+
# ----------------------------------------------
47+
48+
# Note: by default this callback will return with state set to an empty map %{},
49+
# however we recommend using a dedicated State struct.
50+
@impl true
51+
def handle_init(_ctx, opts) do
52+
{[], %State{}}
53+
end
54+
55+
# @impl true
56+
# def handle_pad_added(_pad, _context, state) do
57+
# {[], state}
58+
# end
59+
60+
# @impl true
61+
# def handle_pad_removed(_pad, _context, state) do
62+
# {[], state}
63+
# end
64+
65+
# @impl true
66+
# def handle_setup(_context, state) do
67+
# {[], state}
68+
# end
69+
70+
# @impl true
71+
# def handle_playing(_context, state) do
72+
# {[], state}
73+
# end
74+
75+
# @impl true
76+
# def handle_info(message, _context, state) do
77+
# Membrane.Logger.warning("""
78+
# Received message but no handle_info callback has been specified. Ignoring.
79+
# Message: #{inspect(message)}\
80+
# """)
81+
#
82+
# {[], state}
83+
# end
84+
85+
# @impl true
86+
# def handle_child_setup_completed(_child, _ctx, state) do
87+
# {[], state}
88+
# end
89+
90+
# @impl true
91+
# def handle_child_playing(_child, _ctx, state) do
92+
# {[], state}
93+
# end
94+
95+
# @impl true
96+
# def handle_element_start_of_stream(_element, _pad, _ctx, state) do
97+
# {[], state}
98+
# end
99+
100+
# @impl true
101+
# def handle_element_end_of_stream(_element, _pad, _ctx, state) do
102+
# {[], state}
103+
# end
104+
105+
# @impl true
106+
# def handle_child_notification(_notification, _element, _ctx, state) do
107+
# {[], state}
108+
# end
109+
110+
# @impl true
111+
# def handle_parent_notification(_notification, _ctx, state) do
112+
# {[], state}
113+
# end
114+
115+
# @impl true
116+
# def handle_crash_group_down(_group_name, _ctx, state) do
117+
# {[], state}
118+
# end
119+
120+
# @impl true
121+
# def handle_terminate_request(_ctx, state) do
122+
# {[terminate: :normal], state}
123+
# end
124+
125+
# @impl true
126+
# def handle_child_terminated(_child, _ctx, state) do
127+
# {[], state}
128+
# end
129+
130+
# --------------------------
131+
# --- OPTIONAL CALLBACKS ---
132+
# --------------------------
133+
134+
# @impl true
135+
# def handle_tick(timer_id, context, state) do
136+
# ...
137+
# end
138+
139+
# @impl true
140+
# handle_child_pad_removed(element, pad, ctx, state) do
141+
# ...
142+
# end
8143
end

templates/endpoint.ex

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
defmodule Membrane.TemplateEndpoint do
2+
@moduledoc """
3+
This is a generated template for an Endpoint. Uncomment the snippets as necessary.
4+
"""
5+
use Membrane.Endpoint
6+
7+
# def_input_pad :input,
8+
# accepted_format: _any,
9+
# availability: :on_request | :always,
10+
# max_instances: positive integer,
11+
# flow_control: :manual | :auto | :push,
12+
# demand_unit: :buffers | :bytes,
13+
# options: [
14+
# Same structure as in def_options/1
15+
# ]
16+
17+
# def_output_pad :output,
18+
# accepted_format: _any,
19+
# availability: :on_request | :always,
20+
# max_instances: positive integer,
21+
# flow_control: :manual | :auto | :push,
22+
# demand_unit: :buffers | :bytes,
23+
# options: [
24+
# Same structure as in def_options/1
25+
# ]
26+
27+
# def_options some_option: [
28+
# spec: typespec of the option,
29+
# default: default value,
30+
# inspector: function converting fields' value to a string for documentation purposes (optional),
31+
# description: """
32+
# Desription of the option.
33+
# """
34+
# ]
35+
36+
defmodule State do
37+
# Using this struct is not strictly necessary, but it's considered a good practice
38+
# and is strongly encouraged. Having a state with static fields with defined
39+
# typespecs adds robustness to the codebase and can prevent many bugs.
40+
@moduledoc false
41+
42+
# When you add new fields to the struct remember to add them to this spec too.
43+
@type t :: %__MODULE__{}
44+
45+
defstruct []
46+
end
47+
48+
# -----------------
49+
# --- CALLBACKS ---
50+
# -----------------
51+
52+
# Important: this callback only needs to be implemented when any output pads operate
53+
# in `:manual` flow control.
54+
# @impl true
55+
# def handle_demand(pad, size, unit, context, state) do
56+
# ...
57+
# end
58+
59+
# ----------------------------------------------
60+
# --- CALLBACKS WITH DEFAULT IMPLEMENTATIONS ---
61+
# ----------------------------------------------
62+
63+
# Note: by default this callback will return with state set to an empty map %{},
64+
# however we recommend using a dedicated State struct.
65+
@impl true
66+
def handle_init(_ctx, opts) do
67+
{[], %State{}}
68+
end
69+
70+
# @impl true
71+
# def handle_setup(_context, state) do
72+
# {[], state}
73+
# end
74+
75+
# @impl true
76+
# def handle_playing(_context, state) do
77+
# {[], state}
78+
# end
79+
80+
# @impl true
81+
# def handle_info(message, _context, state) do
82+
# Membrane.Logger.warning("""
83+
# Received message but no handle_info callback has been specified. Ignoring.
84+
# Message: #{inspect(message)}\
85+
# """)
86+
#
87+
# {[], state}
88+
# end
89+
90+
# @impl true
91+
# def handle_pad_added(_pad, _context, state) do
92+
# {[], state}
93+
# end
94+
95+
# @impl true
96+
# def handle_pad_removed(_pad, _context, state) do
97+
# {[], state}
98+
# end
99+
100+
# @impl true
101+
# def handle_stream_format(_pad, _stream_format, _context, state) do
102+
# {[], state}
103+
# end
104+
105+
# @impl true
106+
# def handle_start_of_stream(_pad, _context, state) do
107+
# {[], state}
108+
# end
109+
110+
# @impl true
111+
# def handle_event(_pad, _event, _context, state) do
112+
# {[], state}
113+
# end
114+
115+
# @impl true
116+
# def handle_parent_notification(_notification, _ctx, state) do
117+
# {[], state}
118+
# end
119+
120+
# @impl true
121+
# def handle_end_of_stream(_pad, _context, state) do
122+
# {[], state}
123+
# end
124+
125+
# @impl true
126+
# def handle_terminate_request(_ctx, state) do
127+
# {[terminate: :normal], state}
128+
# end
129+
130+
# --------------------------
131+
# --- OPTIONAL CALLBACKS ---
132+
# --------------------------
133+
134+
# @impl true
135+
# def handle_tick(timer_id, context, state) do
136+
# ...
137+
# end
138+
end

0 commit comments

Comments
 (0)