Example #1
0
// 1. user login first
// 2. old user not in meeting and online  --> send msg to he and replace he
// 3. old user not in meeting and offline --> replace he and online
// 4. old user in meeting and is not admin and online --> send msg to
// he and replace he and send meeting info to new user and online and
// into meeting and tell other user
// 5. old user in meeting and is admin and online -->  same 4
// 6. old user in meeting and is not admin and offline --> 4 (don't
// send msg to he)
// 7. old user in meeting and is admin and offline --> same 4(dont't
// sned msg to he)
int Msm::login(string id, string name, int sockfd)
{
        Member *m = new Member(id, name);
        Meeting *meeting = NULL;
        if (have_member(id)) {
                Member *m_old = get_member(id);
                m->set_volum(m_old->get_volum());
                m->set_status(m_old->get_status());

                // close old sockfd
                int old_fd;
                old_fd = m_old->get_sockfd();
                // send msg to old user
                if (m_old->is_online()) {
                        MsmReqMsg msg(id, "close", "duplicate user");
                        msg.send_msg(old_fd);
                }
                #if 1
                if (old_fd != -1 && old_fd != sockfd) {
                        if (epoll_ctl(epollfd, EPOLL_CTL_DEL, old_fd, &ev) == -1) {
                                LOG(LOG_ERROR, "epoll_ctl del %d failed: %s", old_fd, strerror(errno));
                                return errno;
                        }
                        close(old_fd);
                        m_old->set_sockfd(-1);
                        LOG(LOG_INFO, "close sockfd: %d", old_fd);
                }
                #endif
                // delete old user in meeting
                meeting = m_old->get_meeting();
                if (meeting != NULL) {
                        meeting->del_member(m_old);
                }

                // delete struct old user
                logout(m_old->get_id());
        }

        register_member(m);
        m->set_sockfd(sockfd);
        m->set_online();
        if (meeting != NULL) {
                /// TODO: send meeting info to user
                meeting->add_member(m);
        }

        LOG(LOG_DEBUG, "%s login", id.c_str());
        return 0;
}
Example #2
0
int Msm::create_meeting(string id, string name, vector<Member *>mem)
{
        if (have_meeting(id)) {
                LOG(LOG_ERROR, "meeting %s have exist.", id.c_str());
                return -1;
        }

        Meeting *m = new Meeting(id, name);

        vector<Member *>::iterator it;
        for (it = mem.begin(); it != mem.end(); ++ it) {
                if (m->add_member((*it)) == 0) {
                        (*it)->set_meeting(m);
                        (*it)->set_inmeeting();
                }
        }

        register_meeting(m);
        return 0;
}