Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
1786f9b1
Commit
1786f9b1
authored
Feb 17, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/Partition: add command "newpartition"
parent
1e972174
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
0 deletions
+88
-0
protocol.xml
doc/protocol.xml
+14
-0
AllCommands.cxx
src/command/AllCommands.cxx
+1
-0
PartitionCommands.cxx
src/command/PartitionCommands.cxx
+70
-0
PartitionCommands.hxx
src/command/PartitionCommands.hxx
+3
-0
No files found.
doc/protocol.xml
View file @
1786f9b1
...
...
@@ -2376,6 +2376,20 @@ OK
</para>
</listitem>
</varlistentry>
<varlistentry
id=
"command_newpartition"
>
<term>
<cmdsynopsis>
<command>
newpartition
</command>
<arg
choice=
"req"
><replaceable>
NAME
</replaceable></arg>
</cmdsynopsis>
</term>
<listitem>
<para>
Create a new partition.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>
...
...
src/command/AllCommands.cxx
View file @
1786f9b1
...
...
@@ -133,6 +133,7 @@ static constexpr struct command commands[] = {
#endif
{
"move"
,
PERMISSION_CONTROL
,
2
,
2
,
handle_move
},
{
"moveid"
,
PERMISSION_CONTROL
,
2
,
2
,
handle_moveid
},
{
"newpartition"
,
PERMISSION_ADMIN
,
1
,
1
,
handle_newpartition
},
{
"next"
,
PERMISSION_CONTROL
,
0
,
0
,
handle_next
},
{
"notcommands"
,
PERMISSION_NONE
,
0
,
0
,
handle_not_commands
},
{
"outputs"
,
PERMISSION_READ
,
0
,
0
,
handle_devices
},
...
...
src/command/PartitionCommands.cxx
View file @
1786f9b1
...
...
@@ -24,6 +24,8 @@
#include "Partition.hxx"
#include "client/Client.hxx"
#include "client/Response.hxx"
#include "player/Thread.hxx"
#include "util/CharUtil.hxx"
CommandResult
handle_listpartitions
(
Client
&
client
,
Request
,
Response
&
r
)
...
...
@@ -34,3 +36,71 @@ handle_listpartitions(Client &client, Request, Response &r)
return
CommandResult
::
OK
;
}
static
constexpr
bool
IsValidPartitionChar
(
char
ch
)
{
return
IsAlphaNumericASCII
(
ch
)
||
ch
==
'-'
||
ch
==
'_'
;
}
gcc_pure
static
bool
IsValidPartitionName
(
const
char
*
name
)
{
do
{
if
(
!
IsValidPartitionChar
(
*
name
))
return
false
;
}
while
(
*++
name
!=
0
);
return
true
;
}
gcc_pure
static
bool
HasPartitionNamed
(
const
Instance
&
instance
,
const
char
*
name
)
{
for
(
const
auto
&
partition
:
instance
.
partitions
)
if
(
partition
.
name
==
name
)
return
true
;
return
false
;
}
CommandResult
handle_newpartition
(
Client
&
client
,
Request
request
,
Response
&
response
)
{
const
char
*
name
=
request
.
front
();
if
(
!
IsValidPartitionName
(
name
))
{
response
.
Error
(
ACK_ERROR_ARG
,
"bad name"
);
return
CommandResult
::
ERROR
;
}
auto
&
instance
=
client
.
partition
.
instance
;
if
(
HasPartitionNamed
(
instance
,
name
))
{
response
.
Error
(
ACK_ERROR_EXIST
,
"name already exists"
);
return
CommandResult
::
ERROR
;
}
if
(
instance
.
partitions
.
size
()
>=
16
)
{
/* arbitrary limit for now */
response
.
Error
(
ACK_ERROR_UNKNOWN
,
"too many partitions"
);
return
CommandResult
::
ERROR
;
}
instance
.
partitions
.
emplace_back
(
instance
,
name
,
// TODO: use real configuration
16384
,
1024
,
128
,
AudioFormat
::
Undefined
(),
ReplayGainConfig
());
auto
&
partition
=
instance
.
partitions
.
back
();
partition
.
outputs
.
AddNullOutput
(
instance
.
io_thread
.
GetEventLoop
(),
ReplayGainConfig
(),
partition
.
pc
);
partition
.
UpdateEffectiveReplayGainMode
();
StartPlayerThread
(
partition
.
pc
);
partition
.
pc
.
LockUpdateAudio
();
return
CommandResult
::
OK
;
}
src/command/PartitionCommands.hxx
View file @
1786f9b1
...
...
@@ -29,4 +29,7 @@ class Response;
CommandResult
handle_listpartitions
(
Client
&
client
,
Request
request
,
Response
&
response
);
CommandResult
handle_newpartition
(
Client
&
client
,
Request
request
,
Response
&
response
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment