2 * Copyright (C) 2013 Andreas Steffen
3 * HSR 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
16 #include "imv_session.h"
18 #include <utils/debug.h>
20 typedef struct private_imv_session_t private_imv_session_t
;
23 * Private data of a imv_session_t object.
25 struct private_imv_session_t
{
28 * Public imv_session_t interface.
40 TNC_ConnectionID conn_id
;
43 * Have the workitems been generated?
48 * List of worklist items
50 linked_list_t
*workitems
;
59 METHOD(imv_session_t
, get_session_id
, int,
60 private_imv_session_t
*this)
62 return this->session_id
;
65 METHOD(imv_session_t
, get_connection_id
, TNC_ConnectionID
,
66 private_imv_session_t
*this)
71 METHOD(imv_session_t
, set_policy_started
, void,
72 private_imv_session_t
*this, bool start
)
74 this->policy_started
= start
;
77 METHOD(imv_session_t
, get_policy_started
, bool,
78 private_imv_session_t
*this)
80 return this->policy_started
;
83 METHOD(imv_session_t
, insert_workitem
, void,
84 private_imv_session_t
*this, imv_workitem_t
*workitem
)
86 this->workitems
->insert_last(this->workitems
, workitem
);
89 METHOD(imv_session_t
, remove_workitem
, void,
90 private_imv_session_t
*this, enumerator_t
*enumerator
)
92 this->workitems
->remove_at(this->workitems
, enumerator
);
95 METHOD(imv_session_t
, create_workitem_enumerator
, enumerator_t
*,
96 private_imv_session_t
*this)
98 if (!this->policy_started
)
102 return this->workitems
->create_enumerator(this->workitems
);
105 METHOD(imv_session_t
, get_workitem_count
, int,
106 private_imv_session_t
*this, TNC_IMVID imv_id
)
108 enumerator_t
*enumerator
;
109 imv_workitem_t
*workitem
;
112 enumerator
= this->workitems
->create_enumerator(this->workitems
);
113 while (enumerator
->enumerate(enumerator
, &workitem
))
115 if (workitem
->get_imv_id(workitem
) == imv_id
)
120 enumerator
->destroy(enumerator
);
125 METHOD(imv_session_t
, get_ref
, imv_session_t
*,
126 private_imv_session_t
*this)
130 return &this->public;
133 METHOD(imv_session_t
, destroy
, void,
134 private_imv_session_t
*this)
136 if (ref_put(&this->ref
))
138 this->workitems
->destroy_offset(this->workitems
,
139 offsetof(imv_workitem_t
, destroy
));
147 imv_session_t
*imv_session_create(int session_id
, TNC_ConnectionID conn_id
)
149 private_imv_session_t
*this;
153 .get_session_id
= _get_session_id
,
154 .get_connection_id
= _get_connection_id
,
155 .set_policy_started
= _set_policy_started
,
156 .get_policy_started
= _get_policy_started
,
157 .insert_workitem
= _insert_workitem
,
158 .remove_workitem
= _remove_workitem
,
159 .create_workitem_enumerator
= _create_workitem_enumerator
,
160 .get_workitem_count
= _get_workitem_count
,
164 .session_id
= session_id
,
166 .workitems
= linked_list_create(),
170 return &this->public;