chiark / gitweb /
unit: Move UnitType definitions from core/unit.c to shared/unit-name.c
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 6 Jun 2012 14:56:18 +0000 (16:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Jul 2012 14:48:08 +0000 (16:48 +0200)
This makes it possible to use them from systemctl without linking
against the core. A string->enum lookup table is added.

src/core/unit.h
src/shared/unit-name.c
src/shared/unit-name.h

index cfb38d0aae751e79eae95e685a8bfbd68c18fc68..049b1dbd1e79fb0d331f07fbd9d7e5675609dfcb 100644 (file)
@@ -41,21 +41,7 @@ typedef struct UnitStatusMessageFormats UnitStatusMessageFormats;
 #include "execute.h"
 #include "condition.h"
 #include "install.h"
-
-enum UnitType {
-        UNIT_SERVICE = 0,
-        UNIT_SOCKET,
-        UNIT_TARGET,
-        UNIT_DEVICE,
-        UNIT_MOUNT,
-        UNIT_AUTOMOUNT,
-        UNIT_SNAPSHOT,
-        UNIT_TIMER,
-        UNIT_SWAP,
-        UNIT_PATH,
-        _UNIT_TYPE_MAX,
-        _UNIT_TYPE_INVALID = -1
-};
+#include "unit-name.h"
 
 enum UnitLoadState {
         UNIT_STUB,
index 4b52f7bc53a581a0944b92e24e27b6068494ee08..67a760ace68afef2d76a6595dce29f8f3f54b5d5 100644 (file)
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"            \
         ":-_.\\"
 
+static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
+        [UNIT_SERVICE] = "service",
+        [UNIT_SOCKET] = "socket",
+        [UNIT_TARGET] = "target",
+        [UNIT_DEVICE] = "device",
+        [UNIT_MOUNT] = "mount",
+        [UNIT_AUTOMOUNT] = "automount",
+        [UNIT_SNAPSHOT] = "snapshot",
+        [UNIT_TIMER] = "timer",
+        [UNIT_SWAP] = "swap",
+        [UNIT_PATH] = "path",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
+
 bool unit_name_is_valid_no_type(const char *n, bool template_ok) {
         const char *e, *i, *at;
 
index 13665c59802a239e44dda2b0f404080cf4aad8a4..4c793c5a7ef56da3ff59a71a17cea9c6d143f116 100644 (file)
 
 #define UNIT_NAME_MAX 256
 
+typedef enum UnitType UnitType;
+
+enum UnitType {
+        UNIT_SERVICE = 0,
+        UNIT_SOCKET,
+        UNIT_TARGET,
+        UNIT_DEVICE,
+        UNIT_MOUNT,
+        UNIT_AUTOMOUNT,
+        UNIT_SNAPSHOT,
+        UNIT_TIMER,
+        UNIT_SWAP,
+        UNIT_PATH,
+        _UNIT_TYPE_MAX,
+        _UNIT_TYPE_INVALID = -1
+};
+
+const char *unit_type_to_string(UnitType i);
+UnitType unit_type_from_string(const char *s);
+
 int unit_name_to_instance(const char *n, char **instance);
 char* unit_name_to_prefix(const char *n);
 char* unit_name_to_prefix_and_instance(const char *n);