1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the session class
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "project.hpp"
29 #include "session.hpp"
30 #include "lash_client.hpp"
34 std::list
<boost::shared_ptr
<project
> > projects
;
35 std::list
<boost::shared_ptr
<lash_client
> > clients
;
40 _impl_ptr
= new session_impl
;
51 boost::shared_ptr
<project
> project_ptr
;
53 _impl_ptr
->clients
.clear();
55 while (!_impl_ptr
->projects
.empty())
57 project_ptr
= _impl_ptr
->projects
.front();
58 _impl_ptr
->projects
.pop_front();
60 _signal_project_closed
.emit(project_ptr
);
66 boost::shared_ptr
<project
> project_ptr
)
68 _impl_ptr
->projects
.push_back(project_ptr
);
70 _signal_project_added
.emit(project_ptr
);
73 boost::shared_ptr
<project
>
74 session::find_project_by_name(
75 const std::string
& name
)
77 boost::shared_ptr
<project
> project_ptr
;
78 std::string temp_name
;
80 for (std::list
<boost::shared_ptr
<project
> >::iterator iter
= _impl_ptr
->projects
.begin(); iter
!= _impl_ptr
->projects
.end(); iter
++)
83 project_ptr
->get_name(temp_name
);
85 if (temp_name
== name
)
91 return boost::shared_ptr
<project
>();
95 session::project_close(
96 const std::string
& project_name
)
98 boost::shared_ptr
<project
> project_ptr
;
99 std::string temp_name
;
100 std::list
<boost::shared_ptr
<lash_client
> > clients
;
102 for (std::list
<boost::shared_ptr
<project
> >::iterator iter
= _impl_ptr
->projects
.begin(); iter
!= _impl_ptr
->projects
.end(); iter
++)
105 project_ptr
->get_name(temp_name
);
107 if (temp_name
== project_name
)
109 _impl_ptr
->projects
.erase(iter
);
110 _signal_project_closed
.emit(project_ptr
);
112 // remove clients from session, if not removed already
113 project_ptr
->get_clients(clients
);
114 for (std::list
<boost::shared_ptr
<lash_client
> >::iterator iter
= clients
.begin(); iter
!= clients
.end(); iter
++)
130 boost::shared_ptr
<lash_client
> client_ptr
)
132 _impl_ptr
->clients
.push_back(client_ptr
);
136 session::client_remove(
137 const std::string
& id
)
139 boost::shared_ptr
<lash_client
> client_ptr
;
142 for (std::list
<boost::shared_ptr
<lash_client
> >::iterator iter
= _impl_ptr
->clients
.begin(); iter
!= _impl_ptr
->clients
.end(); iter
++)
145 client_ptr
->get_id(temp_id
);
149 _impl_ptr
->clients
.erase(iter
);
155 boost::shared_ptr
<lash_client
>
156 session::find_client_by_id(const std::string
& id
)
158 boost::shared_ptr
<lash_client
> client_ptr
;
161 for (std::list
<boost::shared_ptr
<lash_client
> >::iterator iter
= _impl_ptr
->clients
.begin(); iter
!= _impl_ptr
->clients
.end(); iter
++)
164 client_ptr
->get_id(temp_id
);
172 return boost::shared_ptr
<lash_client
>();