API add removepool like the screen interface
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
diff --git a/README b/README
index 3232f87..6344846 100644
--- a/README
+++ b/README
@@ -709,6 +709,12 @@ The list of requests - a (*) means it requires privileged access - and replies a
stating the results of disabling pool N
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 (*)
none There is no reply section just the STATUS section
stating the results of the enable request
diff --git a/api.c b/api.c
index ac2197c..dc373f7 100644
--- a/api.c
+++ b/api.c
@@ -337,6 +337,10 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_PGAUNW 65
#endif
+#define MSG_REMLASTP 66
+#define MSG_ACTPOOL 67
+#define MSG_REMPOOL 68
+
enum code_severity {
SEVERITY_ERR,
SEVERITY_WARN,
@@ -456,6 +460,9 @@ struct CODES {
{ SEVERITY_ERR, MSG_INVPDP, PARAM_STR, "Invalid addpool details '%s'" },
{ SEVERITY_ERR, MSG_TOOMANYP,PARAM_NONE, "Reached maximum number of pools (%d)" },
{ 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_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));
}
+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)
{
int id;
@@ -1934,6 +1992,7 @@ struct CMDS {
{ "addpool", addpool, true },
{ "enablepool", enablepool, true },
{ "disablepool", disablepool, true },
+ { "removepool", removepool, true },
{ "gpuintensity", gpuintensity, true },
{ "gpumem", gpumem, true },
{ "gpuengine", gpuengine, true },
diff --git a/cgminer.c b/cgminer.c
index 70f3e5e..0023922 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2383,10 +2383,11 @@ static void display_pool_summary(struct pool *pool)
unlock_curses();
}
}
+#endif
/* 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 */
-static void remove_pool(struct pool *pool)
+void remove_pool(struct pool *pool)
{
int i, last_pool = total_pools - 1;
struct pool *other;
@@ -2407,7 +2408,6 @@ static void remove_pool(struct pool *pool)
pool->pool_no = total_pools;
total_pools--;
}
-#endif
void write_config(FILE *fcfg)
{
diff --git a/miner.h b/miner.h
index 24a6ef3..aa87786 100644
--- a/miner.h
+++ b/miner.h
@@ -645,6 +645,7 @@ extern int curses_int(const char *query);
extern char *curses_input(const char *query);
extern void kill_work(void);
extern void switch_pools(struct pool *selected);
+extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg);
extern void log_curses(int prio, const char *f, va_list ap);
extern void clear_logwin(void);