Permalink
Browse files

Use a macro for *GetName()

Rename the older VERT_FUN_CCHARP_RES which is just too inscrutable. The
new name isn't much better: it returns several types of strings, not
just names.
  • Loading branch information...
1 parent 6d60212 commit 79d809b45e84533a13efb89bbbd7fc963ee5b617 @msantos committed Aug 26, 2012
Showing with 26 additions and 78 deletions.
  1. +18 −17 c_src/vert.h
  2. +1 −1 c_src/vert_connect.c
  3. +1 −17 c_src/vert_domain.c
  4. +2 −2 c_src/vert_interface.c
  5. +2 −21 c_src/vert_network.c
  6. +2 −20 c_src/vert_nwfilter.c
View
35 c_src/vert.h
@@ -171,23 +171,6 @@ vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
enif_make_int(env, n)); \
}
-#define VERT_FUN_CCHARP_RES(fun, type) \
- ERL_NIF_TERM \
-vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
-{ \
- VERT_RESOURCE *vp = NULL; \
- const char *p = NULL; \
- \
- VERT_GET_RESOURCE(0, vp, type); \
- \
- p = fun(vp->res); \
- \
- VERTERR(p == NULL); \
- \
- return enif_make_tuple2(env, atom_ok, \
- enif_make_string(env, p, ERL_NIF_LATIN1)); \
-}
-
#define VERT_FUN_CHARP_RES(fun, type) \
ERL_NIF_TERM \
vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
@@ -284,6 +267,24 @@ vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
return vert_make_resource(env, rp, tag); \
}
+#define VERT_FUN_GETNAME(fun, type) \
+ ERL_NIF_TERM \
+vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
+{ \
+ VERT_RESOURCE *rp = NULL; \
+ const char *name = NULL; \
+ \
+ VERT_GET_RESOURCE(0, rp, type); \
+ \
+ name = fun(rp->res); \
+ \
+ VERTERR(name == NULL); \
+ \
+ return enif_make_tuple2(env, \
+ atom_ok, \
+ enif_make_string(env, name, ERL_NIF_LATIN1)); \
+}
+
#define VERT_FUN_UNSUPPORTED(fun) \
ERL_NIF_TERM \
vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
View
2 c_src/vert_connect.c
@@ -51,7 +51,7 @@ VERT_FUN_INT_RES(virConnectNumOfNWFilters, VERT_RES_CONNECT)
VERT_FUN_UNSUPPORTED(virConnectNumOfNWFilters)
#endif
-VERT_FUN_CCHARP_RES(virConnectGetType, VERT_RES_CONNECT)
+VERT_FUN_GETNAME(virConnectGetType, VERT_RES_CONNECT)
VERT_FUN_CHARP_RES(virConnectGetCapabilities, VERT_RES_CONNECT)
VERT_FUN_CHARP_RES(virConnectGetHostname, VERT_RES_CONNECT)
View
18 c_src/vert_domain.c
@@ -42,6 +42,7 @@ VERT_FUN_INT_RES(virDomainSuspend, VERT_RES_DOMAIN)
VERT_FUN_INT_RES(virDomainUndefine, VERT_RES_DOMAIN)
VERT_FUN_DEFINEXML(virDomainDefineXML, VERT_RES_DOMAIN, atom_domain)
+VERT_FUN_GETNAME(virDomainGetName, VERT_RES_DOMAIN)
#if HAVE_VIRDOMAINCREATEWITHFLAGS
ERL_NIF_TERM
@@ -312,23 +313,6 @@ vert_virDomainGetMemoryParameters(ErlNifEnv *env, int argc, const ERL_NIF_TERM a
}
ERL_NIF_TERM
-vert_virDomainGetName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *dp = NULL;
- const char *name = NULL;
-
-
- VERT_GET_RESOURCE(0, dp, VERT_RES_DOMAIN);
-
- name = virDomainGetName(dp->res);
- VERTERR(name == NULL);
-
- return enif_make_tuple2(env,
- atom_ok,
- enif_make_string(env, name, ERL_NIF_LATIN1));
-}
-
- ERL_NIF_TERM
vert_virDomainGetOSType(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *dp = NULL;
View
4 c_src/vert_interface.c
@@ -36,8 +36,8 @@
VERT_FUN_INT_RES(virInterfaceUndefine, VERT_RES_INTERFACE)
-VERT_FUN_CCHARP_RES(virInterfaceGetMACString, VERT_RES_INTERFACE)
-VERT_FUN_CCHARP_RES(virInterfaceGetName, VERT_RES_INTERFACE)
+VERT_FUN_GETNAME(virInterfaceGetMACString, VERT_RES_INTERFACE)
+VERT_FUN_GETNAME(virInterfaceGetName, VERT_RES_INTERFACE)
ERL_NIF_TERM
View
23 c_src/vert_network.c
@@ -41,6 +41,8 @@ VERT_FUN_INT_RES(virNetworkUndefine, VERT_RES_NETWORK)
VERT_FUN_DEFINEXML(virNetworkDefineXML, VERT_RES_NETWORK, atom_network)
+VERT_FUN_GETNAME(virNetworkGetName, VERT_RES_NETWORK)
+
ERL_NIF_TERM
vert_virNetworkLookupByName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
@@ -114,27 +116,6 @@ vert_virNetworkGetBridgeName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]
}
ERL_NIF_TERM
-vert_virNetworkGetName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *np = NULL;
- const char *name = NULL;
-
- ERL_NIF_TERM term = {0};
-
-
- VERT_GET_RESOURCE(0, np, VERT_RES_NETWORK);
-
- name = virNetworkGetName(np->res);
- VERTERR(name == NULL);
-
- term = enif_make_string(env, name, ERL_NIF_LATIN1);
-
- return enif_make_tuple2(env,
- atom_ok,
- term);
-}
-
- ERL_NIF_TERM
vert_virNetworkGetUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *np = NULL;
View
22 c_src/vert_nwfilter.c
@@ -35,26 +35,8 @@
#ifdef HAVE_NWFILTER
VERT_FUN_INT_RES(virNWFilterUndefine, VERT_RES_NWFILTER)
-VERT_FUN_DEFINEXML(virNWFilterDefineXML, VERT_RES_NWFILTER, atom_nwfilter);
-
- ERL_NIF_TERM
-vert_virNWFilterGetName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *np = NULL;
- const char *name = NULL;
-
-
- VERT_GET_RESOURCE(0, np, VERT_RES_NWFILTER);
-
- name = virNWFilterGetName(np->res);
-
- VERTERR(name == NULL);
-
- return enif_make_tuple2(env,
- atom_ok,
- enif_make_string(env, name, ERL_NIF_LATIN1));
-}
-
+VERT_FUN_DEFINEXML(virNWFilterDefineXML, VERT_RES_NWFILTER, atom_nwfilter)
+VERT_FUN_GETNAME(virNWFilterGetName, VERT_RES_NWFILTER)
ERL_NIF_TERM
vert_virNWFilterGetUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])

0 comments on commit 79d809b

Please sign in to comment.