2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 #include <collections/linked_list.h>
22 typedef struct private_manager_t private_manager_t
;
25 * private data of manager
27 struct private_manager_t
{
35 * underlying storage database
40 * user id, if we are logged in
50 METHOD(manager_t
, create_gateway_enumerator
, enumerator_t
*,
51 private_manager_t
*this)
53 return this->store
->create_gateway_enumerator(this->store
, this->user
);
56 METHOD(manager_t
, select_gateway
, gateway_t
*,
57 private_manager_t
*this, int select_id
)
61 enumerator_t
*enumerator
;
66 if (this->gateway
) this->gateway
->destroy(this->gateway
);
69 enumerator
= this->store
->create_gateway_enumerator(this->store
, this->user
);
70 while (enumerator
->enumerate(enumerator
, &id
, &name
, &port
, &address
))
76 this->gateway
= gateway_create_unix(name
);
80 host
= host_create_from_string(address
, port
);
83 this->gateway
= gateway_create_tcp(name
, host
);
89 enumerator
->destroy(enumerator
);
94 METHOD(manager_t
, logged_in
, bool,
95 private_manager_t
*this)
97 return this->user
!= 0;
100 METHOD(manager_t
, login
, bool,
101 private_manager_t
*this, char *username
, char *password
)
105 this->user
= this->store
->login(this->store
, username
, password
);
107 return this->user
!= 0;
110 METHOD(manager_t
, logout
, void,
111 private_manager_t
*this)
115 this->gateway
->destroy(this->gateway
);
116 this->gateway
= NULL
;
121 METHOD(context_t
, destroy
, void,
122 private_manager_t
*this)
124 if (this->gateway
) this->gateway
->destroy(this->gateway
);
131 manager_t
*manager_create(storage_t
*storage
)
133 private_manager_t
*this;
138 .logged_in
= _logged_in
,
140 .create_gateway_enumerator
= _create_gateway_enumerator
,
141 .select_gateway
= _select_gateway
,
149 return &this->public;