rpc: Use a single switch statement for both stringifications of cgpu->status
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
diff --git a/api.c b/api.c
index d2f0148..943c0d5 100644
--- a/api.c
+++ b/api.c
@@ -1231,6 +1231,26 @@ static void minerconfig(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
strcat(buf, JSON_CLOSE);
strcat(io_buffer, buf);
}
+
+static const char*
+status2str(enum alive status)
+{
+ switch (status) {
+ case LIFE_WELL:
+ return ALIVE;
+ case LIFE_SICK:
+ return SICK;
+ case LIFE_DEAD:
+ return DEAD;
+ case LIFE_NOSTART:
+ return NOSTART;
+ case LIFE_INIT:
+ return INIT;
+ default:
+ return UNKNOWN;
+ }
+}
+
#ifdef HAVE_OPENCL
static void gpustatus(int gpu, bool isjson)
{
@@ -1257,23 +1277,7 @@ static void gpustatus(int gpu, bool isjson)
else
enabled = (char *)NO;
- switch(cgpu->status) {
- case LIFE_DEAD:
- status = (char *)DEAD;
- break;
- case LIFE_SICK:
- status = (char *)SICK;
- break;
- case LIFE_NOSTART:
- status = (char *)NOSTART;
- break;
- case LIFE_INIT:
- status = (char *)INIT;
- break;
- default:
- status = (char *)ALIVE;
- break;
- }
+ status = (char *)status2str(cgpu->status);
if (cgpu->dynamic)
strcpy(intensity, DYNAMIC);
@@ -1312,6 +1316,7 @@ static void gpustatus(int gpu, bool isjson)
}
}
#endif
+
#ifdef HAVE_AN_FPGA
static void pgastatus(int pga, bool isjson)
{
@@ -1365,16 +1370,7 @@ static void pgastatus(int pga, bool isjson)
else
enabled = (char *)NO;
- if (cgpu->status == LIFE_DEAD)
- status = (char *)DEAD;
- else if (cgpu->status == LIFE_SICK)
- status = (char *)SICK;
- else if (cgpu->status == LIFE_NOSTART)
- status = (char *)NOSTART;
- else if (cgpu->status == LIFE_INIT)
- status = (char *)INIT;
- else
- status = (char *)ALIVE;
+ status = (char *)status2str(cgpu->status);
root = api_add_int(root, "PGA", &pga, false);
root = api_add_string(root, "Name", cgpu->api->name, false);