source: branches/gsoc11-statistics/base/src/cregistry/registry.h @ 140222

Last change on this file since 140222 was 105085, checked in by snc@…, 7 years ago

merge from trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/*
2 * registry.h
3 * vim:tw=80:expandtab
4 * $Id: registry.h 105085 2013-04-09 18:46:31Z snc@macports.org $
5 *
6 * Copyright (c) 2007 Chris Pickel <sfiera@macports.org>
7 * Copyright (c) 2012 The MacPorts Project
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30#ifndef _CREG_H
31#define _CREG_H
32
33#if HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include <sqlite3.h>
38#include <tcl.h>
39
40#define REG_NOT_FOUND       "registry::not-found"
41#define REG_INVALID         "registry::invalid"
42#define REG_CONSTRAINT      "registry::constraint"
43#define REG_SQLITE_ERROR    "registry::sqlite-error"
44#define REG_MISUSE          "registry::misuse"
45#define REG_CANNOT_INIT     "registry::cannot-init"
46#define REG_ALREADY_ACTIVE  "registry::already-active"
47
48typedef void reg_error_destructor(const char* description);
49
50typedef struct {
51    char* code;
52    const char* description;
53    reg_error_destructor* free;
54} reg_error;
55
56void reg_sqlite_error(sqlite3* db, reg_error* errPtr, char* query);
57void reg_error_destruct(reg_error* errPtr);
58void reg_throw(reg_error* errPtr, char* code, char* fmt, ...);
59
60typedef int (cast_function)(void* userdata, void** dst, void* src,
61        void* calldata, reg_error* errPtr);
62typedef void (free_function)(void* userdata, void* item);
63
64enum {
65    reg_none = 0,
66    reg_attached = 1,
67    reg_transacting = 2,
68    reg_can_write = 4
69};
70
71typedef struct {
72    sqlite3* db;
73    int status;
74    Tcl_HashTable open_entries;
75    Tcl_HashTable open_files;
76} reg_registry;
77
78int reg_open(reg_registry** regPtr, reg_error* errPtr);
79int reg_close(reg_registry* reg, reg_error* errPtr);
80
81int reg_attach(reg_registry* reg, const char* path, reg_error* errPtr);
82int reg_detach(reg_registry* reg, reg_error* errPtr);
83
84int reg_start_read(reg_registry* reg, reg_error* errPtr);
85int reg_start_write(reg_registry* reg, reg_error* errPtr);
86int reg_commit(reg_registry* reg, reg_error* errPtr);
87int reg_rollback(reg_registry* reg, reg_error* errPtr);
88
89int reg_vacuum(char* db_path);
90
91#endif /* _CREG_H */
Note: See TracBrowser for help on using the repository browser.