Permalink
Browse files

Convert *GetUUID/GetUUIDString to macros

  • Loading branch information...
1 parent 79d809b commit 7d525e12ced46e3cc65e38c5dd4ba3970cec86a1 @msantos committed Aug 26, 2012
Showing with 52 additions and 99 deletions.
  1. +35 −0 c_src/vert.h
  2. +2 −31 c_src/vert_domain.c
  3. +1 −0 c_src/vert_func.h
  4. +2 −20 c_src/vert_network.c
  5. +7 −6 c_src/vert_network.h
  6. +2 −41 c_src/vert_nwfilter.c
  7. +3 −1 src/vert.erl
View
35 c_src/vert.h
@@ -285,6 +285,41 @@ vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
enif_make_string(env, name, ERL_NIF_LATIN1)); \
}
+#define VERT_FUN_GETUUID(fun, type) \
+ ERL_NIF_TERM \
+vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
+{ \
+ VERT_RESOURCE *rp = NULL; \
+ ErlNifBinary uuid = {0}; \
+ \
+ VERT_GET_RESOURCE(0, rp, type); \
+ \
+ if (!enif_alloc_binary(VIR_UUID_BUFLEN, &uuid)) \
+ return error_tuple(env, atom_enomem); \
+ \
+ VERTERR(fun(rp->res, uuid.data) < 0); \
+ \
+ return enif_make_tuple2(env, \
+ atom_ok, \
+ enif_make_binary(env, &uuid)); \
+}
+
+#define VERT_FUN_GETUUIDSTRING(fun, type) \
+ ERL_NIF_TERM \
+vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
+{ \
+ VERT_RESOURCE *rp = NULL; \
+ char buf[VIR_UUID_STRING_BUFLEN] = {0}; \
+ \
+ VERT_GET_RESOURCE(0, rp, VERT_RES_NWFILTER); \
+ \
+ VERTERR(fun(rp->res, buf) < 0); \
+ \
+ return enif_make_tuple2(env, \
+ atom_ok, \
+ enif_make_string(env, buf, ERL_NIF_LATIN1)); \
+}
+
#define VERT_FUN_UNSUPPORTED(fun) \
ERL_NIF_TERM \
vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
View
33 c_src/vert_domain.c
@@ -43,6 +43,8 @@ VERT_FUN_INT_RES(virDomainUndefine, VERT_RES_DOMAIN)
VERT_FUN_DEFINEXML(virDomainDefineXML, VERT_RES_DOMAIN, atom_domain)
VERT_FUN_GETNAME(virDomainGetName, VERT_RES_DOMAIN)
+VERT_FUN_GETUUID(virDomainGetUUID, VERT_RES_DOMAIN)
+VERT_FUN_GETUUIDSTRING(virDomainGetUUIDString, VERT_RES_DOMAIN)
#if HAVE_VIRDOMAINCREATEWITHFLAGS
ERL_NIF_TERM
@@ -400,37 +402,6 @@ vert_virDomainGetSecurityLabel(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv
return enif_make_tuple2(env, atom_ok, buf);
}
- ERL_NIF_TERM
-vert_virDomainGetUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *dp = NULL;
- unsigned char uuid[VIR_UUID_BUFLEN];
- ERL_NIF_TERM buf = {0};
-
-
- VERT_GET_RESOURCE(0, dp, VERT_RES_DOMAIN);
-
- VERTERR(virDomainGetUUID(dp->res, uuid) < 0);
- BINCOPY(buf, &uuid, sizeof(VIR_UUID_BUFLEN));
-
- return enif_make_tuple2(env, atom_ok, buf);
-}
-
- ERL_NIF_TERM
-vert_virDomainGetUUIDString(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *dp = NULL;
- char uuid[VIR_UUID_STRING_BUFLEN];
-
-
- VERT_GET_RESOURCE(0, dp, VERT_RES_DOMAIN);
-
- VERTERR(virDomainGetUUIDString(dp->res, uuid) < 0);
-
- return enif_make_tuple2(env, atom_ok,
- enif_make_string(env, uuid, ERL_NIF_LATIN1));
-}
-
#ifdef HAVE_VIRDOMAINGETVCPUS
/*
ERL_NIF_TERM
View
1 c_src/vert_func.h
@@ -123,6 +123,7 @@ ErlNifFunc vert_funcs[] = {
{"virNetworkGetBridgeName", 1, vert_virNetworkGetBridgeName},
{"virNetworkGetName", 1, vert_virNetworkGetName},
{"virNetworkGetUUID", 1, vert_virNetworkGetUUID},
+ {"virNetworkGetUUIDString", 1, vert_virNetworkGetUUIDString},
{"virNetworkGetXMLDesc", 2, vert_virNetworkGetXMLDesc},
{"virNetworkIsPersistent", 1, vert_virNetworkIsPersistent},
{"virNetworkLookupByName", 2, vert_virNetworkLookupByName},
View
22 c_src/vert_network.c
@@ -42,6 +42,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)
+VERT_FUN_GETUUID(virNetworkGetUUID, VERT_RES_NETWORK)
+VERT_FUN_GETUUIDSTRING(virNetworkGetUUIDString, VERT_RES_NETWORK)
ERL_NIF_TERM
vert_virNetworkLookupByName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
@@ -116,26 +118,6 @@ vert_virNetworkGetBridgeName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]
}
ERL_NIF_TERM
-vert_virNetworkGetUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *np = NULL;
- unsigned char uuid[VIR_UUID_BUFLEN];
-
- ERL_NIF_TERM term = {0};
-
-
- VERT_GET_RESOURCE(0, np, VERT_RES_NETWORK);
-
- VERTERR(virNetworkGetUUID(np->res, uuid) < 0);
-
- BINCOPY(term, uuid, sizeof(uuid));
-
- return enif_make_tuple2(env,
- atom_ok,
- term);
-}
-
- ERL_NIF_TERM
vert_virNetworkGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *np = NULL;
View
13 c_src/vert_network.h
@@ -29,19 +29,20 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-ERL_NIF_TERM vert_virNetworkLookupByName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
-ERL_NIF_TERM vert_virNetworkLookupByUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
-ERL_NIF_TERM vert_virNetworkLookupByUUIDString(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM vert_virNetworkCreate(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM vert_virNetworkDefineXML(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM vert_virNetworkDestroy(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM vert_virNetworkGetAutostart(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM 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[]);
ERL_NIF_TERM vert_virNetworkGetUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM vert_virNetworkGetUUIDString(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM vert_virNetworkGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM vert_virNetworkIsPersistent(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
-ERL_NIF_TERM vert_virNetworkDefineXML(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM vert_virNetworkLookupByName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM vert_virNetworkLookupByUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM vert_virNetworkLookupByUUIDString(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM vert_virNetworkUndefine(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
-ERL_NIF_TERM vert_virNetworkCreate(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
-ERL_NIF_TERM vert_virNetworkDestroy(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM vert_network_res_res_ccharp(
ErlNifEnv *env,
View
43 c_src/vert_nwfilter.c
@@ -37,47 +37,8 @@
VERT_FUN_INT_RES(virNWFilterUndefine, VERT_RES_NWFILTER)
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[])
-{
- VERT_RESOURCE *np = NULL;
- ErlNifBinary uuid = {0};
- int rv = 0;
-
-
- VERT_GET_RESOURCE(0, np, VERT_RES_NWFILTER);
-
- if (!enif_alloc_binary(VIR_UUID_BUFLEN, &uuid))
- return error_tuple(env, atom_enomem);
-
- rv = virNWFilterGetUUID(np->res, uuid.data);
-
- VERTERR(rv < 0);
-
- return enif_make_tuple2(env,
- atom_ok,
- enif_make_binary(env, &uuid));
-}
-
- ERL_NIF_TERM
-vert_virNWFilterGetUUIDString(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *np = NULL;
- char buf[VIR_UUID_STRING_BUFLEN] = {0};
- int rv = 0;
-
-
- VERT_GET_RESOURCE(0, np, VERT_RES_NWFILTER);
-
- rv = virNWFilterGetUUIDString(np->res, buf);
-
- VERTERR(rv < 0);
-
- return enif_make_tuple2(env,
- atom_ok,
- enif_make_string(env, buf, ERL_NIF_LATIN1));
-}
+VERT_FUN_GETUUID(virNWFilterGetUUID, VERT_RES_NWFILTER)
+VERT_FUN_GETUUIDSTRING(virNWFilterGetUUIDString, VERT_RES_NWFILTER)
ERL_NIF_TERM
vert_virNWFilterGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
View
4 src/vert.erl
@@ -43,6 +43,7 @@
virNetworkIsPersistent/1,
virNetworkGetXMLDesc/2,
virNetworkGetUUID/1,
+ virNetworkGetUUIDString/1,
virNetworkGetName/1,
virNetworkGetBridgeName/1,
virNetworkGetAutostart/1,
@@ -371,7 +372,8 @@ virNetworkGetXMLDesc(#resource{type = network, res = Res}, Flags)
when is_integer(Flags) ->
call(virNetworkGetXMLDesc, [Res, Flags]).
-%virNetworkGetUUIDString(Network, Buf) ->
+virNetworkGetUUIDString(#resource{type = network, res = Res}) ->
+ call(virNetworkGetUUIDString, [Res]).
virNetworkGetUUID(#resource{type = network, res = Res}) ->
call(virNetworkGetUUID, [Res]).

0 comments on commit 7d525e1

Please sign in to comment.