1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-09-01 08:42:02 +00:00

API add removepool like the screen interface

This commit is contained in:
Kano 2012-04-21 03:15:41 +10:00
parent eec7c1a963
commit 2e1d2017de
4 changed files with 68 additions and 2 deletions

6
README
View File

@ -709,6 +709,12 @@ The list of requests - a (*) means it requires privileged access - and replies a
stating the results of disabling pool N stating the results of disabling pool N
The Msg includes the pool URL The Msg includes the pool URL
removepool|N (*)
none There is no reply section just the STATUS section
stating the results of removing pool N
The Msg includes the pool URL
N.B. all details for the pool will be lost
gpuenable|N (*) gpuenable|N (*)
none There is no reply section just the STATUS section none There is no reply section just the STATUS section
stating the results of the enable request stating the results of the enable request

59
api.c
View File

@ -337,6 +337,10 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_PGAUNW 65 #define MSG_PGAUNW 65
#endif #endif
#define MSG_REMLASTP 66
#define MSG_ACTPOOL 67
#define MSG_REMPOOL 68
enum code_severity { enum code_severity {
SEVERITY_ERR, SEVERITY_ERR,
SEVERITY_WARN, SEVERITY_WARN,
@ -456,6 +460,9 @@ struct CODES {
{ SEVERITY_ERR, MSG_INVPDP, PARAM_STR, "Invalid addpool details '%s'" }, { SEVERITY_ERR, MSG_INVPDP, PARAM_STR, "Invalid addpool details '%s'" },
{ SEVERITY_ERR, MSG_TOOMANYP,PARAM_NONE, "Reached maximum number of pools (%d)" }, { SEVERITY_ERR, MSG_TOOMANYP,PARAM_NONE, "Reached maximum number of pools (%d)" },
{ SEVERITY_SUCC, MSG_ADDPOOL, PARAM_STR, "Added pool '%s'" }, { SEVERITY_SUCC, MSG_ADDPOOL, PARAM_STR, "Added pool '%s'" },
{ SEVERITY_ERR, MSG_REMLASTP,PARAM_POOL, "Cannot remove last pool %d:'%s'" },
{ SEVERITY_ERR, MSG_ACTPOOL, PARAM_POOL, "Cannot remove active pool %d:'%s'" },
{ SEVERITY_SUCC, MSG_REMPOOL, PARAM_BOTH, "Removed pool %d:'%s'" },
{ SEVERITY_SUCC, MSG_NOTIFY, PARAM_NONE, "Notify" }, { SEVERITY_SUCC, MSG_NOTIFY, PARAM_NONE, "Notify" },
{ SEVERITY_FAIL, 0, 0, NULL } { SEVERITY_FAIL, 0, 0, NULL }
}; };
@ -1621,6 +1628,57 @@ static void disablepool(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
strcpy(io_buffer, message(MSG_DISPOOL, id, NULL, isjson)); strcpy(io_buffer, message(MSG_DISPOOL, id, NULL, isjson));
} }
static void removepool(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
{
struct pool *pool;
char *rpc_url;
bool dofree = false;
int id;
if (total_pools == 0) {
strcpy(io_buffer, message(MSG_NOPOOL, 0, NULL, isjson));
return;
}
if (param == NULL || *param == '\0') {
strcpy(io_buffer, message(MSG_MISPID, 0, NULL, isjson));
return;
}
id = atoi(param);
if (id < 0 || id >= total_pools) {
strcpy(io_buffer, message(MSG_INVPID, id, NULL, isjson));
return;
}
if (total_pools <= 1) {
strcpy(io_buffer, message(MSG_REMLASTP, id, NULL, isjson));
return;
}
pool = pools[id];
if (pool == current_pool())
switch_pools(NULL);
if (pool == current_pool()) {
strcpy(io_buffer, message(MSG_ACTPOOL, id, NULL, isjson));
return;
}
pool->enabled = false;
rpc_url = escape_string(pool->rpc_url, isjson);
if (rpc_url != pool->rpc_url)
dofree = true;
remove_pool(pool);
strcpy(io_buffer, message(MSG_REMPOOL, id, rpc_url, isjson));
if (dofree)
free(rpc_url);
rpc_url = NULL;
}
static bool splitgpuvalue(char *param, int *gpu, char **value, bool isjson) static bool splitgpuvalue(char *param, int *gpu, char **value, bool isjson)
{ {
int id; int id;
@ -1934,6 +1992,7 @@ struct CMDS {
{ "addpool", addpool, true }, { "addpool", addpool, true },
{ "enablepool", enablepool, true }, { "enablepool", enablepool, true },
{ "disablepool", disablepool, true }, { "disablepool", disablepool, true },
{ "removepool", removepool, true },
{ "gpuintensity", gpuintensity, true }, { "gpuintensity", gpuintensity, true },
{ "gpumem", gpumem, true }, { "gpumem", gpumem, true },
{ "gpuengine", gpuengine, true }, { "gpuengine", gpuengine, true },

View File

@ -2383,10 +2383,11 @@ static void display_pool_summary(struct pool *pool)
unlock_curses(); unlock_curses();
} }
} }
#endif
/* We can't remove the memory used for this struct pool because there may /* We can't remove the memory used for this struct pool because there may
* still be work referencing it. We just remove it from the pools list */ * still be work referencing it. We just remove it from the pools list */
static void remove_pool(struct pool *pool) void remove_pool(struct pool *pool)
{ {
int i, last_pool = total_pools - 1; int i, last_pool = total_pools - 1;
struct pool *other; struct pool *other;
@ -2407,7 +2408,6 @@ static void remove_pool(struct pool *pool)
pool->pool_no = total_pools; pool->pool_no = total_pools;
total_pools--; total_pools--;
} }
#endif
void write_config(FILE *fcfg) void write_config(FILE *fcfg)
{ {

View File

@ -645,6 +645,7 @@ extern int curses_int(const char *query);
extern char *curses_input(const char *query); extern char *curses_input(const char *query);
extern void kill_work(void); extern void kill_work(void);
extern void switch_pools(struct pool *selected); extern void switch_pools(struct pool *selected);
extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg); extern void write_config(FILE *fcfg);
extern void log_curses(int prio, const char *f, va_list ap); extern void log_curses(int prio, const char *f, va_list ap);
extern void clear_logwin(void); extern void clear_logwin(void);