1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* File: uiapi.cpp
*
* Author: Beat Forster (bfo@synthesis.ch)
*
* TUI_Api class
* Bridge to user programmable interface
*
* Copyright (c) 2007-2009 by Synthesis AG (www.synthesis.ch)
*
*/
/*
* The "TUI_Api" class acts as a standard interface between
* the SySync Server and a (user programmable) module "sync_uiapi".
*
* It is possible to have more than one (identical) interface module,
* either packed into a DLL or directly linked to the server
* (or combined).
*
*/
#include "uiapi.h"
#include "sync_uiapi.h"
namespace sysync {
/* ---- "DB_Api_Config" implementation ------------------------------------- */
TUI_Api:: TUI_Api() { fConnected= false; uCreated= false; } // constructor
TUI_Api::~TUI_Api() { /* empty */ } // destructor
/* Create a context */
TSyError TUI_Api::CreateContext( cAppCharP uiName, TDB_Api_Config &config )
{
typedef TSyError (*CreateU_Func)( CContext *uContext,
cAppCharP uiName,
DB_Callback uCB );
if (uCreated) return DB_Forbidden;
uName= uiName; // make a local copy
dm= &config.m; // assign reference to the methods
CreateU_Func p= (CreateU_Func)dm->ui.UI_CreateContext;
DB_Callback uCB= &fCB.Callback;
CContext* uc= &uCB->mContext; // store it at a temporary var
*uc= 0; // set it to check later, if changed
uCB->cContext= config.mContext; // inherit info
uContext= 0; uCB->mContext= config.fCB.Callback.mContext;
TSyError err= p( &uContext, uName.c_str(), uCB );
if (!err) {
uCreated= true;
if (*uc==0) *uc= uContext; // assign for datastores, but only if not assigned in plug-in module
} // if
return err;
} // CreateContext
// Run the UI API
TSyError TUI_Api::RunContext()
{
if (!uCreated) return DB_Forbidden;
Context_Func p= (Context_Func)dm->ui.UI_RunContext;
TSyError err= p( uContext );
return err;
} // RunContext
TSyError TUI_Api::DeleteContext()
{
if (!uCreated) return DB_Forbidden;
Context_Func p= (Context_Func)dm->ui.UI_DeleteContext;
TSyError err= p( uContext );
if (!err) uCreated= false;
return err;
} // DeleteContext
// Connect the UI API
TSyError TUI_Api::Connect( cAppCharP moduleName,
cAppCharP mContextName, bool aIsLib, bool allowDLL )
{
m= new TDB_Api_Config;
m->fCB= fCB;
CContext gContext= 0;
TSyError err= m->Connect( moduleName, gContext, mContextName, aIsLib,allowDLL );
if (!err) {
err= CreateContext( moduleName, *m );
} // if
if (err) delete m;
else fConnected= true;
printf( "TUI connected err=%d\n", err );
return err;
} // Connect
// Disconnect the UI API
TSyError TUI_Api::Disconnect()
{
if (!fConnected) return DB_Forbidden;
TSyError err= DeleteContext();
if (!err) {
err= m->Disconnect();
if (!err) { delete m; fConnected= false; }
} // if
printf( "TUI disconnected err=%d\n", err );
return err;
} // Disconnect
} // namespace
/* eof */
|