lib: Add XdgAppRemoteRef subclass

This doesn't do anything yet, but its a place to hang remote-specific
ops off.
This commit is contained in:
Alexander Larsson
2015-12-04 15:33:00 +01:00
parent 1647c85d6f
commit a4df4ff811
8 changed files with 213 additions and 34 deletions

View File

@@ -6,6 +6,7 @@ public_headers = \
lib/xdg-app.h \
lib/xdg-app-ref.h \
lib/xdg-app-installed-ref.h \
lib/xdg-app-remote-ref.h \
lib/xdg-app-installation.h \
lib/xdg-app-remote.h \
lib/xdg-app-version-macros.h \
@@ -43,6 +44,7 @@ sources = \
lib/xdg-app-ref.c \
lib/xdg-app-installed-ref.c \
lib/xdg-app-installed-ref-private.h \
lib/xdg-app-remote-ref.c \
lib/xdg-app-remote-private.h \
lib/xdg-app-remote.c \
lib/xdg-app-installation.c \

View File

@@ -5,7 +5,7 @@ main (int argc, char *argv[])
{
XdgAppInstallation *installation;
XdgAppInstalledRef **apps;
XdgAppRef **refs;
XdgAppRemoteRef **refs;
XdgAppInstalledRef *app1;
XdgAppInstalledRef *app2;
XdgAppInstalledRef **runtimes;
@@ -98,11 +98,11 @@ main (int argc, char *argv[])
for (j = 0; refs[j] != NULL; j++)
{
g_print ("%d %s %s %s %s\n",
xdg_app_ref_get_kind (refs[j]),
xdg_app_ref_get_name (refs[j]),
xdg_app_ref_get_arch (refs[j]),
xdg_app_ref_get_version (refs[j]),
xdg_app_ref_get_commit (refs[j]));
xdg_app_ref_get_kind (XDG_APP_REF(refs[j])),
xdg_app_ref_get_name (XDG_APP_REF(refs[j])),
xdg_app_ref_get_arch (XDG_APP_REF(refs[j])),
xdg_app_ref_get_version (XDG_APP_REF(refs[j])),
xdg_app_ref_get_commit (XDG_APP_REF(refs[j])));
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright © 2015 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <alexl@redhat.com>
*/
#if !defined (__XDG_APP_H_INSIDE__) && !defined (XDG_APP_COMPILATION)
#error "Only <xdg-app.h> can be included remote_refectly."
#endif
#ifndef __XDG_APP_REMOTE_REF_PRIVATE_H__
#define __XDG_APP_REMOTE_REF_PRIVATE_H__
#include <xdg-app-remote-ref.h>
XdgAppRemoteRef *xdg_app_remote_ref_new (const char *full_ref,
const char *commit);
#endif /* __XDG_APP_REMOTE_REF_PRIVATE_H__ */

113
lib/xdg-app-remote-ref.c Normal file
View File

@@ -0,0 +1,113 @@
/*
* Copyright © 2015 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <alexl@redhat.com>
*/
#include "config.h"
#include <string.h>
#include "xdg-app-remote-ref.h"
#include "xdg-app-enum-types.h"
#include "xdg-app-error.h"
typedef struct _XdgAppRemoteRefPrivate XdgAppRemoteRefPrivate;
struct _XdgAppRemoteRefPrivate
{
int dummy;
};
G_DEFINE_TYPE_WITH_PRIVATE (XdgAppRemoteRef, xdg_app_remote_ref, XDG_APP_TYPE_REF)
enum {
PROP_0,
};
static void
xdg_app_remote_ref_finalize (GObject *object)
{
G_OBJECT_CLASS (xdg_app_remote_ref_parent_class)->finalize (object);
}
static void
xdg_app_remote_ref_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xdg_app_remote_ref_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xdg_app_remote_ref_class_init (XdgAppRemoteRefClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = xdg_app_remote_ref_get_property;
object_class->set_property = xdg_app_remote_ref_set_property;
object_class->finalize = xdg_app_remote_ref_finalize;
}
static void
xdg_app_remote_ref_init (XdgAppRemoteRef *self)
{
}
XdgAppRemoteRef *
xdg_app_remote_ref_new (const char *full_ref,
const char *commit)
{
XdgAppRefKind kind = XDG_APP_REF_KIND_APP;
g_auto(GStrv) parts = NULL;
parts = g_strsplit (full_ref, "/", -1);
if (strcmp (parts[0], "app") != 0)
kind = XDG_APP_REF_KIND_RUNTIME;
return g_object_new (XDG_APP_TYPE_REMOTE_REF,
"kind", kind,
"name", parts[1],
"arch", parts[2],
"version", parts[3],
"commit", commit,
NULL);
}

51
lib/xdg-app-remote-ref.h Normal file
View File

@@ -0,0 +1,51 @@
/*
* Copyright © 2015 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <alexl@redhat.com>
*/
#if !defined (__XDG_APP_H_INSIDE__) && !defined (XDG_APP_COMPILATION)
#error "Only <xdg-app.h> can be included remote_refectly."
#endif
#ifndef __XDG_APP_REMOTE_REF_H__
#define __XDG_APP_REMOTE_REF_H__
typedef struct XdgAppRemoteRef XdgAppRemoteRef;
#include <gio/gio.h>
#include <xdg-app-ref.h>
#define XDG_APP_TYPE_REMOTE_REF xdg_app_remote_ref_get_type()
#define XDG_APP_REMOTE_REF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XDG_APP_TYPE_REMOTE_REF, XdgAppRemoteRef))
#define XDG_APP_IS_REMOTE_REF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XDG_APP_TYPE_REMOTE_REF))
XDG_APP_EXTERN GType xdg_app_remote_ref_get_type (void);
struct XdgAppRemoteRef {
XdgAppRef parent;
};
typedef struct {
XdgAppRefClass parent_class;
} XdgAppRemoteRefClass;
#if !GLIB_CHECK_VERSION(2, 43, 4)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppRemoteRef, g_object_unref)
#endif
#endif /* __XDG_APP_REMOTE_REF_H__ */

View File

@@ -21,6 +21,7 @@
#include "config.h"
#include "xdg-app-remote-private.h"
#include "xdg-app-remote-ref-private.h"
#include "xdg-app-enum-types.h"
#include "xdg-app-utils.h"
@@ -170,28 +171,6 @@ xdg_app_remote_get_gpg_verify (XdgAppRemote *self)
return FALSE;
}
static XdgAppRef *
get_ref (XdgAppRemote *self,
const char *full_ref,
const char *commit)
{
g_auto(GStrv) parts = NULL;
XdgAppRefKind kind = XDG_APP_REF_KIND_APP;
parts = g_strsplit (full_ref, "/", -1);
if (strcmp (parts[0], "app") != 0)
kind = XDG_APP_REF_KIND_RUNTIME;
return g_object_new (XDG_APP_TYPE_REF,
"kind", kind,
"name", parts[1],
"arch", parts[2],
"version", parts[3],
"commit", commit,
NULL);
}
/**
* xdg_app_remote_list_refs:
* @self: a #XdgAppRemove
@@ -201,9 +180,9 @@ get_ref (XdgAppRemote *self,
* Lists all the refs in a #XdgAppRemote.
*
* Returns: (transfer full) (array zero-terminated=1): a %NULL-terminated array
* of #XdgAppRef instances
* of #XdgAppRemoteRef instances
*/
XdgAppRef **
XdgAppRemoteRef **
xdg_app_remote_list_refs (XdgAppRemote *self,
GCancellable *cancellable,
GError **error)
@@ -229,11 +208,11 @@ xdg_app_remote_list_refs (XdgAppRemote *self,
const char *checksum = value;
g_ptr_array_add (refs,
get_ref (self, refspec, checksum));
xdg_app_remote_ref_new (refspec, checksum));
}
g_ptr_array_add (refs, NULL);
return (XdgAppRef **)g_ptr_array_free (g_steal_pointer (&refs), FALSE);
return (XdgAppRemoteRef **)g_ptr_array_free (g_steal_pointer (&refs), FALSE);
}

