diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-13 09:42:06 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-10-13 09:42:06 -0500 |
| commit | 1e87c47a84ab5b2188fb34aa642b8bae123dc2d3 (patch) | |
| tree | 80fbca16f6e8851ff7515fd8b401a93d39e434f6 | |
| parent | 528f3537c630fe1e0e2d8ce991a388731ffb9b1c (diff) | |
| download | slskd-1e87c47a84ab5b2188fb34aa642b8bae123dc2d3.tar.gz | |
add Host types
| -rw-r--r-- | src/slskd/Shares/Types/Host.cs | 69 | ||||
| -rw-r--r-- | src/slskd/Shares/Types/HostState.cs | 35 |
2 files changed, 104 insertions, 0 deletions
diff --git a/src/slskd/Shares/Types/Host.cs b/src/slskd/Shares/Types/Host.cs new file mode 100644 index 00000000..45706b23 --- /dev/null +++ b/src/slskd/Shares/Types/Host.cs @@ -0,0 +1,69 @@ +// <copyright file="Host.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd.Shares +{ + using System.Collections.Generic; + using System.Linq; + + /// <summary> + /// A share host. + /// </summary> + public class Host + { + /// <summary> + /// Initializes a new instance of the <see cref="Host"/> class. + /// </summary> + /// <param name="name">The name of the host.</param> + /// <param name="shares">The collection of hosted shares.</param> + /// <param name="state">The initial state of the host.</param> + public Host(string name, IEnumerable<Share> shares = null, HostState state = HostState.Offline) + { + Name = name; + Shares = shares ?? Enumerable.Empty<Share>(); + State = state; + } + + /// <summary> + /// Gets the name of the host. + /// </summary> + /// <remarks>Corresponds to the configured <see cref="Options.InstanceName"/> of the host.</remarks> + public string Name { get; } + + /// <summary> + /// Gets the collection of hosted shares. + /// </summary> + public IEnumerable<Share> Shares { get; private set; } + + /// <summary> + /// Gets the host state. + /// </summary> + public HostState State { get; private set; } + + /// <summary> + /// Sets the hosted shares for the host. + /// </summary> + /// <param name="shares">The collection of shares.</param> + public void SetShares(IEnumerable<Share> shares) => Shares = shares; + + /// <summary> + /// Sets the state of the host. + /// </summary> + /// <param name="state">The new state.</param> + public void SetState(HostState state) => State = state; + } +}
\ No newline at end of file diff --git a/src/slskd/Shares/Types/HostState.cs b/src/slskd/Shares/Types/HostState.cs new file mode 100644 index 00000000..b10074d3 --- /dev/null +++ b/src/slskd/Shares/Types/HostState.cs @@ -0,0 +1,35 @@ +// <copyright file="HostState.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd.Shares +{ + /// <summary> + /// The state of a share host. + /// </summary> + public enum HostState + { + /// <summary> + /// Offline; unable to service requests. + /// </summary> + Offline = 0, + + /// <summary> + /// Online; able to service requests. + /// </summary> + Online = 1, + } +} |
