|
| 1 | +// Copyright 2020 The Defold Foundation |
| 2 | +// Licensed under the Defold License version 1.0 (the "License"); you may not use |
| 3 | +// this file except in compliance with the License. |
| 4 | +// |
| 5 | +// You may obtain a copy of the License, together with FAQs at |
| 6 | +// https://www.defold.com/license |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software distributed |
| 9 | +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 10 | +// CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | +// specific language governing permissions and limitations under the License. |
| 12 | + |
| 13 | +#ifndef DM_WEBSERVER_H |
| 14 | +#define DM_WEBSERVER_H |
| 15 | + |
| 16 | +#include <dmsdk/dlib/socket.h> |
| 17 | +#include <dmsdk/dlib/webserver.h> |
| 18 | + |
| 19 | +namespace dmWebServer |
| 20 | +{ |
| 21 | + /** |
| 22 | + * Set NewParams default values |
| 23 | + * @param params Pointer to NewParams |
| 24 | + */ |
| 25 | + void SetDefaultParams(struct NewParams* params); |
| 26 | + |
| 27 | + /** |
| 28 | + * Parameters passed into #New when creating a new web-server instance |
| 29 | + */ |
| 30 | + struct NewParams |
| 31 | + { |
| 32 | + /// Web-server port |
| 33 | + uint16_t m_Port; |
| 34 | + |
| 35 | + /// Max persistent client connections |
| 36 | + uint16_t m_MaxConnections; |
| 37 | + |
| 38 | + /// Connection timeout in seconds |
| 39 | + uint16_t m_ConnectionTimeout; |
| 40 | + |
| 41 | + NewParams() |
| 42 | + { |
| 43 | + SetDefaultParams(this); |
| 44 | + } |
| 45 | + }; |
| 46 | + |
| 47 | + /** |
| 48 | + * Crete a new web server |
| 49 | + * @param params Parameters |
| 50 | + * @param server Web server instance |
| 51 | + * @return RESULT_OK on success |
| 52 | + */ |
| 53 | + Result New(const NewParams* params, HServer* server); |
| 54 | + |
| 55 | + /** |
| 56 | + * Delete web server |
| 57 | + * @param server Web server instance |
| 58 | + */ |
| 59 | + void Delete(HServer server); |
| 60 | + /** |
| 61 | + * Update server |
| 62 | + * @param server Server handle |
| 63 | + * @return RESULT_OK on success |
| 64 | + */ |
| 65 | + Result Update(HServer server); |
| 66 | + |
| 67 | + /** |
| 68 | + * Get name for socket, ie address and port |
| 69 | + * @param server Web server |
| 70 | + * @param address Address (result) |
| 71 | + * @param port Port (result) |
| 72 | + */ |
| 73 | + void GetName(HServer server, dmSocket::Address* address, uint16_t* port); |
| 74 | +} |
| 75 | + |
| 76 | +#endif // DM_WEBSERVER_H |
0 commit comments