View File

@@ -28,7 +28,7 @@
typedef struct XdgAppRemote XdgAppRemote;
#include <gio/gio.h>
#include <xdg-app-ref.h>
#include <xdg-app-remote-ref.h>
#define XDG_APP_TYPE_REMOTE xdg_app_remote_get_type()
#define XDG_APP_REMOTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XDG_APP_TYPE_REMOTE, XdgAppRemote))
@@ -54,7 +54,7 @@ XDG_APP_EXTERN char * xdg_app_remote_get_title (XdgAppRemote *self);
XDG_APP_EXTERN gboolean xdg_app_remote_get_gpg_verify (XdgAppRemote *self);
XDG_APP_EXTERN gboolean xdg_app_remote_get_noenumerate (XdgAppRemote *self);
XDG_APP_EXTERN XdgAppRef ** xdg_app_remote_list_refs (XdgAppRemote *self,
XDG_APP_EXTERN XdgAppRemoteRef **xdg_app_remote_list_refs (XdgAppRemote *self,
GCancellable *cancellable,
GError **error);

View File

@@ -29,6 +29,7 @@
#include <xdg-app-enum-types.h>
#include <xdg-app-ref.h>
#include <xdg-app-installed-ref.h>
#include <xdg-app-remote-ref.h>
#include <xdg-app-remote.h>
#include <xdg-app-installation.h>