diff --git a/K-observer_client_qt/CustomButton.h b/K-observer_client_qt/CustomButton.h new file mode 100644 index 0000000..fcfedd3 --- /dev/null +++ b/K-observer_client_qt/CustomButton.h @@ -0,0 +1,37 @@ +#ifndef CUSTOMBUTTON_H +#define CUSTOMBUTTON_H + +#include + +#include "observerclientmodel.h" + +class TCustomButton : public QPushButton +{ + Q_OBJECT +public: + + explicit TCustomButton(QWidget *parent=0) + : QPushButton(parent) + { + } + + explicit TCustomButton(const QString &text, QWidget *parent=0) + : QPushButton(text, parent) + { + } + + boost::function PressedHandler; + +protected: + + virtual void mouseReleaseEvent ( QMouseEvent * e ) + { + QAbstractButton::mouseReleaseEvent(e); + + PressedHandler(); + + } + +}; + +#endif // CUSTOMBUTTON_H diff --git a/K-observer_client_qt/K-observer_client.pro b/K-observer_client_qt/K-observer_client.pro new file mode 100644 index 0000000..ef1f7e0 --- /dev/null +++ b/K-observer_client_qt/K-observer_client.pro @@ -0,0 +1,42 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2012-08-22T11:32:24 +# +#------------------------------------------------- + +QT += core gui +QT += webkit + +CONFIG += no_keywords + +TARGET = K-observer_client +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + ../common/UserInfo.cpp \ + ../common/misc.cpp \ + ../common/MessageSender.cpp \ + observerclientmodel.cpp \ + ../common/ClientSocket.cpp \ + customtimer.cpp + +HEADERS += mainwindow.h \ + ../common/UserInfo.h \ + ../common/misc.h \ + ../common/MessageSender.h \ + observerclientmodel.h \ + ../common/ClientSocket.h \ + CustomButton.h \ + customtimer.h + +INCLUDEPATH += C:/Workplace/libs/boost_1_47_0/ +INCLUDEPATH += ../common/ + +LIBS += -LC:/Workplace/libs/boost_1_47_0/boost_windows/libs_engine/debug/ +LIBS += -LC:/Workplace/libs/boost_1_47_0/boost_windows/libs_engine/release/ + + + +FORMS += mainwindow.ui diff --git a/K-observer_client_qt/Release/release/QtCore4.dll b/K-observer_client_qt/Release/release/QtCore4.dll new file mode 100644 index 0000000..813845d Binary files /dev/null and b/K-observer_client_qt/Release/release/QtCore4.dll differ diff --git a/K-observer_client_qt/Release/release/QtGui4.dll b/K-observer_client_qt/Release/release/QtGui4.dll new file mode 100644 index 0000000..ccc25d9 Binary files /dev/null and b/K-observer_client_qt/Release/release/QtGui4.dll differ diff --git a/K-observer_client_qt/Release/release/QtNetwork4.dll b/K-observer_client_qt/Release/release/QtNetwork4.dll new file mode 100644 index 0000000..d1eee2d Binary files /dev/null and b/K-observer_client_qt/Release/release/QtNetwork4.dll differ diff --git a/K-observer_client_qt/Release/release/QtWebKit4.dll b/K-observer_client_qt/Release/release/QtWebKit4.dll new file mode 100644 index 0000000..77a7e81 Binary files /dev/null and b/K-observer_client_qt/Release/release/QtWebKit4.dll differ diff --git a/K-observer_client_qt/Release/ui_mainwindow.h b/K-observer_client_qt/Release/ui_mainwindow.h new file mode 100644 index 0000000..c336717 --- /dev/null +++ b/K-observer_client_qt/Release/ui_mainwindow.h @@ -0,0 +1,240 @@ +/******************************************************************************** +** Form generated from reading UI file 'mainwindow.ui' +** +** Created: Sat 25. Aug 20:45:30 2012 +** by: Qt User Interface Compiler version 4.8.1 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_MAINWINDOW_H +#define UI_MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "custombutton.h" + +QT_BEGIN_NAMESPACE + +class Ui_MainWindow +{ +public: + QWidget *centralWidget; + TCustomButton *ConnectButton; + QLineEdit *AddressField; + QLineEdit *LastNameField; + QLabel *label; + QLabel *label_2; + QLineEdit *FirstNameField; + QLabel *label_3; + QLineEdit *MiddleNameField; + QLabel *label_4; + QLineEdit *PhoneNumberField; + QSpinBox *UikSpinBox; + QLabel *label_5; + QComboBox *StatusComboBox; + QLabel *label_6; + TCustomButton *UpdateDataButton; + QWebView *webView; + QDoubleSpinBox *PosXSpinBox; + QDoubleSpinBox *PosYSpinBox; + QLabel *label_7; + QLabel *label_8; + QComboBox *MapStateComboBox; + QPushButton *AlarmButton; + QLineEdit *PortField; + TCustomButton *DisconnectButton; + TCustomButton *MapTypeButton; + QComboBox *MapTypeComboBox; + QTextEdit *ChatList; + QLineEdit *ChatTextLine; + TCustomButton *ChatSendButton; + QMenuBar *menuBar; + QToolBar *mainToolBar; + QStatusBar *statusBar; + + void setupUi(QMainWindow *MainWindow) + { + if (MainWindow->objectName().isEmpty()) + MainWindow->setObjectName(QString::fromUtf8("MainWindow")); + MainWindow->resize(646, 543); + centralWidget = new QWidget(MainWindow); + centralWidget->setObjectName(QString::fromUtf8("centralWidget")); + ConnectButton = new TCustomButton(centralWidget); + ConnectButton->setObjectName(QString::fromUtf8("ConnectButton")); + ConnectButton->setGeometry(QRect(10, 30, 91, 23)); + AddressField = new QLineEdit(centralWidget); + AddressField->setObjectName(QString::fromUtf8("AddressField")); + AddressField->setGeometry(QRect(10, 10, 111, 20)); + LastNameField = new QLineEdit(centralWidget); + LastNameField->setObjectName(QString::fromUtf8("LastNameField")); + LastNameField->setGeometry(QRect(10, 110, 113, 20)); + label = new QLabel(centralWidget); + label->setObjectName(QString::fromUtf8("label")); + label->setGeometry(QRect(10, 90, 46, 13)); + label_2 = new QLabel(centralWidget); + label_2->setObjectName(QString::fromUtf8("label_2")); + label_2->setGeometry(QRect(10, 140, 46, 13)); + FirstNameField = new QLineEdit(centralWidget); + FirstNameField->setObjectName(QString::fromUtf8("FirstNameField")); + FirstNameField->setGeometry(QRect(10, 160, 113, 20)); + label_3 = new QLabel(centralWidget); + label_3->setObjectName(QString::fromUtf8("label_3")); + label_3->setGeometry(QRect(10, 190, 71, 16)); + MiddleNameField = new QLineEdit(centralWidget); + MiddleNameField->setObjectName(QString::fromUtf8("MiddleNameField")); + MiddleNameField->setGeometry(QRect(10, 210, 113, 20)); + label_4 = new QLabel(centralWidget); + label_4->setObjectName(QString::fromUtf8("label_4")); + label_4->setGeometry(QRect(10, 240, 121, 16)); + PhoneNumberField = new QLineEdit(centralWidget); + PhoneNumberField->setObjectName(QString::fromUtf8("PhoneNumberField")); + PhoneNumberField->setGeometry(QRect(10, 260, 113, 20)); + UikSpinBox = new QSpinBox(centralWidget); + UikSpinBox->setObjectName(QString::fromUtf8("UikSpinBox")); + UikSpinBox->setGeometry(QRect(10, 310, 111, 22)); + label_5 = new QLabel(centralWidget); + label_5->setObjectName(QString::fromUtf8("label_5")); + label_5->setGeometry(QRect(10, 290, 121, 16)); + StatusComboBox = new QComboBox(centralWidget); + StatusComboBox->setObjectName(QString::fromUtf8("StatusComboBox")); + StatusComboBox->setGeometry(QRect(10, 360, 131, 22)); + label_6 = new QLabel(centralWidget); + label_6->setObjectName(QString::fromUtf8("label_6")); + label_6->setGeometry(QRect(10, 340, 121, 16)); + UpdateDataButton = new TCustomButton(centralWidget); + UpdateDataButton->setObjectName(QString::fromUtf8("UpdateDataButton")); + UpdateDataButton->setGeometry(QRect(10, 390, 131, 23)); + webView = new QWebView(centralWidget); + webView->setObjectName(QString::fromUtf8("webView")); + webView->setGeometry(QRect(220, 10, 401, 251)); + webView->setUrl(QUrl(QString::fromUtf8("about:blank"))); + PosXSpinBox = new QDoubleSpinBox(centralWidget); + PosXSpinBox->setObjectName(QString::fromUtf8("PosXSpinBox")); + PosXSpinBox->setGeometry(QRect(262, 270, 81, 22)); + PosXSpinBox->setDecimals(6); + PosXSpinBox->setSingleStep(0.001); + PosXSpinBox->setValue(37.4432); + PosYSpinBox = new QDoubleSpinBox(centralWidget); + PosYSpinBox->setObjectName(QString::fromUtf8("PosYSpinBox")); + PosYSpinBox->setGeometry(QRect(372, 270, 81, 22)); + PosYSpinBox->setDecimals(6); + PosYSpinBox->setSingleStep(0.01); + PosYSpinBox->setValue(55.8889); + label_7 = new QLabel(centralWidget); + label_7->setObjectName(QString::fromUtf8("label_7")); + label_7->setGeometry(QRect(242, 270, 16, 16)); + label_8 = new QLabel(centralWidget); + label_8->setObjectName(QString::fromUtf8("label_8")); + label_8->setGeometry(QRect(352, 270, 16, 16)); + MapStateComboBox = new QComboBox(centralWidget); + MapStateComboBox->setObjectName(QString::fromUtf8("MapStateComboBox")); + MapStateComboBox->setGeometry(QRect(462, 270, 151, 22)); + AlarmButton = new QPushButton(centralWidget); + AlarmButton->setObjectName(QString::fromUtf8("AlarmButton")); + AlarmButton->setGeometry(QRect(432, 310, 181, 23)); + PortField = new QLineEdit(centralWidget); + PortField->setObjectName(QString::fromUtf8("PortField")); + PortField->setGeometry(QRect(130, 10, 61, 20)); + DisconnectButton = new TCustomButton(centralWidget); + DisconnectButton->setObjectName(QString::fromUtf8("DisconnectButton")); + DisconnectButton->setGeometry(QRect(110, 30, 75, 23)); + MapTypeButton = new TCustomButton(centralWidget); + MapTypeButton->setObjectName(QString::fromUtf8("MapTypeButton")); + MapTypeButton->setGeometry(QRect(332, 300, 75, 23)); + MapTypeComboBox = new QComboBox(centralWidget); + MapTypeComboBox->setObjectName(QString::fromUtf8("MapTypeComboBox")); + MapTypeComboBox->setGeometry(QRect(230, 300, 91, 22)); + ChatList = new QTextEdit(centralWidget); + ChatList->setObjectName(QString::fromUtf8("ChatList")); + ChatList->setGeometry(QRect(230, 340, 381, 111)); + ChatList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ChatList->setReadOnly(true); + ChatTextLine = new QLineEdit(centralWidget); + ChatTextLine->setObjectName(QString::fromUtf8("ChatTextLine")); + ChatTextLine->setGeometry(QRect(230, 460, 301, 20)); + ChatSendButton = new TCustomButton(centralWidget); + ChatSendButton->setObjectName(QString::fromUtf8("ChatSendButton")); + ChatSendButton->setGeometry(QRect(540, 460, 75, 23)); + MainWindow->setCentralWidget(centralWidget); + menuBar = new QMenuBar(MainWindow); + menuBar->setObjectName(QString::fromUtf8("menuBar")); + menuBar->setGeometry(QRect(0, 0, 646, 21)); + MainWindow->setMenuBar(menuBar); + mainToolBar = new QToolBar(MainWindow); + mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); + MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar); + statusBar = new QStatusBar(MainWindow); + statusBar->setObjectName(QString::fromUtf8("statusBar")); + MainWindow->setStatusBar(statusBar); + + retranslateUi(MainWindow); + + QMetaObject::connectSlotsByName(MainWindow); + } // setupUi + + void retranslateUi(QMainWindow *MainWindow) + { + MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); + ConnectButton->setText(QApplication::translate("MainWindow", "\320\237\320\276\320\264\320\272\320\273\321\216\321\207\320\270\321\202\321\214\321\201\321\217", 0, QApplication::UnicodeUTF8)); + AddressField->setText(QApplication::translate("MainWindow", "127.0.0.1", 0, QApplication::UnicodeUTF8)); + LastNameField->setText(QApplication::translate("MainWindow", "\320\230\320\262\320\260\320\275\320\276\320\262", 0, QApplication::UnicodeUTF8)); + label->setText(QApplication::translate("MainWindow", "\320\244\320\260\320\274\320\270\320\273\320\270\321\217:", 0, QApplication::UnicodeUTF8)); + label_2->setText(QApplication::translate("MainWindow", "\320\230\320\274\321\217:", 0, QApplication::UnicodeUTF8)); + FirstNameField->setText(QApplication::translate("MainWindow", "\320\230\320\262\320\260\320\275", 0, QApplication::UnicodeUTF8)); + label_3->setText(QApplication::translate("MainWindow", "\320\236\321\202\321\207\320\265\321\201\321\202\320\262\320\276:", 0, QApplication::UnicodeUTF8)); + MiddleNameField->setText(QApplication::translate("MainWindow", "\320\230\320\262\320\260\320\275\320\276\320\262\320\270\321\207", 0, QApplication::UnicodeUTF8)); + label_4->setText(QApplication::translate("MainWindow", "\320\232\320\276\320\275\321\202\320\260\320\272\321\202\320\275\321\213\320\271 \321\202\320\265\320\273\320\265\321\204\320\276\320\275:", 0, QApplication::UnicodeUTF8)); + PhoneNumberField->setText(QApplication::translate("MainWindow", "1111", 0, QApplication::UnicodeUTF8)); + label_5->setText(QApplication::translate("MainWindow", "\320\235\320\276\320\274\320\265\321\200 \320\243\320\230\320\232:", 0, QApplication::UnicodeUTF8)); + StatusComboBox->clear(); + StatusComboBox->insertItems(0, QStringList() + << QApplication::translate("MainWindow", "\320\235\320\260\320\261\320\273\321\216\320\264\320\260\321\202\320\265\320\273\321\214", 0, QApplication::UnicodeUTF8) + << QApplication::translate("MainWindow", "\320\234\320\276\320\261\320\270\320\273\321\214\320\275\320\260\321\217 \320\263\321\200\321\203\320\277\320\277\320\260", 0, QApplication::UnicodeUTF8) + ); + label_6->setText(QApplication::translate("MainWindow", "\320\241\321\202\320\260\321\202\321\203\321\201:", 0, QApplication::UnicodeUTF8)); + UpdateDataButton->setText(QApplication::translate("MainWindow", "\320\236\320\261\320\275\320\276\320\262\320\270\321\202\321\214 \320\270\320\275\321\204\320\276\321\200\320\274\320\260\321\206\320\270\321\216", 0, QApplication::UnicodeUTF8)); + label_7->setText(QApplication::translate("MainWindow", "X:", 0, QApplication::UnicodeUTF8)); + label_8->setText(QApplication::translate("MainWindow", "Y:", 0, QApplication::UnicodeUTF8)); + MapStateComboBox->clear(); + MapStateComboBox->insertItems(0, QStringList() + << QApplication::translate("MainWindow", "\320\241\320\276\321\201\321\202\320\276\321\217\320\275\320\270\320\265 \320\275\320\276\321\200\320\274", 0, QApplication::UnicodeUTF8) + << QApplication::translate("MainWindow", "\320\241\320\276\321\201\321\202\320\276\321\217\320\275\320\270\320\265 \321\202\321\200\320\265\320\262\320\276\320\263\320\260", 0, QApplication::UnicodeUTF8) + ); + AlarmButton->setText(QApplication::translate("MainWindow", "\320\237\320\276\321\201\320\273\320\260\321\202\321\214 \321\201\320\270\320\263\320\275\320\260\320\273 \321\202\321\200\320\265\320\262\320\276\320\263\320\270", 0, QApplication::UnicodeUTF8)); + PortField->setText(QApplication::translate("MainWindow", "1984", 0, QApplication::UnicodeUTF8)); + DisconnectButton->setText(QApplication::translate("MainWindow", "PushButton", 0, QApplication::UnicodeUTF8)); + MapTypeButton->setText(QApplication::translate("MainWindow", "\320\222\321\213\320\261\321\200\320\260\321\202\321\214", 0, QApplication::UnicodeUTF8)); + MapTypeComboBox->clear(); + MapTypeComboBox->insertItems(0, QStringList() + << QApplication::translate("MainWindow", "\320\236\320\261\321\211\320\260\321\217 \320\272\320\260\321\200\321\202\320\260", 0, QApplication::UnicodeUTF8) + << QApplication::translate("MainWindow", "\320\232\320\260\321\200\321\202\320\260 \321\202\321\200\320\265\320\262\320\276\320\263\320\270", 0, QApplication::UnicodeUTF8) + ); + ChatSendButton->setText(QApplication::translate("MainWindow", "\320\236\321\202\320\277\321\200\320\260\320\262\320\270\321\202\321\214", 0, QApplication::UnicodeUTF8)); + } // retranslateUi + +}; + +namespace Ui { + class MainWindow: public Ui_MainWindow {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_MAINWINDOW_H diff --git a/K-observer_client_qt/customtimer.cpp b/K-observer_client_qt/customtimer.cpp new file mode 100644 index 0000000..c0824ee --- /dev/null +++ b/K-observer_client_qt/customtimer.cpp @@ -0,0 +1,15 @@ +#include "customtimer.h" + +#include "observerclientmodel.h" + +CustomTimer::CustomTimer(QObject *parent) + : QTimer(parent) +{ +} + + +void CustomTimer::timerEvent ( QTimerEvent * e ) +{ + + TimerSignal(); +} diff --git a/K-observer_client_qt/customtimer.h b/K-observer_client_qt/customtimer.h new file mode 100644 index 0000000..3fc492e --- /dev/null +++ b/K-observer_client_qt/customtimer.h @@ -0,0 +1,20 @@ +#ifndef CUSTOMTIMER_H +#define CUSTOMTIMER_H + +#include +#include +#include "UserInfo.h" +class CustomTimer : public QTimer +{ + Q_OBJECT +public: + explicit CustomTimer(QObject *parent = 0); + + boost::signal TimerSignal; + +protected: + virtual void timerEvent ( QTimerEvent * e ); + +}; + +#endif // CUSTOMTIMER_H diff --git a/K-observer_client_qt/main.cpp b/K-observer_client_qt/main.cpp new file mode 100644 index 0000000..7cfc0a8 --- /dev/null +++ b/K-observer_client_qt/main.cpp @@ -0,0 +1,38 @@ +#include +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "observerclientmodel.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + TObserverClientModel observerClient; + + w.ObserverClientModel = &observerClient; + observerClient.MainWindowPtr = &w; + + w.OpenMap(); + + w.GetUi()->ConnectButton->PressedHandler = boost::bind(&TObserverClientModel::OnConnectButtonPressed, &observerClient); + w.GetUi()->UpdateDataButton->PressedHandler = boost::bind(&TObserverClientModel::OnUpdateInfoButtonPressed, &observerClient); + + + w.GetUi()->DisconnectButton->PressedHandler = boost::bind(&TObserverClientModel::Finish, &observerClient); + + w.GetUi()->MapTypeButton->PressedHandler = boost::bind(&TObserverClientModel::OnChangeMapTypeButtonPressed, &observerClient); + + w.GetUi()->ChatSendButton->PressedHandler = boost::bind(&TObserverClientModel::OnChatSendClick, &observerClient); + + w.GetUi()->AlarmButton->PressedHandler = boost::bind(&TObserverClientModel::OnSendAlarmClick, &observerClient); + + w.GetUi()->KickButton->PressedHandler = boost::bind(&TObserverClientModel::OnKickPlayerClick, &observerClient); + + w.GetUi()->SelectPlayerButton->PressedHandler = boost::bind(&TObserverClientModel::OnSelectPlayerClick, &observerClient); + + + + return a.exec(); +} diff --git a/K-observer_client_qt/mainwindow.cpp b/K-observer_client_qt/mainwindow.cpp new file mode 100644 index 0000000..79f1999 --- /dev/null +++ b/K-observer_client_qt/mainwindow.cpp @@ -0,0 +1,35 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + + delete ui; +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + if (ObserverClientModel->Connected) + { + ObserverClientModel->Finish(); + } + event->accept(); +} + + +void MainWindow::OpenMap() +{ + QUrl url("C:/Workplace/Projects/k_observer/K-observer_client_qt/script.html"); + + ui->webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); + ui->webView->load(url); + +} diff --git a/K-observer_client_qt/mainwindow.h b/K-observer_client_qt/mainwindow.h new file mode 100644 index 0000000..9a8efb4 --- /dev/null +++ b/K-observer_client_qt/mainwindow.h @@ -0,0 +1,39 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class TObserverClientModel; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + + + Ui::MainWindow* GetUi() + { + return ui; + } + + void OpenMap(); + + TObserverClientModel* ObserverClientModel; + + +protected: + void closeEvent(QCloseEvent *event); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/K-observer_client_qt/mainwindow.ui b/K-observer_client_qt/mainwindow.ui new file mode 100644 index 0000000..c9a7634 --- /dev/null +++ b/K-observer_client_qt/mainwindow.ui @@ -0,0 +1,605 @@ + + + MainWindow + + + + 0 + 0 + 846 + 607 + + + + MainWindow + + + + + + 10 + 30 + 91 + 23 + + + + Подключиться + + + false + + + + + + 10 + 10 + 111 + 20 + + + + 127.0.0.1 + + + + + + 10 + 110 + 113 + 20 + + + + Иванов + + + + + + 10 + 90 + 46 + 13 + + + + Фамилия: + + + + + + 10 + 140 + 46 + 13 + + + + Имя: + + + + + + 10 + 160 + 113 + 20 + + + + Иван + + + + + + 10 + 190 + 71 + 16 + + + + Отчество: + + + + + + 10 + 210 + 113 + 20 + + + + Иванович + + + + + + 10 + 240 + 121 + 16 + + + + Контактный телефон: + + + + + + 10 + 260 + 113 + 20 + + + + 1111 + + + + + + 10 + 310 + 111 + 22 + + + + + + + 10 + 290 + 121 + 16 + + + + Номер УИК: + + + + + + 10 + 360 + 131 + 22 + + + + + Наблюдатель + + + + + Мобильная группа + + + + + + + 10 + 340 + 121 + 16 + + + + Статус: + + + + + + 10 + 390 + 131 + 23 + + + + Обновить информацию + + + + + + 220 + 10 + 401 + 251 + + + + + about:blank + + + + + + + 262 + 270 + 81 + 22 + + + + 6 + + + 0.001000000000000 + + + 30.215800000000002 + + + + + + 372 + 270 + 81 + 22 + + + + 6 + + + 0.001000000000000 + + + 60.005200000000002 + + + + + + 242 + 270 + 16 + 16 + + + + X: + + + + + + 352 + 270 + 16 + 16 + + + + Y: + + + + + + 462 + 270 + 151 + 22 + + + + + Состояние норм + + + + + Состояние тревога + + + + + + + 432 + 310 + 181 + 23 + + + + Послать сигнал тревоги + + + + + + 130 + 10 + 61 + 20 + + + + 1984 + + + + + + 110 + 30 + 91 + 23 + + + + Отключиться + + + + + + 332 + 300 + 75 + 23 + + + + Выбрать + + + + + + 230 + 300 + 91 + 22 + + + + + Общая карта + + + + + Карта тревоги + + + + + + + 230 + 340 + 381 + 111 + + + + Qt::ScrollBarAlwaysOn + + + true + + + + + + 230 + 460 + 301 + 20 + + + + + + + 540 + 460 + 75 + 23 + + + + Отправить + + + + + + 630 + 10 + 211 + 191 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 70 + 0 + 46 + 13 + + + + Админка: + + + + + + 70 + 160 + 75 + 23 + + + + Кикнуть + + + + + + 10 + 50 + 171 + 20 + + + + + + + 10 + 90 + 171 + 20 + + + + + + + 10 + 130 + 171 + 20 + + + + + + + 10 + 70 + 46 + 13 + + + + Имя: + + + + + + 10 + 30 + 46 + 13 + + + + Фамилия: + + + + + + 10 + 110 + 61 + 16 + + + + Отчество: + + + + + + + 630 + 210 + 181 + 191 + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOn + + + + + + 660 + 400 + 75 + 23 + + + + Выбрать + + + + + + + 0 + 0 + 846 + 21 + + + + + + TopToolBarArea + + + false + + + + + + + + QWebView + QWidget +
QtWebKit/QWebView
+
+ + TCustomButton + QPushButton +
custombutton.h
+
+
+ + +
diff --git a/K-observer_client_qt/observerclientmodel.cpp b/K-observer_client_qt/observerclientmodel.cpp new file mode 100644 index 0000000..8121d1a --- /dev/null +++ b/K-observer_client_qt/observerclientmodel.cpp @@ -0,0 +1,390 @@ +#include "observerclientmodel.h" +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include + +QString +ws2qs(const std::wstring& str) +{ + return (QString((const QChar*)str.c_str(), str.length())); +} + +// Convert a QString to a wstring +std::wstring +qs2ws(const QString& str) +{ + return (std::wstring((wchar_t*)str.unicode(), str.length())); +} + + +TObserverClientModel::TObserverClientModel(QObject *parent) + : QObject(parent) + , MapType(0) + , Connected(false) +{ +} + + +void TObserverClientModel::Start(std::string address, std::string port) +{ + if (!Connected) + { + ClientSocket = boost::shared_ptr(new TClientSocket(IoService)); + + ClientSocket->ReceiveMapSignal.connect(boost::bind(&TObserverClientModel::OnReceiveMapUpdate, this, _1)); + + ClientSocket->ReceiveAlarmMapSignal.connect(boost::bind(&TObserverClientModel::OnReceiveAlarmMapUpdate, this, _1)); + + ClientSocket->ReceiveForceCloseSignal.connect(boost::bind(&TObserverClientModel::OnSocketClosed, this)); + + ClientSocket->ReceiveMessageSignal.connect(boost::bind(&TObserverClientModel::OnReceiveChatMessage, this, _1, _2)); + + ClientSocket->ReceiveAutorizationSentSignal.connect(boost::bind(&TObserverClientModel::OnAutorizationSent, this)); + + ClientSocket->Open(address, port); + + IoServiceThread = boost::thread(boost::bind(&TObserverClientModel::DoRunIoService, this)); + + Timer.TimerSignal.connect(boost::bind(&TObserverClientModel::OnUpdateMapTimer, this)); + + Timer.start(1000); + + Connected = true; + } +} + +void TObserverClientModel::OnAutorizationSent() +{ + + RestartHeartbeatTimer(); + RestartMapHeartbeatTimer(); + +} + +void TObserverClientModel::RestartHeartbeatTimer() +{ + HeartbeatTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3))); + + HeartbeatTimer->async_wait(boost::bind(&TObserverClientModel::OnHeartbeat, this, boost::asio::placeholders::error)); + +} + +void TObserverClientModel::RestartMapHeartbeatTimer() +{ + MapHeartbeatTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3))); + + MapHeartbeatTimer->async_wait(boost::bind(&TObserverClientModel::OnMapHeartbeat, this, boost::asio::placeholders::error)); + +} + + +void TObserverClientModel::Finish() +{ + if (Connected) + { + Connected = false; + + Timer.stop(); + HeartbeatTimer->cancel(); + MapHeartbeatTimer->cancel(); + + ClientSocket->CloseImmediate(); + } + + + +} + +void TObserverClientModel::OnSocketClosed() +{ + //ClientSocket->BlockCloseOnError = true; + //ClientSocket->CloseImmediate(); + ClientSocket = boost::shared_ptr(); +} + +void TObserverClientModel::OnUpdateMapTimer() +{ + UpdatingMapMutex.lock(); + + MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("Clear();"); + + if (MapType == 0) + { + + + for (std::vector::iterator i = UserInfoArr.begin(); i != UserInfoArr.end(); ++i) + { + QString posX = QString::number( i->PosX ); + QString posY = QString::number( i->PosY ); + QString mapState = QString::number(i->MapState); + + if (i->PosX != 0.f && i->PosY != 0.f) + { + MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarker("+posX+", "+posY+", "+ mapState + ");"); + } + } + } + else + { + MainWindowPtr->GetUi()->PlayerListWidget->clear(); + + for (std::vector::iterator i = AlarmUserInfoArr.begin(); i != AlarmUserInfoArr.end(); ++i) + { + QString posX = QString::number( i->PosX ); + QString posY = QString::number( i->PosY ); + QString mapState = QString::number(i->MapState); + + + + std::wstring Uik = L" "; + std::wstring StateHeader = L": "; + + QString lastName = QString::fromUtf8(i->LastName.c_str()); + QString firstName = QString::fromUtf8(i->FirstName.c_str()); + QString middleName = QString::fromUtf8(i->MiddleName.c_str()); + + QString text = ws2qs(Uik); + text = text + QString::number(i->Uik)+"\\n"; + text = text + lastName; + text = text +"\\n" + firstName; + text = text + "\\n"+middleName; + text = text + "\\n"+QString::fromUtf8(i->PhoneNumber.c_str()); + text = text + "\\n"; + text = text +ws2qs(StateHeader); + + std::wstring State; + + if (i->MapState == 2) + { + State = L""; + } + else if (i->MapState == 3) + { + State = L" - "; + } + else if (i->MapState == 4) + { + State = L" - "; + } + else if (i->MapState == 5) + { + State = L" - "; + } + else if (i->MapState == 6) + { + State = L" - "; + } + + text += ws2qs(State); + + if (i->PosX != 0.f && i->PosY != 0.f) + { + MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarkerWithPopup("+posX+", "+posY+", "+ mapState + ", \"" +text+ "\");"); + } + MainWindowPtr->GetUi()->PlayerListWidget->addItem(QString("LastName: "+lastName + " FirstName: " + firstName+" MiddleName: "+middleName)); + + } + } + + Timer.start(1000); + + UpdatingMapMutex.unlock(); +} + + +void TObserverClientModel::DoRunIoService() +{ + IoService.run(); + + ReceiveCloseSignal(); + ReceiveCloseSignal.disconnect_all_slots(); +} + +void TObserverClientModel::OnConnectButtonPressed() +{ + std::string address(MainWindowPtr->GetUi()->AddressField->text().toAscii()); + std::string port(MainWindowPtr->GetUi()->PortField->text().toAscii()); + + Start(address, port); +} + +void TObserverClientModel::OnUpdateInfoButtonPressed() +{ + + std::string lastName(MainWindowPtr->GetUi()->LastNameField->text().toUtf8()); + std::string firstName(MainWindowPtr->GetUi()->FirstNameField->text().toUtf8()); + std::string middleName(MainWindowPtr->GetUi()->MiddleNameField->text().toUtf8()); + + std::string phoneNumber(MainWindowPtr->GetUi()->PhoneNumberField->text().toUtf8()); + + int uik = MainWindowPtr->GetUi()->UikSpinBox->value(); + + int status = MainWindowPtr->GetUi()->StatusComboBox->currentIndex(); + + float posX = MainWindowPtr->GetUi()->PosXSpinBox->value(); + float posY = MainWindowPtr->GetUi()->PosYSpinBox->value(); + + int mapState = MainWindowPtr->GetUi()->MapStateComboBox->currentIndex(); + if (status == 1) + { + mapState = 0; + } + + ClientSocket->UserInfo.LastName = lastName; + ClientSocket->UserInfo.FirstName = firstName; + ClientSocket->UserInfo.MiddleName = middleName; + ClientSocket->UserInfo.PhoneNumber = phoneNumber; + ClientSocket->UserInfo.Uik = uik; + ClientSocket->UserInfo.Status = status; + ClientSocket->UserInfo.MapState = mapState; + + ClientSocket->UserInfo.PosX = posX; + ClientSocket->UserInfo.PosY = posY; + + ClientSocket->SendUserinfoUpdateThreaded(); + +} + + +void TObserverClientModel::OnHeartbeat(const boost::system::error_code& e) +{ + if (e) + { + return; + } + + float posX = MainWindowPtr->GetUi()->PosXSpinBox->value(); + float posY = MainWindowPtr->GetUi()->PosYSpinBox->value(); + + int uik = MainWindowPtr->GetUi()->UikSpinBox->value(); + int status = MainWindowPtr->GetUi()->StatusComboBox->currentIndex(); + int mapState = MainWindowPtr->GetUi()->MapStateComboBox->currentIndex() + 1; + if (status == 1) + { + mapState = 0; + } + + ClientSocket->UserInfo.Uik = uik; + ClientSocket->UserInfo.MapState = mapState; + + ClientSocket->UserInfo.PosX = posX; + ClientSocket->UserInfo.PosY = posY; + + ClientSocket->SendHeartbeatThreaded(); + + RestartHeartbeatTimer(); +} + +void TObserverClientModel::OnMapHeartbeat(const boost::system::error_code& e) +{ + if (e) + { + return; + } + + if (MapType == 0) + { + ClientSocket->SendMapQueryThreaded(); + } + else + { + ClientSocket->SendAlarmMapQueryThreaded(); + } + + RestartMapHeartbeatTimer(); +} + +void TObserverClientModel::OnReceiveMapUpdate(std::vector userInfoArr) +{ + + UpdatingMapMutex.lock(); + + UserInfoArr = userInfoArr; + + UpdatingMapMutex.unlock(); + +} + +void TObserverClientModel::OnReceiveAlarmMapUpdate(std::vector userInfoArr) +{ + UpdatingMapMutex.lock(); + + AlarmUserInfoArr = userInfoArr; + + UpdatingMapMutex.unlock(); +} + + +void TObserverClientModel::OnChangeMapTypeButtonPressed() +{ + MapType = MainWindowPtr->GetUi()->MapTypeComboBox->currentIndex(); + + if (MapType == 0) + { + ClientSocket->SendMapQueryThreaded(); + } + else + { + ClientSocket->SendAlarmMapQueryThreaded(); + } +} + +void TObserverClientModel::OnChatSendClick() +{ + QString msg = MainWindowPtr->GetUi()->ChatTextLine->text(); + + ClientSocket->SendMessageThreaded(std::string(msg.toUtf8())); +} + +void TObserverClientModel::OnReceiveChatMessage(TUserInfo userInfo, std::string msg) +{ + QString qmsg; + + qmsg += QString::fromUtf8(userInfo.LastName.c_str()) + " "; + qmsg += QString::fromUtf8(userInfo.FirstName.c_str()) + " "; + qmsg += QString::fromUtf8(userInfo.MiddleName.c_str()) + " "; + qmsg += QString::fromUtf8(userInfo.PhoneNumber.c_str()) + " "; + qmsg += QString(ws2qs(L" ")) + QString::number(userInfo.Uik) + ": "; + + + qmsg += QString::fromUtf8(msg.c_str()) + "\n"; + + + MainWindowPtr->GetUi()->ChatList->insertPlainText(qmsg); + +} + + +void TObserverClientModel::OnSendAlarmClick() +{ + ClientSocket->UserInfo.MapState = 2; + + QString msg = ws2qs(L"!"); + + ClientSocket->SendMessageThreaded(std::string(msg.toUtf8())); +} + + +void TObserverClientModel::OnKickPlayerClick() +{ + QString lastName = MainWindowPtr->GetUi()->LastNameKickEdit->text(); + QString firstName = MainWindowPtr->GetUi()->FirstNameKickEdit->text(); + QString middleName = MainWindowPtr->GetUi()->MiddleNameKickEdit->text(); + + ClientSocket->SendKickPlayerThreaded(std::string(lastName.toUtf8()), std::string(firstName.toUtf8()), std::string(middleName.toUtf8())); + +} + + +void TObserverClientModel::OnSelectPlayerClick() +{ + int i = MainWindowPtr->GetUi()->PlayerListWidget->currentRow(); + + QString lastName = QString::fromUtf8(AlarmUserInfoArr[i].LastName.c_str()); + QString firstName = QString::fromUtf8(AlarmUserInfoArr[i].FirstName.c_str()); + QString middleName = QString::fromUtf8(AlarmUserInfoArr[i].MiddleName.c_str()); + + MainWindowPtr->GetUi()->LastNameKickEdit->setText(lastName); + MainWindowPtr->GetUi()->FirstNameKickEdit->setText(firstName); + MainWindowPtr->GetUi()->MiddleNameKickEdit->setText(middleName); +} diff --git a/K-observer_client_qt/observerclientmodel.h b/K-observer_client_qt/observerclientmodel.h new file mode 100644 index 0000000..3747e60 --- /dev/null +++ b/K-observer_client_qt/observerclientmodel.h @@ -0,0 +1,86 @@ +#ifndef OBSERVERCLIENTMODEL_H +#define OBSERVERCLIENTMODEL_H + +#include + +#include "UserInfo.h" +#include "misc.h" +#include "ClientSocket.h" +#include "customtimer.h" + + +class MainWindow; + +class TObserverClientModel : public QObject +{ + Q_OBJECT +public: + explicit TObserverClientModel(QObject *parent = 0); + + MainWindow* MainWindowPtr; + + boost::shared_ptr ClientSocket; + + boost::asio::io_service IoService; + + boost::thread IoServiceThread; + + boost::mutex UpdatingMapMutex; + + std::vector UserInfoArr; + std::vector AlarmUserInfoArr; + + CustomTimer Timer; + + int MapType; + + bool Connected; + + void Start(std::string address, std::string port); + void Finish(); + + void OnSocketClosed(); + + void RestartHeartbeatTimer(); + void RestartMapHeartbeatTimer(); + + void OnConnectButtonPressed(); + + + + void OnUpdateInfoButtonPressed(); + + void OnChangeMapTypeButtonPressed(); + + void OnAutorizationSent(); + + void OnHeartbeat(const boost::system::error_code& e); + void OnMapHeartbeat(const boost::system::error_code& e); + + void DoRunIoService(); + + void OnUpdateMapTimer(); + void OnReceiveMapUpdate(std::vector userInfoArr); + void OnReceiveAlarmMapUpdate(std::vector userInfoArr); + + void OnChatSendClick(); + + void OnReceiveChatMessage(TUserInfo userInfo, std::string msg); + + void OnSendAlarmClick(); + + void OnKickPlayerClick(); + void OnSelectPlayerClick(); + + boost::shared_ptr HeartbeatTimer; + boost::shared_ptr MapHeartbeatTimer; + + boost::signal ReceiveCloseSignal; + +//signals: + +//public slots: + +}; + +#endif // OBSERVERCLIENTMODEL_H diff --git a/K-observer_client_qt/script.html b/K-observer_client_qt/script.html new file mode 100644 index 0000000..03c162e --- /dev/null +++ b/K-observer_client_qt/script.html @@ -0,0 +1,93 @@ + +OpenLayers Simplest Example +
+ + \ No newline at end of file diff --git a/KObserverAndroid/.classpath b/KObserverAndroid/.classpath new file mode 100644 index 0000000..f83b374 --- /dev/null +++ b/KObserverAndroid/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/KObserverAndroid/.project b/KObserverAndroid/.project new file mode 100644 index 0000000..ec8c15e --- /dev/null +++ b/KObserverAndroid/.project @@ -0,0 +1,33 @@ + + + K-Observer + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/KObserverAndroid/AndroidManifest.xml b/KObserverAndroid/AndroidManifest.xml new file mode 100644 index 0000000..174778f --- /dev/null +++ b/KObserverAndroid/AndroidManifest.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/KObserverAndroid/default.properties b/KObserverAndroid/default.properties new file mode 100644 index 0000000..0b9250e --- /dev/null +++ b/KObserverAndroid/default.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-8 diff --git a/KObserverAndroid/jni/Android.mk b/KObserverAndroid/jni/Android.mk new file mode 100644 index 0000000..b4f2255 --- /dev/null +++ b/KObserverAndroid/jni/Android.mk @@ -0,0 +1,105 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +LPATH := $(call my-dir) + +BOOST_PATH = $(LibsPathCygwin)/boost_1_47_0 + +#====== BOOST ===================== + + +LOCAL_PATH := $(BOOST_PATH) + +include $(CLEAR_VARS) + +LOCAL_MODULE := boost +LOCAL_C_INCLUDES := $(BOOST_PATH) + +#thread +LOCAL_SRC_FILES := /libs/thread/src/pthread/thread.cpp +LOCAL_SRC_FILES += /libs/thread/src/pthread/once.cpp + +#signals +LOCAL_SRC_FILES += /libs/signals/src/connection.cpp +LOCAL_SRC_FILES += /libs/signals/src/named_slot_map.cpp +LOCAL_SRC_FILES += /libs/signals/src/signal_base.cpp +LOCAL_SRC_FILES += /libs/signals/src/slot.cpp +LOCAL_SRC_FILES += /libs/signals/src/trackable.cpp + +#system +LOCAL_SRC_FILES += /libs/system/src/error_code.cpp + +#regex +LOCAL_SRC_FILES += /libs/regex/src/c_regex_traits.cpp +LOCAL_SRC_FILES += /libs/regex/src/cpp_regex_traits.cpp +LOCAL_SRC_FILES += /libs/regex/src/cregex.cpp +LOCAL_SRC_FILES += /libs/regex/src/fileiter.cpp +LOCAL_SRC_FILES += /libs/regex/src/icu.cpp +LOCAL_SRC_FILES += /libs/regex/src/instances.cpp +LOCAL_SRC_FILES += /libs/regex/src/posix_api.cpp +LOCAL_SRC_FILES += /libs/regex/src/regex.cpp +LOCAL_SRC_FILES += /libs/regex/src/regex_debug.cpp +LOCAL_SRC_FILES += /libs/regex/src/regex_raw_buffer.cpp +LOCAL_SRC_FILES += /libs/regex/src/regex_traits_defaults.cpp +LOCAL_SRC_FILES += /libs/regex/src/static_mutex.cpp +LOCAL_SRC_FILES += /libs/regex/src/usinstances.cpp +LOCAL_SRC_FILES += /libs/regex/src/w32_regex_traits.cpp +LOCAL_SRC_FILES += /libs/regex/src/wc_regex_traits.cpp +LOCAL_SRC_FILES += /libs/regex/src/wide_posix_api.cpp +LOCAL_SRC_FILES += /libs/regex/src/winstances.cpp + +#date_time +LOCAL_SRC_FILES += /libs/date_time/src/gregorian/greg_month.cpp +LOCAL_SRC_FILES += /libs/date_time/src/gregorian/greg_weekday.cpp +LOCAL_SRC_FILES += /libs/date_time/src/gregorian/date_generators.cpp + +#asio +#nothing + + + +LOCAL_LDLIBS := -llog -Wl + +#debug +#LOCAL_CFLAGS := -g -ggdb -O0 +#LOCAL_LDLIBS += -g -ggdb + + +include $(BUILD_STATIC_LIBRARY) + + +#================= THE APP ======================= + + +LOCAL_PATH:= $(LPATH) + +include $(CLEAR_VARS) + +LOCAL_STATIC_LIBRARIES := boost +LOCAL_C_INCLUDES := $(BOOST_PATH) +LOCAL_C_INCLUDES += ../../common +LOCAL_MODULE := KObserver +LOCAL_SRC_FILES := main_code.cpp +LOCAL_SRC_FILES += android_api.cpp + +LOCAL_SRC_FILES += ../../common/ClientSocket.cpp +LOCAL_SRC_FILES += ../../common/MessageSender.cpp +LOCAL_SRC_FILES += ../../common/misc.cpp +LOCAL_SRC_FILES += ../../common/UserInfo.cpp + +LOCAL_LDLIBS := -llog -Wl,-s + +include $(BUILD_SHARED_LIBRARY) diff --git a/KObserverAndroid/jni/Application.mk b/KObserverAndroid/jni/Application.mk new file mode 100644 index 0000000..824acab --- /dev/null +++ b/KObserverAndroid/jni/Application.mk @@ -0,0 +1,3 @@ +APP_STL := gnustl_static +APP_CPPFLAGS += -fexceptions +APP_CPPFLAGS += -frtti \ No newline at end of file diff --git a/KObserverAndroid/jni/android_api.cpp b/KObserverAndroid/jni/android_api.cpp new file mode 100644 index 0000000..0acbf0d --- /dev/null +++ b/KObserverAndroid/jni/android_api.cpp @@ -0,0 +1,623 @@ +#include "android_api.h" + +#include "main_code.h" + + + +#include + +#include "boost/asio.hpp" +#include "boost/bind.hpp" +#include "boost/shared_ptr.hpp" +#include "boost/shared_array.hpp" +#include "boost/array.hpp" +#include "boost/enable_shared_from_this.hpp" +#include "boost/thread.hpp" + +#include +#include +#include + +#include "ClientSocket.h" + + + +boost::asio::io_service IoService; + +boost::thread IoServiceThread; + +boost::shared_ptr ClientSocket; + +boost::mutex connection_mutex; + +std::vector MessageHeaderArr; +std::vector MessageTextArr; + +std::vector JavaStringHolder; + +boost::shared_ptr HeartbeatTimer; +boost::shared_ptr MapHeartbeatTimer; + +std::vector UserInfoMapArr; +std::vector UserInfoAlarmMapArr; + +std::vector* CurrentUserInfoMapArr = &UserInfoMapArr; + +float LastPosX = 0.f; +float LastPosY = 0.f; + +int MapType = 0; + +/* +void WriteToFile(std::string text) +{ +std::string LogFilename = "/sdcard/hello.txt"; + + FILE* f = fopen(LogFilename.c_str(), "a"); + + if (f != NULL) + { + fputs(text.c_str(), f); + fflush(f); + fclose(f); + } +}*/ + +void IoServiceRun() +{ + IoService.run(); + + ClientSocket = boost::shared_ptr(); + + IoService.reset(); + + //WriteToFile("lolwaauat\n"); + + +} + + + +void OnAutorizationSent() +{ + //WriteToFile("OnAutorizationSent\n"); + + RestartHeartbeatTimer(); + RestartMapHeartbeatTimer(); + + connection_mutex.unlock(); +} + +void OnRecieveMapUpdate(std::vector userInfoArr) +{ + UserInfoMapArr = userInfoArr; +} + +void OnRecieveAlarmMapUpdate(std::vector userInfoArr) +{ + UserInfoAlarmMapArr = userInfoArr; +} + +void OnClosed() +{ +//WriteToFile("OnClosed\n"); +} + +JavaVM* JavaVirtualMachine; + +template +inline std::string tostr(T i) +{ + std::ostringstream out; + out << i; + return std::string(out.str()); +} + + +JNIEnv* jenv; + +jclass clazzLUSCore; + +struct OnReceiveMessage +{ +void operator()(TUserInfo userInfo, std::string message) +{ + + JNIEnv* j_env; + JavaVirtualMachine->GetEnv((void**)&j_env, JNI_VERSION_1_4); + + std::string header = tostr(userInfo.Uik) + " " + message; + + std::string status; + + if (userInfo.Status == 0) + { + status = "Наблюдатель"; + } + else + { + status = "Мобильная группа"; + } + + std::string text = userInfo.LastName + + " " + userInfo.FirstName + + " " + userInfo.MiddleName + + " " + userInfo.PhoneNumber + + " " + status + + " УИК №" + tostr(userInfo.Uik) + + ": " + message; + + + { + boost::this_thread::disable_interruption di; + + MessageHeaderArr.push_back(header); + MessageTextArr.push_back(text); + } + +} +}; + +void OnHeartbeat(const boost::system::error_code& e) +{ + + if (e) + { + return; + } +/* + float posX = MainWindowPtr->GetUi()->PosXSpinBox->value(); + float posY = MainWindowPtr->GetUi()->PosYSpinBox->value(); + + int uik = MainWindowPtr->GetUi()->UikSpinBox->value(); + int status = MainWindowPtr->GetUi()->StatusComboBox->currentIndex(); + int mapState = MainWindowPtr->GetUi()->MapStateComboBox->currentIndex() + 1; + if (status == 1) + { + mapState = 0; + } + + ClientSocket->UserInfo.Uik = uik; + ClientSocket->UserInfo.MapState = mapState; + + ClientSocket->UserInfo.PosX = posX; + ClientSocket->UserInfo.PosY = posY; +*/ + ClientSocket->SendHeartbeatThreaded(); + + RestartHeartbeatTimer(); +} + +void OnMapHeartbeat(const boost::system::error_code& e) +{ + if (e) + { + return; + } + + if (MapType == 0) + { + ClientSocket->SendMapQueryThreaded(); + } + else + { + ClientSocket->SendAlarmMapQueryThreaded(); + } + + RestartMapHeartbeatTimer(); +} + +void RestartHeartbeatTimer() +{ + HeartbeatTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3))); + + HeartbeatTimer->async_wait(boost::bind(&OnHeartbeat, boost::asio::placeholders::error)); + +} + +void RestartMapHeartbeatTimer() +{ + MapHeartbeatTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3))); + + MapHeartbeatTimer->async_wait(boost::bind(&OnMapHeartbeat, boost::asio::placeholders::error)); + +} + + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_Open(JNIEnv * env, jobject obj, jstring addr, jstring port) +{ + + int JVMResult; + JVMResult = env->GetJavaVM(&JavaVirtualMachine); + + jenv = env; + +static bool x = false; + +if (!x) +{ +x = true; + +std::string LogFilename = "/sdcard/hello.txt"; + + FILE* f = fopen(LogFilename.c_str(), "w"); + + if (f != NULL) + { + fclose(f); + } +} + const char *addr_c; + + addr_c = env->GetStringUTFChars(addr, NULL); + if (addr_c == NULL) + { + return; + } + + const char *port_c; + + port_c = env->GetStringUTFChars(port, NULL); + if (port_c == NULL) + { + return; + } + + //WriteToFile("Thread go xxx\n"); + + + connection_mutex.lock(); + + ClientSocket = boost::shared_ptr(new TClientSocket(IoService)); + + ClientSocket->UserInfo.PosX = LastPosX; + ClientSocket->UserInfo.PosY = LastPosY; + + ClientSocket->ReceiveAutorizationSentSignal.connect(boost::bind(&OnAutorizationSent)); + + ClientSocket->ReceiveForceCloseSignal.connect(boost::bind(&OnClosed)); + + ClientSocket->ReceiveMessageSignal.connect(OnReceiveMessage()); + + + + ClientSocket->ReceiveMapSignal.connect(boost::bind(&OnRecieveMapUpdate, _1)); + ClientSocket->ReceiveAlarmMapSignal.connect(boost::bind(&OnRecieveAlarmMapUpdate, _1)); + + + + + ClientSocket->Open(std::string(addr_c), std::string(port_c)); + + IoServiceThread = boost::thread(boost::bind(&IoServiceRun)); + + //WriteToFile("Thread go\n"); + + + connection_mutex.lock(); + connection_mutex.unlock(); + + //WriteToFile("Sleep over\n"); + + jclass cls = env->FindClass("fishrungames/kobserver/JniWrapper"); + jmethodID mid = env->GetStaticMethodID(cls, "OnConnectSuccessful", "()V"); + + clazzLUSCore = (_jclass*)env->NewGlobalRef(cls); + + env->DeleteLocalRef(cls); + + + if (mid == NULL) + { + return; + } + + env->CallStaticVoidMethod(cls, mid); + + + env->ReleaseStringUTFChars(addr, addr_c); + env->ReleaseStringUTFChars(port, port_c); + +} + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_Close(JNIEnv * env, jobject obj) +{ + ClientSocket->CloseThreaded(); +} + + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_UpdateUserInfo(JNIEnv * env, jobject obj + , jstring lastName + , jstring firstName + , jstring middleName + , jstring contactNumber + , int mapState + , int uik + , int status + , float posX + , float posY) +{ + TUserInfo userInfo; + + const char *c_lastName; + + c_lastName = env->GetStringUTFChars(lastName, NULL); + + if (c_lastName == NULL) + { + return; + } + + userInfo.LastName = std::string(c_lastName); + + env->ReleaseStringUTFChars(lastName, c_lastName); + + + // ==== First Name + const char *c_firstName; + + c_firstName = env->GetStringUTFChars(firstName, NULL); + + if (c_firstName == NULL) + { + return; + } + + userInfo.FirstName = std::string(c_firstName); + + env->ReleaseStringUTFChars(firstName, c_firstName); + + + // ==== Middle Name + const char *c_middleName; + + c_middleName = env->GetStringUTFChars(middleName, NULL); + + if (c_middleName == NULL) + { + return; + } + + userInfo.MiddleName = std::string(c_middleName); + + env->ReleaseStringUTFChars(middleName, c_middleName); + + + // ==== Contact Number + const char *c_contactNumber; + + c_contactNumber = env->GetStringUTFChars(contactNumber, NULL); + + if (c_contactNumber == NULL) + { + return; + } + + userInfo.PhoneNumber = std::string(c_contactNumber); + + env->ReleaseStringUTFChars(contactNumber, c_contactNumber); + + userInfo.MapState = mapState; + userInfo.Uik = uik; + userInfo.Status = status; + + userInfo.PosX = posX; + + userInfo.PosY = posY; + + ClientSocket->UserInfo = userInfo; + + ClientSocket->SendUserinfoUpdateThreaded(); + +} + + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmCommon(JNIEnv * env, jobject obj) +{ + ClientSocket->UserInfo.MapState = 2; + ClientSocket->SendUserinfoUpdateThreaded(); + ClientSocket->SendMessageThreaded(std::string("ТРЕВОГА (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)")); +} + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmExclusion(JNIEnv * env, jobject obj) +{ + ClientSocket->UserInfo.MapState = 3; + ClientSocket->SendUserinfoUpdateThreaded(); + ClientSocket->SendMessageThreaded(std::string("ТРЕВОГА: УДАЛЕНИЕ С УИК (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)")); +} + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmInjection(JNIEnv * env, jobject obj) +{ + ClientSocket->UserInfo.MapState = 4; + ClientSocket->SendUserinfoUpdateThreaded(); + ClientSocket->SendMessageThreaded(std::string("ТРЕВОГА: ВБРОС (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)")); +} + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmCarousel(JNIEnv * env, jobject obj) +{ + ClientSocket->UserInfo.MapState = 5; + ClientSocket->SendUserinfoUpdateThreaded(); + ClientSocket->SendMessageThreaded(std::string("ТРЕВОГА: КАРУСЕЛЬ (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)")); +} + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmAssault(JNIEnv * env, jobject obj) +{ + ClientSocket->UserInfo.MapState = 6; + ClientSocket->SendUserinfoUpdateThreaded(); + ClientSocket->SendMessageThreaded(std::string("ТРЕВОГА: НАПАДЕНИЕ (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)")); +} + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SendMessage(JNIEnv * env, jobject obj, jstring msg) +{ + const char *c_msg; + + c_msg = env->GetStringUTFChars(msg, NULL); + + if (c_msg == NULL) + { + return; + } + + std::string str_msg(c_msg); + + env->ReleaseStringUTFChars(msg, c_msg); + + ClientSocket->SendMessageThreaded(str_msg); + +} + + +JNIEXPORT jstring JNICALL Java_fishrungames_kobserver_JniWrapper_GetLastMessageHeader(JNIEnv * env, jobject obj) +{ + + jstring jstr; + + + if (MessageHeaderArr.size() > 0) + { + JavaStringHolder.push_back(MessageHeaderArr[0]); + jstr = env->NewStringUTF(JavaStringHolder[JavaStringHolder.size()-1].c_str()); + MessageHeaderArr.clear(); + } + else + { + jstr = env->NewStringUTF(""); + } + + return jstr; + +} + +JNIEXPORT jstring JNICALL Java_fishrungames_kobserver_JniWrapper_GetLastMessageText(JNIEnv * env, jobject obj) +{ + + jstring jstr; + + if (MessageTextArr.size() > 0) + { + JavaStringHolder.push_back(MessageTextArr[0]); + jstr = env->NewStringUTF(JavaStringHolder[JavaStringHolder.size()-1].c_str()); + MessageTextArr.clear(); + } + else + { + jstr = env->NewStringUTF(""); + } + + return jstr; +} + + +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetNumberOfUsers(JNIEnv * env, jobject obj) +{ + return (*CurrentUserInfoMapArr).size(); +} + +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserUik(JNIEnv * env, jobject obj, int i) +{ + return (*CurrentUserInfoMapArr)[i].Uik; +} + +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserPosX(JNIEnv * env, jobject obj, int i) +{ + return (*CurrentUserInfoMapArr)[i].PosX; +} + +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserPosY(JNIEnv * env, jobject obj, int i) +{ + return (*CurrentUserInfoMapArr)[i].PosY; +} + +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserMapState(JNIEnv * env, jobject obj, int i) +{ + return (*CurrentUserInfoMapArr)[i].MapState; +} + +JNIEXPORT jstring JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserDescription(JNIEnv * env, jobject obj, int i) +{ + + std::string State; + + if ((*CurrentUserInfoMapArr)[i].MapState == 2) + { + State = "Тревога"; + } + else if ((*CurrentUserInfoMapArr)[i].MapState == 3) + { + State = "Тревога - Удаление с УИК"; + } + else if ((*CurrentUserInfoMapArr)[i].MapState == 4) + { + State = "Тревога - Вброс"; + } + else if ((*CurrentUserInfoMapArr)[i].MapState == 5) + { + State = "Тревога - Карусель"; + } + else if ((*CurrentUserInfoMapArr)[i].MapState == 6) + { + State = "Тревога - Нападение"; + } + + std::string status = "Наблюдатель"; + + if ((*CurrentUserInfoMapArr)[i].Status == 1) + { + status = "Мобильная группа"; + } + + std::string descr = "УИК №" + tostr((*CurrentUserInfoMapArr)[i].Uik) + "\\n"+ + (*CurrentUserInfoMapArr)[i].LastName+ "\\n"+ + (*CurrentUserInfoMapArr)[i].FirstName+ "\\n"+ + (*CurrentUserInfoMapArr)[i].MiddleName+ "\\n"+ + (*CurrentUserInfoMapArr)[i].PhoneNumber+ "\\n"+ + status + "\\n" + + "Состояние: "+State; + + jstring jstr; + + jstr = env->NewStringUTF(descr.c_str()); + + return jstr; +} + +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetMapCenterPosX(JNIEnv * env, jobject obj) +{ + return ClientSocket->BaseLon; +} + +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetMapCenterPosY(JNIEnv * env, jobject obj) +{ + return ClientSocket->BaseLat; +} + +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetMapCenterZoom(JNIEnv * env, jobject obj) +{ + return ClientSocket->BaseZoom; +} + + + +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_SetPosition(JNIEnv * env, jobject obj, float x, float y) +{ + ClientSocket->UserInfo.PosX = x; + ClientSocket->UserInfo.PosY = y; + + LastPosX = x; + LastPosY = y; +} + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_ChangeMapType(JNIEnv * env, jobject obj, int mapType) +{ + MapType = mapType; + + if (MapType == 0) + { + CurrentUserInfoMapArr = &UserInfoMapArr; + } + else + { + CurrentUserInfoMapArr = &UserInfoAlarmMapArr; + } +} + diff --git a/KObserverAndroid/jni/android_api.h b/KObserverAndroid/jni/android_api.h new file mode 100644 index 0000000..ef13962 --- /dev/null +++ b/KObserverAndroid/jni/android_api.h @@ -0,0 +1,65 @@ +#ifndef ANDROID_API_H_INCLUDED +#define ANDROID_API_H_INCLUDED + +#include +#include + +#include +#include +#include + +#include "boost/shared_ptr.hpp" + +#include "main_code.h" + + +void RestartHeartbeatTimer(); +void RestartMapHeartbeatTimer(); + +extern "C" { + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_Open(JNIEnv * env, jobject obj, jstring addr, jstring port); +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_Close(JNIEnv * env, jobject obj); +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_UpdateUserInfo(JNIEnv * env, jobject obj + , jstring lastName + , jstring firstName + , jstring middleName + , jstring contactNumber + , int mapState + , int uik + , int status + , float posX + , float posY); + + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmCommon(JNIEnv * env, jobject obj); +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmExclusion(JNIEnv * env, jobject obj); +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmInjection(JNIEnv * env, jobject obj); +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmCarousel(JNIEnv * env, jobject obj); +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SetAlarmAssault(JNIEnv * env, jobject obj); +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_SendMessage(JNIEnv * env, jobject obj, jstring msg); +JNIEXPORT jstring JNICALL Java_fishrungames_kobserver_JniWrapper_GetLastMessageHeader(JNIEnv * env, jobject obj); +JNIEXPORT jstring JNICALL Java_fishrungames_kobserver_JniWrapper_GetLastMessageText(JNIEnv * env, jobject obj); + + +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetNumberOfUsers(JNIEnv * env, jobject obj); +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserUik(JNIEnv * env, jobject obj, int i); +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserPosX(JNIEnv * env, jobject obj, int i); +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserPosY(JNIEnv * env, jobject obj, int i); +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserMapState(JNIEnv * env, jobject obj, int i); +JNIEXPORT jstring JNICALL Java_fishrungames_kobserver_JniWrapper_GetUserDescription(JNIEnv * env, jobject obj, int i); + +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetMapCenterPosX(JNIEnv * env, jobject obj); +JNIEXPORT float JNICALL Java_fishrungames_kobserver_JniWrapper_GetMapCenterPosY(JNIEnv * env, jobject obj); +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_GetMapCenterZoom(JNIEnv * env, jobject obj); + + +JNIEXPORT int JNICALL Java_fishrungames_kobserver_JniWrapper_SetPosition(JNIEnv * env, jobject obj, float x, float y); + +JNIEXPORT void JNICALL Java_fishrungames_kobserver_JniWrapper_ChangeMapType(JNIEnv * env, jobject obj, int mapType); + + + +}; + +#endif diff --git a/KObserverAndroid/jni/main_code.cpp b/KObserverAndroid/jni/main_code.cpp new file mode 100644 index 0000000..058bb32 --- /dev/null +++ b/KObserverAndroid/jni/main_code.cpp @@ -0,0 +1,10 @@ +#include "main_code.h" +#include "android_api.h" + +#include +#include +#include +#include + + + diff --git a/KObserverAndroid/jni/main_code.h b/KObserverAndroid/jni/main_code.h new file mode 100644 index 0000000..5802325 --- /dev/null +++ b/KObserverAndroid/jni/main_code.h @@ -0,0 +1,16 @@ +#ifndef GL_CODE_H_INCLUDED +#define GL_CODE_H_INCLUDED + + +#include +#include +#include + +#include "boost/shared_ptr.hpp" +#include "boost/thread/thread.hpp" +#include "boost/signal.hpp" +#include "boost/assign.hpp" +#include "boost/bind.hpp" + + +#endif diff --git a/KObserverAndroid/res/drawable-hdpi/ic_menu_template.png b/KObserverAndroid/res/drawable-hdpi/ic_menu_template.png new file mode 100644 index 0000000..8ca4ffc Binary files /dev/null and b/KObserverAndroid/res/drawable-hdpi/ic_menu_template.png differ diff --git a/KObserverAndroid/res/drawable-ldpi/ic_menu_template.png b/KObserverAndroid/res/drawable-ldpi/ic_menu_template.png new file mode 100644 index 0000000..a9d412b Binary files /dev/null and b/KObserverAndroid/res/drawable-ldpi/ic_menu_template.png differ diff --git a/KObserverAndroid/res/drawable-mdpi/ic_menu_template.png b/KObserverAndroid/res/drawable-mdpi/ic_menu_template.png new file mode 100644 index 0000000..7b87c2c Binary files /dev/null and b/KObserverAndroid/res/drawable-mdpi/ic_menu_template.png differ diff --git a/KObserverAndroid/res/layout/alarm_layout.xml b/KObserverAndroid/res/layout/alarm_layout.xml new file mode 100644 index 0000000..2c158c6 --- /dev/null +++ b/KObserverAndroid/res/layout/alarm_layout.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KObserverAndroid/res/layout/connect_layout.xml b/KObserverAndroid/res/layout/connect_layout.xml new file mode 100644 index 0000000..67297c4 --- /dev/null +++ b/KObserverAndroid/res/layout/connect_layout.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KObserverAndroid/res/layout/main_menu_layout.xml b/KObserverAndroid/res/layout/main_menu_layout.xml new file mode 100644 index 0000000..3f1127e --- /dev/null +++ b/KObserverAndroid/res/layout/main_menu_layout.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KObserverAndroid/res/layout/map_layout.xml b/KObserverAndroid/res/layout/map_layout.xml new file mode 100644 index 0000000..36d16dd --- /dev/null +++ b/KObserverAndroid/res/layout/map_layout.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KObserverAndroid/res/layout/messages_layout.xml b/KObserverAndroid/res/layout/messages_layout.xml new file mode 100644 index 0000000..b355afc --- /dev/null +++ b/KObserverAndroid/res/layout/messages_layout.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KObserverAndroid/res/layout/profile_layout.xml b/KObserverAndroid/res/layout/profile_layout.xml new file mode 100644 index 0000000..d822389 --- /dev/null +++ b/KObserverAndroid/res/layout/profile_layout.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KObserverAndroid/res/layout/send_message_layout.xml b/KObserverAndroid/res/layout/send_message_layout.xml new file mode 100644 index 0000000..e0ed358 --- /dev/null +++ b/KObserverAndroid/res/layout/send_message_layout.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KObserverAndroid/res/raw/script.html b/KObserverAndroid/res/raw/script.html new file mode 100644 index 0000000..1a609fc --- /dev/null +++ b/KObserverAndroid/res/raw/script.html @@ -0,0 +1,117 @@ + +OpenLayers Simplest Example +
+ + \ No newline at end of file diff --git a/KObserverAndroid/res/values/colors.xml b/KObserverAndroid/res/values/colors.xml new file mode 100644 index 0000000..092208e --- /dev/null +++ b/KObserverAndroid/res/values/colors.xml @@ -0,0 +1,7 @@ + + +#ff8080ff +#ffffe080 +#ff000000 +#ffffffff + diff --git a/KObserverAndroid/res/values/strings.xml b/KObserverAndroid/res/values/strings.xml new file mode 100644 index 0000000..b8fcfcd --- /dev/null +++ b/KObserverAndroid/res/values/strings.xml @@ -0,0 +1,4 @@ + + + AndroidJniTemplate + diff --git a/KObserverAndroid/src/fishrungames/kobserver/AlarmActivity.java b/KObserverAndroid/src/fishrungames/kobserver/AlarmActivity.java new file mode 100644 index 0000000..320d0da --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/AlarmActivity.java @@ -0,0 +1,102 @@ +package fishrungames.kobserver; + +import fishrungames.kobserver.JniWrapper; + +import android.app.Activity; +import android.content.Intent; + +import android.os.Bundle; + +import android.view.View; + +import android.widget.Button; +import android.widget.EditText; + + +public class AlarmActivity extends Activity +{ + + @Override + protected void onCreate(Bundle icicle) + { + + super.onCreate(icicle); + + setContentView(R.layout.alarm_layout); + + Button backbtn = (Button) findViewById(R.id.backButton_alarm); + backbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), MainMenuActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + + + Button exclusionButton = (Button) findViewById(R.id.exclusionButton); + exclusionButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + + JniWrapper.MapState = 3; + JniWrapper.SetAlarmExclusion(); + + + } + }); + + + Button injectionButton = (Button) findViewById(R.id.injectionButton); + injectionButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + + JniWrapper.MapState = 4; + JniWrapper.SetAlarmInjection(); + + + } + }); + + + Button carouselButton = (Button) findViewById(R.id.carouselButton); + carouselButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + + JniWrapper.MapState = 5; + JniWrapper.SetAlarmCarousel(); + + + } + }); + + + Button assaultButton = (Button) findViewById(R.id.assaultButton); + assaultButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + + JniWrapper.MapState = 6; + JniWrapper.SetAlarmAssault(); + + + } + }); + + Button sendAdditionalMessageButton = (Button) findViewById(R.id.sendAdditionalMessageButton); + sendAdditionalMessageButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + + EditText additionalMessageEdit = (EditText) findViewById(R.id.additionalMessageEdit); + + JniWrapper.SendMessage(additionalMessageEdit.getText().toString()); + + additionalMessageEdit.setText(""); + + + } + }); + + + + + } +} \ No newline at end of file diff --git a/KObserverAndroid/src/fishrungames/kobserver/ConnectActivity.java b/KObserverAndroid/src/fishrungames/kobserver/ConnectActivity.java new file mode 100644 index 0000000..74eb24b --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/ConnectActivity.java @@ -0,0 +1,56 @@ +package fishrungames.kobserver; + +import fishrungames.kobserver.JniWrapper; + +import android.app.Activity; +import android.content.Intent; + +import android.os.Bundle; + +import android.view.View; + +import android.widget.Button; +import android.widget.EditText; + + +public class ConnectActivity extends Activity +{ + + @Override + protected void onCreate(Bundle icicle) + { + + super.onCreate(icicle); + + setContentView(R.layout.connect_layout); + + JniWrapper.connectActivity = this; + + Button connectbtn = (Button) findViewById(R.id.connectButton); + connectbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + + + EditText addr_edit = (EditText) findViewById(R.id.edit_addr); + EditText port_edit = (EditText) findViewById(R.id.edit_port); + + JniWrapper.Open(addr_edit.getText().toString(), port_edit.getText().toString()); + JniWrapper.StartGetMessageTimer(); + + } + }); + + if (JniWrapper.connected) + { + goToMainMenu(); + } + + + } + + public void goToMainMenu() + { + Intent myIntent = new Intent(this, MainMenuActivity.class); + startActivityForResult(myIntent, 0); + } +} \ No newline at end of file diff --git a/KObserverAndroid/src/fishrungames/kobserver/GeoUpdateHandler.java b/KObserverAndroid/src/fishrungames/kobserver/GeoUpdateHandler.java new file mode 100644 index 0000000..f6115f4 --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/GeoUpdateHandler.java @@ -0,0 +1,30 @@ +package fishrungames.kobserver; + +import android.location.Location; +import android.location.LocationListener; +import android.os.Bundle; + + public class GeoUpdateHandler implements LocationListener { + @Override + public void onLocationChanged(Location location) { + //int lat = (int) (location.getLatitude() * 1E6); + //int lng = (int) (location.getLongitude() * 1E6); + // GeoPoint point = new GeoPoint(lat, lng); + //mapController.animateTo(point); + + float lat = (float)location.getLatitude(); + float lon = (float)location.getLongitude(); + + JniWrapper.SetPosition(lon, lat); + + } + @Override + public void onProviderDisabled(String provider) { } + + @Override + public void onProviderEnabled(String provider) { } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { } + } + diff --git a/KObserverAndroid/src/fishrungames/kobserver/GetMessageTimerTask.java b/KObserverAndroid/src/fishrungames/kobserver/GetMessageTimerTask.java new file mode 100644 index 0000000..303e6f7 --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/GetMessageTimerTask.java @@ -0,0 +1,30 @@ +package fishrungames.kobserver; + +import java.util.TimerTask; + +import fishrungames.kobserver.JniWrapper; + +class GetMessageTimerTask extends TimerTask +{ + + @Override + public void run() + { + + String messageHeader = JniWrapper.GetLastMessageHeader(); + String messageText = JniWrapper.GetLastMessageText(); + + if (!messageHeader.equals("") && !messageText.equals("")) + { + JniWrapper.messages_headers.add(0, messageHeader); + JniWrapper.messages_texts.add(0, messageText); + + if (JniWrapper.messagesActivity != null) + { + JniWrapper.messagesActivity.RefreshMessageList(); + } + + } + + } +} diff --git a/KObserverAndroid/src/fishrungames/kobserver/JniWrapper.java b/KObserverAndroid/src/fishrungames/kobserver/JniWrapper.java new file mode 100644 index 0000000..a0c90dc --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/JniWrapper.java @@ -0,0 +1,113 @@ +package fishrungames.kobserver; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Timer; + +import android.content.Context; +import android.location.LocationManager; + + +import fishrungames.kobserver.GetMessageTimerTask; + +public class JniWrapper +{ + static { + System.loadLibrary("KObserver"); + } + + + + public static Timer UpdateTimer; + + public static MessagesActivity messagesActivity = null; + + public static boolean connected = false; + + //Info to be saved + + public static String LastName = new String(); + public static String FirstName = new String(); + public static String MiddleName = new String(); + public static String ContactNumber = new String(); + public static int MapState; + public static int UikNumber; + public static int Status; + public static float PosX; + public static float PosY; + + + public static ArrayList messages_headers = new ArrayList(Arrays.asList(" ")); + public static ArrayList messages_texts = new ArrayList(Arrays.asList(" ")); + + public static ConnectActivity connectActivity; + + public static native void Open(String addr, String port); + public static native void Close(); + + public static void OnConnectSuccessful() + { + connectActivity.goToMainMenu(); + connected = true; + } + + public static native void UpdateUserInfo(String lastName, String firstName, String middleName, String contactNumber, int mapState, int Uik, int Status, float posX, float posY); + + public static native void SetAlarmCommon(); + + public static native void SetAlarmExclusion(); + + public static native void SetAlarmInjection(); + + public static native void SetAlarmCarousel(); + + public static native void SetAlarmAssault(); + + public static native void SendMessage(String msg); + + public static native String GetLastMessageHeader(); + + public static native String GetLastMessageText(); + + public static native int GetNumberOfUsers(); + public static native int GetUserUik(int i); + public static native float GetUserPosX(int i); + public static native float GetUserPosY(int i); + public static native int GetUserMapState(int i); + public static native String GetUserDescription(int i); + + public static native float GetMapCenterPosX(); + public static native float GetMapCenterPosY(); + public static native int GetMapCenterZoom(); + + + public static native float SetPosition(float x, float y); + + public static native void ChangeMapType(int mapType); + + public static void StartGetMessageTimer() + { + UpdateTimer = new Timer(); + + + UpdateTimer.schedule(new GetMessageTimerTask(), 0, 100); + } + + public static void StopGetMessageTimer() + { + UpdateTimer = null; + } + + public static LocationManager locationManager = null; + + public static void StartUpdateMapLocation(MainMenuActivity act) + { + locationManager = (LocationManager) act.getSystemService(Context.LOCATION_SERVICE); + + //Use both =) + //locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new GeoUpdateHandler()); + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new GeoUpdateHandler()); + + } + +} \ No newline at end of file diff --git a/KObserverAndroid/src/fishrungames/kobserver/MainMenuActivity.java b/KObserverAndroid/src/fishrungames/kobserver/MainMenuActivity.java new file mode 100644 index 0000000..d86a147 --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/MainMenuActivity.java @@ -0,0 +1,80 @@ +package fishrungames.kobserver; + +import fishrungames.kobserver.JniWrapper; + +import android.app.Activity; +import android.content.Intent; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + + + +public class MainMenuActivity extends Activity +{ + + @Override + protected void onCreate(Bundle icicle) + { + + super.onCreate(icicle); + + //setContentView(R.layout.connect_layout); + setContentView(R.layout.main_menu_layout); + + JniWrapper.StartUpdateMapLocation(this); + + Button mapbtn = (Button) findViewById(R.id.mapButton); + mapbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), MapActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + Button profilebtn = (Button) findViewById(R.id.profileButton); + profilebtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), ProfileActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + + Button alarmbtn = (Button) findViewById(R.id.alarmButton); + alarmbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), AlarmActivity.class); + startActivityForResult(myIntent, 0); + + JniWrapper.MapState = 2; + JniWrapper.SetAlarmCommon(); + + } + }); + + + Button messagesbtn = (Button) findViewById(R.id.messagesButton); + messagesbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), MessagesActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + Button backbtn = (Button) findViewById(R.id.disconnectButton); + backbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + JniWrapper.Close(); + JniWrapper.connected = false; + JniWrapper.StopGetMessageTimer(); + Intent myIntent = new Intent(view.getContext(), ConnectActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + + } + +} \ No newline at end of file diff --git a/KObserverAndroid/src/fishrungames/kobserver/MapActivity.java b/KObserverAndroid/src/fishrungames/kobserver/MapActivity.java new file mode 100644 index 0000000..74de421 --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/MapActivity.java @@ -0,0 +1,168 @@ +package fishrungames.kobserver; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Timer; +import java.util.TimerTask; + +import fishrungames.kobserver.JniWrapper; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.Resources; + +import android.os.Bundle; + +import android.view.View; + + +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; + +public class MapActivity extends Activity +{ + + ArrayAdapter spinnerAdapter; + + public Timer mapUpdateTimer; + + @Override + protected void onCreate(Bundle icicle) + { + + super.onCreate(icicle); + + setContentView(R.layout.map_layout); + + Button backbtn = (Button) findViewById(R.id.backButton_map); + backbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), MainMenuActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + Spinner mapModeSpinner = (Spinner) findViewById(R.id.mapModeSpinner); + + ArrayList strings = + new ArrayList(Arrays.asList(" ", " ")); + + spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, strings); + + mapModeSpinner.setAdapter(spinnerAdapter); + + WebView webView = (WebView) findViewById(R.id.webView); + + mapModeSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener(webView)); + + + String htmlCode = new String(); + + try { + Resources res = getResources(); + InputStream in_s = res.openRawResource(R.raw.script); + + byte[] b = new byte[in_s.available()]; + in_s.read(b); + htmlCode = new String(b); + } catch (Exception e) { + e.printStackTrace(); + } + + WebSettings webSettings = webView.getSettings(); + webSettings.setJavaScriptEnabled(true); + webSettings.setDomStorageEnabled(true); + + webView.setWebChromeClient(new WebChromeClient()); + + htmlCode = htmlCode.replace("%", "%"); + + float lon = JniWrapper.GetMapCenterPosX(); + float lat = JniWrapper.GetMapCenterPosY(); + int zoom = JniWrapper.GetMapCenterZoom(); + htmlCode = htmlCode.replace("__LON__", Float.toString(lon)); + htmlCode = htmlCode.replace("__LAT__", Float.toString(lat)); + htmlCode = htmlCode.replace("__ZOOM__", Integer.toString(zoom)); + + webView.loadData(htmlCode, "text/html", "UTF-8"); + + mapUpdateTimer = new Timer(); + + mapUpdateTimer.schedule(new MapUpdateTimerTask(), 0, 1000); + + //webView.loadUrl("javascript:(function() { ActivateSelectControl();})()"); + + + } + + public class MyOnItemSelectedListener implements OnItemSelectedListener { + + public WebView webView = null; + + + MyOnItemSelectedListener(WebView selectWebView) + { + webView = selectWebView; + } + + public void onItemSelected(AdapterView parent, + View view, int pos, long id) { + + if (pos == 0) + { + JniWrapper.ChangeMapType(0); + webView.loadUrl("javascript:(function() { DeactivateSelectControl();})()"); + } + else + { + JniWrapper.ChangeMapType(1); + webView.loadUrl("javascript:(function() { ActivateSelectControl();})()"); + } + } + + + public void onNothingSelected(AdapterView parent) { + // Do nothing. + } + } + + + + class MapUpdateTimerTask extends TimerTask + { + + @Override + public void run() + { + WebView webView = (WebView) findViewById(R.id.webView); + webView.loadUrl("javascript:(function() { Clear();})()"); + + int userCount = JniWrapper.GetNumberOfUsers(); + + for (int i=0; i mAdapter; + + Handler mHandler = new Handler(); + + @Override + protected void onCreate(Bundle icicle) + { + JniWrapper.messagesActivity = this; + + super.onCreate(icicle); + + setContentView(R.layout.messages_layout); + + Button backbtn = (Button) findViewById(R.id.backButton_messages); + backbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), MainMenuActivity.class); + startActivityForResult(myIntent, 0); + JniWrapper.messagesActivity = null; + } + }); + + Button sendmessagebtn = (Button) findViewById(R.id.sendMessageButton); + sendmessagebtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), SendMessageActivity.class); + startActivityForResult(myIntent, 0); + JniWrapper.messagesActivity = null; + } + }); + + + EditText editView = (EditText) findViewById(R.id.currentMessageEdit); + + editView.setKeyListener(null); + + + mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, JniWrapper.messages_headers); + + ListView messageListView = (ListView)findViewById(R.id.messageListView2); + + messageListView.setAdapter(mAdapter); + + messageListView.setOnItemClickListener(new ListView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView a, View v, int i, long l) + { + EditText editView = (EditText) findViewById(R.id.currentMessageEdit); + + editView.setText(JniWrapper.messages_texts.get(i)); + } + }); + + } + + public void RefreshMessageList() + { + //mAdapter.notifyDataSetChanged(); + + Runnable TheDelegatedTimerTask= new Runnable() { + @Override public void run() { // function called by main thread when posted message is dequeued + + mAdapter.notifyDataSetChanged(); + + } + }; + + mHandler.post(TheDelegatedTimerTask); + } +} \ No newline at end of file diff --git a/KObserverAndroid/src/fishrungames/kobserver/ProfileActivity.java b/KObserverAndroid/src/fishrungames/kobserver/ProfileActivity.java new file mode 100644 index 0000000..95cc1f0 --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/ProfileActivity.java @@ -0,0 +1,151 @@ +package fishrungames.kobserver; + +import java.util.ArrayList; +import java.util.Arrays; + +import fishrungames.kobserver.JniWrapper; + +import android.app.Activity; +import android.content.Intent; + +import android.os.Bundle; + +import android.view.View; + +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.Spinner; + + +public class ProfileActivity extends Activity +{ + + ArrayAdapter spinnerAdapter; + + @Override + protected void onCreate(Bundle icicle) + { + + super.onCreate(icicle); + + setContentView(R.layout.profile_layout); + + Button backbtn = (Button) findViewById(R.id.backButton_profile); + backbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), MainMenuActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + + EditText lastNameEdit = (EditText) findViewById(R.id.lastNameEdit); + + EditText firstNameEdit = (EditText) findViewById(R.id.firstNameEdit); + + EditText middleNameEdit = (EditText) findViewById(R.id.middleNameEdit); + + EditText contactNumberEdit = (EditText) findViewById(R.id.contactNumberEdit); + + EditText uikNumberEdit = (EditText) findViewById(R.id.uikNumberEdit); + + lastNameEdit.setText(JniWrapper.LastName); + firstNameEdit.setText(JniWrapper.FirstName); + middleNameEdit.setText(JniWrapper.MiddleName); + contactNumberEdit.setText(JniWrapper.ContactNumber); + uikNumberEdit.setText(Integer.toString(JniWrapper.UikNumber)); + + + + if (JniWrapper.MapState >= 2) + { + CheckBox alarmCheckBox = (CheckBox) findViewById(R.id.alarmCheckBox); + alarmCheckBox.setChecked(true); + + + } + + + Spinner statusSpinner = (Spinner) findViewById(R.id.statusSpinner); + + ArrayList strings = + new ArrayList(Arrays.asList("", " ")); + + spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, strings); + + statusSpinner.setAdapter(spinnerAdapter); + + statusSpinner.setSelection(JniWrapper.Status); + + + + Button updateUserinfoButton = (Button) findViewById(R.id.updateUserinfoButton); + updateUserinfoButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + //Intent myIntent = new Intent(view.getContext(), MainMenuActivity.class); + //startActivityForResult(myIntent, 0); + + //LocationManager m = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + + EditText lastNameEdit = (EditText) findViewById(R.id.lastNameEdit); + + EditText firstNameEdit = (EditText) findViewById(R.id.firstNameEdit); + + EditText middleNameEdit = (EditText) findViewById(R.id.middleNameEdit); + + EditText contactNumberEdit = (EditText) findViewById(R.id.contactNumberEdit); + + EditText uikNumberEdit = (EditText) findViewById(R.id.uikNumberEdit); + + Spinner statusSpinner = (Spinner) findViewById(R.id.statusSpinner); + + int mapState; + + int status = statusSpinner.getSelectedItemPosition(); + + if (status == 1) + { + mapState = 0; + } + else + { + CheckBox alarmCheckBox = (CheckBox) findViewById(R.id.alarmCheckBox); + + if (alarmCheckBox.isChecked()) + { + mapState = 2; + } + else + { + mapState = 1; + } + } + + JniWrapper.LastName = lastNameEdit.getText().toString(); + JniWrapper.FirstName = firstNameEdit.getText().toString(); + JniWrapper.MiddleName = middleNameEdit.getText().toString(); + JniWrapper.ContactNumber = contactNumberEdit.getText().toString(); + JniWrapper.MapState = mapState; + + JniWrapper.UikNumber = Integer.parseInt(uikNumberEdit.getText().toString()); + JniWrapper.Status = status; + JniWrapper.PosX = 30.215800f; + JniWrapper.PosY = 60.005200f; + + + JniWrapper.UpdateUserInfo(JniWrapper.LastName, + JniWrapper.FirstName, + JniWrapper.MiddleName, + JniWrapper.ContactNumber, + JniWrapper.MapState, + JniWrapper.UikNumber, + JniWrapper.Status, + JniWrapper.PosX, + JniWrapper.PosY); + } + }); + + } +} \ No newline at end of file diff --git a/KObserverAndroid/src/fishrungames/kobserver/SendMessageActivity.java b/KObserverAndroid/src/fishrungames/kobserver/SendMessageActivity.java new file mode 100644 index 0000000..acf3074 --- /dev/null +++ b/KObserverAndroid/src/fishrungames/kobserver/SendMessageActivity.java @@ -0,0 +1,51 @@ +package fishrungames.kobserver; + +import fishrungames.kobserver.JniWrapper; + +import android.app.Activity; +import android.content.Intent; + +import android.os.Bundle; + +import android.view.View; + +import android.widget.Button; +import android.widget.EditText; + + +public class SendMessageActivity extends Activity +{ + + @Override + protected void onCreate(Bundle icicle) + { + + super.onCreate(icicle); + + setContentView(R.layout.send_message_layout); + + Button backbtn = (Button) findViewById(R.id.backButton_send_message); + backbtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Intent myIntent = new Intent(view.getContext(), MessagesActivity.class); + startActivityForResult(myIntent, 0); + } + }); + + + + + Button sendMessageButton = (Button) findViewById(R.id.sendMessageButton); + sendMessageButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + + EditText messageEdit = (EditText) findViewById(R.id.messageEdit); + + JniWrapper.SendMessage(messageEdit.getText().toString()); + + messageEdit.setText(""); + } + }); + + } +} \ No newline at end of file diff --git a/common/ClientSocket.cpp b/common/ClientSocket.cpp new file mode 100644 index 0000000..a82d9b4 --- /dev/null +++ b/common/ClientSocket.cpp @@ -0,0 +1,332 @@ +#include "ClientSocket.h" + + +TClientSocket::TClientSocket(boost::asio::io_service& io_service) + : Socket(io_service) + , IoService(io_service) + , AutorizationCodeResult(" ") + , BlockCloseOnError(false) + , BlockForceCloseMessage(false) +{ +} + + +void TClientSocket::Open(std::string address, std::string port) +{ + boost::asio::ip::tcp::resolver resolver(IoService); + + boost::asio::ip::tcp::resolver::query query(address.c_str(), port.c_str()); + + boost::system::error_code ec; + + boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query, ec); + + boost::asio::ip::tcp::resolver::iterator end; + + if (ec) + { + OnAddressNotResolved(); + return; + } + + boost::asio::async_connect(Socket, iterator, boost::bind(&TClientSocket::HandleConnect, shared_from_this(), boost::asio::placeholders::error)); + + + ConnectionTimeoutTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3))); + + + ConnectionTimeoutTimer->async_wait(boost::bind(&TClientSocket::ConnectTimeout, this, boost::asio::placeholders::error)); +} + +void TClientSocket::ConnectTimeout(const boost::system::error_code& e) +{ + if (e) + { + return; + } + + Socket.cancel(); + BlockCloseOnError = true; + + IoService.stop(); + + ReceiveForceCloseSignal(); +} + +void TClientSocket::OnAddressNotResolved() +{ + + BlockCloseOnError = true; + IoService.stop(); + + ReceiveForceCloseSignal(); +} + + +void TClientSocket::HandleConnect(const boost::system::error_code& error) +{ + if (!error) + { + ConnectionTimeoutTimer->cancel(); + boost::asio::async_read(Socket, boost::asio::buffer(&AutorizationCode, 4), boost::bind(&TClientSocket::HandleReadAutorizationCode, shared_from_this(), boost::asio::placeholders::error)); + } + else + { + if (!BlockCloseOnError) + { + CloseImmediate(); + } + } +} + + + +void TClientSocket::HandleReadAutorizationCode(const boost::system::error_code& error) +{ + if (!error) + { + AutorizationCodeResponce = check_func(AutorizationCode); + + boost::asio::async_write(Socket, boost::asio::buffer(&AutorizationCodeResponce, 4), boost::bind(&TClientSocket::HandleWrite, shared_from_this(), boost::asio::placeholders::error)); + + ReadData.resize(16); + + boost::asio::async_read(Socket, boost::asio::buffer(&ReadData[0], 16), boost::bind(&TClientSocket::HandleReadAutorizationResult, shared_from_this(), boost::asio::placeholders::error)); + + ReceiveAutorizationSentSignal(); + } + else + { + if (!BlockCloseOnError) + { + CloseImmediate(); + } + } +} + +void TClientSocket::HandleReadAutorizationResult(const boost::system::error_code& error) +{ + if (!error) + { + AutorizationCodeResult = std::string(ReadData.begin(), ReadData.begin() + 2); + if (AutorizationCodeResult == "ok") + { + BaseLon = (reinterpret_cast(&ReadData[0]))[1]; + BaseLat = (reinterpret_cast(&ReadData[0]))[2]; + BaseZoom = (reinterpret_cast(&ReadData[0]))[3]; + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TClientSocket::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + } + } + else + { + if (!BlockCloseOnError) + { + CloseImmediate(); + } + } +} + +void TClientSocket::HandleReadSignal(const boost::system::error_code& error) +{ + if (!error) + { + boost::asio::async_read(Socket, boost::asio::buffer(&ReadDataLenLong, 4), boost::bind(&TClientSocket::HandleReadDataLen, shared_from_this(), boost::asio::placeholders::error)); + + + } + else + { + if (!BlockCloseOnError) + { + CloseImmediate(); + } + } +} + +void TClientSocket::HandleReadDataLen(const boost::system::error_code& error) +{ + if (!error) + { + ReadData.resize(ReadDataLenLong); + if (ReadDataLenLong == 0) + { + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TClientSocket::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + + if (LastSignal == 4) + { + + } + else if (LastSignal == 1) + { + std::vector userInfoArr; + + ReceiveMapSignal(userInfoArr); + + } + else if (LastSignal == 2) + { + std::vector userInfoArr; + + ReceiveAlarmMapSignal(userInfoArr); + } + + } + else + { + boost::asio::async_read(Socket, boost::asio::buffer(&ReadData[0], ReadDataLenLong), boost::bind(&TClientSocket::HandleReadData, shared_from_this(), boost::asio::placeholders::error)); + + + + } + } + else + { + if (!BlockCloseOnError) + { + CloseImmediate(); + } + } +} + +void TClientSocket::HandleReadData(const boost::system::error_code& error) +{ + if (!error) + { + + if (LastSignal == 4) + { + std::string message; + TUserInfo userInfo; + + DecodeMessage(ReadData, userInfo, message); + + ReceiveMessageSignal(userInfo, message); + } + else if (LastSignal == 1) + { + std::vector userInfoArr; + + DecodeMapUpdateResponce(ReadData, userInfoArr); + + ReceiveMapSignal(userInfoArr); + + } + else if (LastSignal == 2) + { + std::vector userInfoArr; + + DecodeAlarmMapUpdateResponce(ReadData, userInfoArr); + + ReceiveAlarmMapSignal(userInfoArr); + } + + + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TClientSocket::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + } + else + { + if (!BlockCloseOnError) + { + CloseImmediate(); + } + } +} + + +void TClientSocket::HandleWrite(const boost::system::error_code& error) +{ + if (error) + { + if (!BlockCloseOnError) + { + CloseImmediate(); + } + } +} + + + void TClientSocket::CloseImmediate() +{ + // Cancel all outstanding asynchronous operations. + + BlockCloseOnError = true; + + ConnectionTimeoutTimer->cancel(); + + Socket.close(); + + if (!BlockForceCloseMessage) + { + ReceiveForceCloseSignal(); + } + +} + + +void TClientSocket::SendMessageImmediate(std::string msg) +{ + boost::shared_ptr(new TMessageSender(Socket, CONST_SIGNAL_MESSAGE, CreateMessage(UserInfo, msg)))->Send(); +} + +void TClientSocket::SendUserinfoUpdateImmediate() +{ + boost::shared_ptr(new TMessageSender(Socket, 3, CreateProfileUpdateQuery(UserInfo)))->Send(); +} + +void TClientSocket::SendHeartbeatImmediate() +{ + boost::shared_ptr(new TMessageSender(Socket, 5, CreateHeartBeatQuery(UserInfo)))->Send(); +} + +void TClientSocket::SendMapQueryImmediate() +{ + boost::shared_ptr(new TSignalSender(Socket, 1))->Send(); +} + +void TClientSocket::SendAlarmMapQueryImmediate() +{ + boost::shared_ptr(new TSignalSender(Socket, 2))->Send(); +} + +void TClientSocket::SendKickPlayerImmediate(std::string lastName, std::string firstName, std::string middleName) +{ + boost::shared_ptr(new TMessageSender(Socket, 100, CreateKickPlayerSignal(lastName, firstName, middleName)))->Send(); +} + + +void TClientSocket::CloseThreaded() +{ + IoService.post(boost::bind(&TClientSocket::CloseImmediate, this)); +} + +void TClientSocket::SendMessageThreaded(std::string msg) +{ + IoService.post(boost::bind(&TClientSocket::SendMessageImmediate, this, msg)); +} + +void TClientSocket::SendUserinfoUpdateThreaded() +{ + IoService.post(boost::bind(&TClientSocket::SendUserinfoUpdateImmediate, this)); +} + +void TClientSocket::SendHeartbeatThreaded() +{ + IoService.post(boost::bind(&TClientSocket::SendHeartbeatImmediate, this)); +} + +void TClientSocket::SendMapQueryThreaded() +{ + IoService.post(boost::bind(&TClientSocket::SendMapQueryImmediate, this)); +} + +void TClientSocket::SendAlarmMapQueryThreaded() +{ + IoService.post(boost::bind(&TClientSocket::SendAlarmMapQueryImmediate, this)); +} + +void TClientSocket::SendKickPlayerThreaded(std::string lastName, std::string firstName, std::string middleName) +{ + IoService.post(boost::bind(&TClientSocket::SendKickPlayerImmediate, this, lastName, firstName, middleName)); +} + + diff --git a/common/ClientSocket.h b/common/ClientSocket.h new file mode 100644 index 0000000..89678f7 --- /dev/null +++ b/common/ClientSocket.h @@ -0,0 +1,80 @@ +#ifndef CLIENT_SOCKET_H_INCLUDED +#define CLIENT_SOCKET_H_INCLUDED + +#include "UserInfo.h" +#include "misc.h" +#include "MessageSender.h" + + +struct TClientSocket + : public boost::enable_shared_from_this +{ + boost::asio::ip::tcp::socket Socket; + boost::asio::io_service& IoService; + + boost::shared_ptr ConnectionTimeoutTimer; + + int AutorizationCode; + int AutorizationCodeResponce; + std::string AutorizationCodeResult; + float BaseLon; + float BaseLat; + int BaseZoom; + + int LastSignal; + int ReadDataLenLong; + std::vector ReadData; + + TUserInfo UserInfo; + + bool BlockCloseOnError; + bool BlockForceCloseMessage; + + TClientSocket(boost::asio::io_service& io_service); + + void Open(std::string address, std::string port); + + void ConnectTimeout(const boost::system::error_code& e); + void OnAddressNotResolved(); + + void HandleConnect(const boost::system::error_code& error); + + void HandleReadAutorizationCode(const boost::system::error_code& error); + void HandleReadAutorizationResult(const boost::system::error_code& error); + + void HandleReadSignal(const boost::system::error_code& error); + void HandleReadDataLen(const boost::system::error_code& error); + void HandleReadData(const boost::system::error_code& error); + + void HandleWrite(const boost::system::error_code& error); + + void CloseImmediate(); + + + void SendMessageImmediate(std::string msg); + void SendUserinfoUpdateImmediate(); + void SendHeartbeatImmediate(); + void SendMapQueryImmediate(); + void SendAlarmMapQueryImmediate(); + void SendKickPlayerImmediate(std::string lastName, std::string firstName, std::string middleName); + + void CloseThreaded(); + + void SendMessageThreaded(std::string msg); + void SendUserinfoUpdateThreaded(); + void SendHeartbeatThreaded(); + void SendMapQueryThreaded(); + void SendAlarmMapQueryThreaded(); + void SendKickPlayerThreaded(std::string lastName, std::string firstName, std::string middleName); + + boost::signal ReceiveMessageSignal; + boost::signal userInfoArr)> ReceiveMapSignal; + boost::signal userInfoArr)> ReceiveAlarmMapSignal; + boost::signal ReceiveForceCloseSignal; + boost::signal ReceiveAutorizationSentSignal; +}; + + + + +#endif diff --git a/common/MessageSender.cpp b/common/MessageSender.cpp new file mode 100644 index 0000000..4170c0c --- /dev/null +++ b/common/MessageSender.cpp @@ -0,0 +1,429 @@ +#include "MessageSender.h" +#include "misc.h" + + +TSignalSender::TSignalSender(boost::asio::ip::tcp::socket& socket, int messageType) + : Socket(socket) + , MessageType(messageType) +{ +} + +void TSignalSender::Send() +{ + boost::asio::async_write(Socket, boost::asio::buffer(&MessageType, 4), boost::bind(&TSignalSender::Handle, shared_from_this(), boost::asio::placeholders::error)); + +} + +void TSignalSender::Handle(const boost::system::error_code& error) +{ +} + + +TMessageSender::TMessageSender(boost::asio::ip::tcp::socket& socket, int messageType, std::vector messageData) + : Socket(socket) + , MessageType(messageType) + , MessageDataSize(messageData.size()) + , MessageData(messageData) +{ +} + +void TMessageSender::Send() +{ + boost::asio::async_write(Socket, boost::asio::buffer(&MessageType, 4), boost::bind(&TMessageSender::Handle, shared_from_this(), boost::asio::placeholders::error)); + boost::asio::async_write(Socket, boost::asio::buffer(&MessageDataSize, 4), boost::bind(&TMessageSender::Handle, shared_from_this(), boost::asio::placeholders::error)); + + if (MessageDataSize > 0) + { + boost::asio::async_write(Socket, boost::asio::buffer(&MessageData[0], MessageDataSize), boost::bind(&TMessageSender::Handle, shared_from_this(), boost::asio::placeholders::error)); + } +} + +void TMessageSender::Handle(const boost::system::error_code& error) +{ +} + + + +std::vector CreateMessage(const TUserInfo& userInfo, std::string message) +{ + int bufferSize = userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.LastName.size() + userInfo.PhoneNumber.size() + 4 + 4 + 4 + 16 + 4 + message.size() + 1; + + std::vector pBuffer; + + pBuffer.resize(bufferSize); + + //reinterpret_cast(&pBuffer[0])[0] = CONST_SIGNAL_MESSAGE; + //reinterpret_cast(&pBuffer[0])[1] = bufferSize - 8; + reinterpret_cast(&pBuffer[0])[2] = userInfo.MapState; + + /* + if (userInfo.Uik != 0) + { + reinterpret_cast(&pBuffer[0])[3] = CONST_90_DEG; + reinterpret_cast(&pBuffer[0])[4] = userInfo.Uik; + } + else*/ + { + reinterpret_cast(&pBuffer[0])[3] = userInfo.PosX; + reinterpret_cast(&pBuffer[0])[4] = userInfo.PosY; + } + + + + pBuffer[20] = static_cast(userInfo.LastName.size()); + + if (userInfo.LastName.size() != 0) + { + memcpy(&pBuffer[21], &userInfo.LastName[0], userInfo.LastName.size()); + } + + pBuffer[20 + userInfo.LastName.size() + 1] = static_cast(userInfo.FirstName.size()); + + if (userInfo.FirstName.size() != 0) + { + memcpy(&pBuffer[userInfo.LastName.size() + 22], &userInfo.FirstName[0], userInfo.FirstName.size()); + } + + pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + 22] = static_cast(userInfo.MiddleName.size()); + + if (userInfo.MiddleName.size() != 0) + { + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + 23], &userInfo.MiddleName[0], userInfo.MiddleName.size()); + } + + pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + 23] = static_cast(userInfo.PhoneNumber.size()); + + if (userInfo.PhoneNumber.size() != 0) + { + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + 24], &userInfo.PhoneNumber[0], userInfo.PhoneNumber.size()); + } + + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.PhoneNumber.size() + 24], &userInfo.Uik, 4); + + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.PhoneNumber.size() + 28], &userInfo.Status, 4); + + pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.PhoneNumber.size() + 32] = message.size(); + + if (message.size() != 0) + { + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.PhoneNumber.size() + 33], &message[0], message.size()); + } + + pBuffer = std::vector(pBuffer.begin() + 8, pBuffer.end()); + + return pBuffer; +} + + +void DecodeMessage(std::vector msgData, TUserInfo& userInfo, std::string& message) +{ + + userInfo.MapState = *(reinterpret_cast(&msgData[0])); + + userInfo.PosX = *(reinterpret_cast(&msgData[4])); + + if (userInfo.PosX == CONST_90_DEG) + { + userInfo.PosY = 0.f; + userInfo.Uik = *(reinterpret_cast(&msgData[8])); + } + else + { + userInfo.PosY = *(reinterpret_cast(&msgData[8])); + userInfo.Uik = 0; + } + + char lastNameLen = msgData[12]; + + std::string lastName(&msgData[13], &msgData[13 + lastNameLen]); + + char firstNameLen = msgData[13 + lastNameLen]; + + std::string firstName(&msgData[14 + lastNameLen], &msgData[14 + lastNameLen + firstNameLen]); + + char middleNameLen = msgData[14 + lastNameLen + firstNameLen]; + + std::string middleName(&msgData[15 + lastNameLen + firstNameLen], &msgData[15 + lastNameLen + firstNameLen + middleNameLen]); + + char phoneLen = msgData[15 + lastNameLen + firstNameLen + middleNameLen]; + + std::string phone(&msgData[16 + lastNameLen + firstNameLen + middleNameLen], &msgData[16 + lastNameLen + firstNameLen + middleNameLen + phoneLen]); + + int uik; + + memcpy(&uik, &msgData[16 + lastNameLen + firstNameLen + middleNameLen + phoneLen], 4); + + int status; + + memcpy(&status, &msgData[16 + lastNameLen + firstNameLen + middleNameLen + phoneLen + 4], 4); + + userInfo.LastName = lastName; + userInfo.FirstName = firstName; + userInfo.MiddleName = middleName; + userInfo.PhoneNumber = phone; + + userInfo.Uik = uik; + + userInfo.Status = status; + + char messageLen = msgData[16 + lastNameLen + firstNameLen + middleNameLen + phoneLen + 4 + 4]; + + message = std::string(msgData.begin() + (16 + lastNameLen + firstNameLen + middleNameLen + phoneLen + 4 + 4 + 1), msgData.begin() + (16 + lastNameLen + firstNameLen + middleNameLen + phoneLen + 4 + 4 + 1 + messageLen)); + +} + +std::vector CreateKickPlayerSignal(std::string lastName, std::string firstName, std::string middleName) +{ + int bufferSize = lastName.size() + firstName.size() + middleName.size() + 3; + + std::vector pBuffer; + + pBuffer.resize(bufferSize); + + pBuffer[0] = static_cast(lastName.size()); + + if (lastName.size() != 0) + { + memcpy(&pBuffer[1], &lastName[0], lastName.size()); + } + + pBuffer[lastName.size() + 1] = static_cast(firstName.size()); + + if (firstName.size() != 0) + { + memcpy(&pBuffer[lastName.size() + 2], &firstName[0], firstName.size()); + } + + pBuffer[lastName.size() + firstName.size() + 2] = static_cast(middleName.size()); + + if (middleName.size() != 0) + { + memcpy(&pBuffer[lastName.size() + firstName.size() + 3], &middleName[0], middleName.size()); + } + + //pBuffer = std::vector(pBuffer.begin() + 8, pBuffer.end()); + + return pBuffer; +} + +void DecodeKickPlayerSignal(std::vector msgData, std::string& lastName, std::string& firstName, std::string& middleName) +{ + char lastNameLen = msgData[0]; + + if (lastNameLen > 0) + { + lastName = std::string(&msgData[1], &msgData[1 + lastNameLen]); + } + else + { + lastName = ""; + } + + char firstNameLen = msgData[1 + lastNameLen]; + + if (firstNameLen > 0) + { + firstName = std::string(&msgData[2 + lastNameLen], &msgData[2 + lastNameLen + firstNameLen]); + } + else + { + firstName = ""; + } + + char middleNameLen = msgData[2 + lastNameLen + firstNameLen]; + + if (middleNameLen > 0) + { + middleName = std::string(&msgData[3 + lastNameLen + firstNameLen], &msgData[3 + lastNameLen + firstNameLen] + middleNameLen); + } + else + { + middleName = ""; + } +} + + +std::vector CreateProfileUpdateQuery(const TUserInfo& userInfo) +{ + int bufferSize = userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.LastName.size() + userInfo.PhoneNumber.size() + 4 + 16 + 4; + + std::vector pBuffer; + + pBuffer.resize(bufferSize); + + reinterpret_cast(&pBuffer[0])[0] = userInfo.MapState; + + /*if (userInfo.Uik != 0) + { + reinterpret_cast(&pBuffer[0])[1] = CONST_90_DEG; + reinterpret_cast(&pBuffer[0])[2] = userInfo.Uik; + } + else*/ + { + reinterpret_cast(&pBuffer[0])[1] = userInfo.PosX; + reinterpret_cast(&pBuffer[0])[2] = userInfo.PosY; + } + + + pBuffer[12] = static_cast(userInfo.LastName.size()); + + if (userInfo.LastName.size() != 0) + { + memcpy(&pBuffer[13], &userInfo.LastName[0], userInfo.LastName.size()); + } + + pBuffer[12 + userInfo.LastName.size() + 1] = static_cast(userInfo.FirstName.size()); + + if (userInfo.FirstName.size() != 0) + { + memcpy(&pBuffer[userInfo.LastName.size() + 14], &userInfo.FirstName[0], userInfo.FirstName.size()); + } + + pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + 14] = static_cast(userInfo.MiddleName.size()); + + if (userInfo.MiddleName.size() != 0) + { + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + 15], &userInfo.MiddleName[0], userInfo.MiddleName.size()); + } + + pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + 15] = static_cast(userInfo.PhoneNumber.size()); + + if (userInfo.PhoneNumber.size() != 0) + { + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + 16], &userInfo.PhoneNumber[0], userInfo.PhoneNumber.size()); + } + + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.PhoneNumber.size() + 16], &userInfo.Uik, 4); + + memcpy(&pBuffer[userInfo.LastName.size() + userInfo.FirstName.size() + userInfo.MiddleName.size() + userInfo.PhoneNumber.size() + 20], &userInfo.Status, 4); + + return pBuffer; +} + +void DecodeProfileUpdateQuery(std::vector& msgData, TUserInfo& userInfo) +{ + userInfo.MapState = *(reinterpret_cast(&msgData[0])); + + userInfo.PosX = *(reinterpret_cast(&msgData[4])); + + if (userInfo.PosX == CONST_90_DEG) + { + userInfo.PosY = 0.f; + userInfo.Uik = *(reinterpret_cast(&msgData[8])); + } + else + { + userInfo.PosY = *(reinterpret_cast(&msgData[8])); + userInfo.Uik = 0; + } + + char lastNameLen = msgData[12]; + + std::string lastName(&msgData[13], &msgData[13 + lastNameLen]); + + char firstNameLen = msgData[13 + lastNameLen]; + + std::string firstName(&msgData[14 + lastNameLen], &msgData[14 + lastNameLen + firstNameLen]); + + char middleNameLen = msgData[14 + lastNameLen + firstNameLen]; + + std::string middleName(&msgData[15 + lastNameLen + firstNameLen], &msgData[15 + lastNameLen + firstNameLen + middleNameLen]); + + char phoneLen = msgData[15 + lastNameLen + firstNameLen + middleNameLen]; + + std::string phone(&msgData[16 + lastNameLen + firstNameLen + middleNameLen], &msgData[16 + lastNameLen + firstNameLen + middleNameLen + phoneLen]); + + int uik; + + memcpy(&uik, &msgData[16 + lastNameLen + firstNameLen + middleNameLen + phoneLen], 4); + + int status; + + memcpy(&status, &msgData[16 + lastNameLen + firstNameLen + middleNameLen + phoneLen + 4], 4); + + userInfo.LastName = lastName; + userInfo.FirstName = firstName; + userInfo.MiddleName = middleName; + userInfo.PhoneNumber = phone; + + userInfo.Uik = uik; + + userInfo.Status = status; + + int bufferSize = 16 + lastNameLen + firstNameLen + middleNameLen + phoneLen + 4 + 4; + + msgData.erase(msgData.begin(), msgData.begin() + bufferSize); +} + + + +std::vector CreateHeartBeatQuery(const TUserInfo& userInfo) +{ + int bufferSize = 12; + + std::vector pBuffer; + + pBuffer.resize(bufferSize); + + reinterpret_cast(&pBuffer[0])[0] = userInfo.MapState; + + /*if (userInfo.Uik != 0) + { + reinterpret_cast(&pBuffer[0])[1] = CONST_90_DEG; + reinterpret_cast(&pBuffer[0])[2] = userInfo.Uik; + } + else*/ + { + reinterpret_cast(&pBuffer[0])[1] = userInfo.PosX; + reinterpret_cast(&pBuffer[0])[2] = userInfo.PosY; + } + + return pBuffer; +} + +void DecodeHeartBeatQuery(std::vector& msgData, TUserInfo& userInfo) +{ + userInfo.MapState = *(reinterpret_cast(&msgData[0])); + + userInfo.PosX = *(reinterpret_cast(&msgData[4])); + + if (userInfo.PosX == CONST_90_DEG) + { + userInfo.PosY = 0.f; + userInfo.Uik = *(reinterpret_cast(&msgData[8])); + } + else + { + userInfo.PosY = *(reinterpret_cast(&msgData[8])); + //userInfo.Uik = 0; + + } + + msgData.erase(msgData.begin(), msgData.begin() + 12); +} + +void DecodeMapUpdateResponce(std::vector msgData, std::vector& userInfoArr) +{ + while (msgData.size() >= 12) + { + TUserInfo userInfo; + + DecodeHeartBeatQuery(msgData, userInfo); + + userInfoArr.push_back(userInfo); + + } +} + +void DecodeAlarmMapUpdateResponce(std::vector msgData, std::vector& userInfoArr) +{ + while (msgData.size() > 0) + { + TUserInfo userInfo; + + DecodeProfileUpdateQuery(msgData, userInfo); + + userInfoArr.push_back(userInfo); + + } +} diff --git a/common/MessageSender.h b/common/MessageSender.h new file mode 100644 index 0000000..4598f47 --- /dev/null +++ b/common/MessageSender.h @@ -0,0 +1,71 @@ +#ifndef MESSAGE_SENDER_H_INCLUDED +#define MESSAGE_SENDER_H_INCLUDED + + +#include "UserInfo.h" + + +struct TSignalSender + : public boost::enable_shared_from_this +{ + boost::asio::ip::tcp::socket& Socket; + + int MessageType; + + TSignalSender(boost::asio::ip::tcp::socket& socket, int messageType); + + void Send(); + + void Handle(const boost::system::error_code& error); +}; + + +struct TMessageSender + : public boost::enable_shared_from_this +{ + boost::asio::ip::tcp::socket& Socket; + + int MessageType; + + int MessageDataSize; + + std::vector MessageData; + + TMessageSender(boost::asio::ip::tcp::socket& socket, int messageType, std::vector messageData); + + void Send(); + + void Handle(const boost::system::error_code& error); +}; + + + + + +std::vector CreateMessage(const TUserInfo& userInfo, std::string message); + +void DecodeMessage(std::vector msgData, TUserInfo& userInfo, std::string& message); + + +std::vector CreateKickPlayerSignal(std::string lastName, std::string firstName, std::string middleName); + +void DecodeKickPlayerSignal(std::vector msgData, std::string& lastName, std::string& firstName, std::string& middleName); + + + + +std::vector CreateProfileUpdateQuery(const TUserInfo& userInfo); + +void DecodeProfileUpdateQuery(std::vector& msgData, TUserInfo& userInfo); + + +std::vector CreateHeartBeatQuery(const TUserInfo& userInfo); + +void DecodeHeartBeatQuery(std::vector& msgData, TUserInfo& userInfo); + +void DecodeMapUpdateResponce(std::vector msgData, std::vector& userInfoArr); + +void DecodeAlarmMapUpdateResponce(std::vector msgData, std::vector& userInfoArr); + + +#endif diff --git a/common/UserInfo.cpp b/common/UserInfo.cpp new file mode 100644 index 0000000..ee459da --- /dev/null +++ b/common/UserInfo.cpp @@ -0,0 +1,13 @@ +#include "UserInfo.h" + +TUserInfo::TUserInfo() + : PosX(0) + , PosY(0) + , MapState(1) + , LastName("Anonymous") + , FirstName("Anonymous") + , MiddleName("Anonymous") + , Uik(0) + , Status(0) +{ +} \ No newline at end of file diff --git a/common/UserInfo.h b/common/UserInfo.h new file mode 100644 index 0000000..33f5f30 --- /dev/null +++ b/common/UserInfo.h @@ -0,0 +1,41 @@ +#ifndef USERINFO_H_INCLUDED +#define USERINFO_H_INCLUDED + +#include "boost/asio.hpp" +#include "boost/bind.hpp" +#include "boost/shared_ptr.hpp" +#include "boost/array.hpp" +#include "boost/enable_shared_from_this.hpp" +#include "boost/signal.hpp" +#include "boost/thread.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" + + + +struct TUserInfo +{ + + float PosX; + float PosY; + + size_t MapState; + + std::string FirstName; + std::string MiddleName; + std::string LastName; + + std::string PhoneNumber; + + size_t Uik; + + size_t Status; + + TUserInfo(); + +}; + + + + + +#endif diff --git a/common/linux_stuff.cpp b/common/linux_stuff.cpp new file mode 100644 index 0000000..c6e517a --- /dev/null +++ b/common/linux_stuff.cpp @@ -0,0 +1,57 @@ +#ifndef _WIN32 + +#include "linux_stuff.h" +#include + +void daemonize() +{ + /* Our process ID and Session ID */ + pid_t pid, sid; + + /* Fork off the parent process */ + pid = fork(); + if (pid < 0) + { + std::cout<<"error, pid < 0"< 0) { + std::cout<<"pid > 0 exit process"< +#include +#include +#include +#include +#include +#include +#include +#include + + + +void daemonize(); + + + +#endif + + + +#endif \ No newline at end of file diff --git a/common/misc.cpp b/common/misc.cpp new file mode 100644 index 0000000..ce2e791 --- /dev/null +++ b/common/misc.cpp @@ -0,0 +1,15 @@ +#include "misc.h" + + +const float CONST_90_DEG = 90.f; + +const int CONST_SIGNAL_MESSAGE = 4; + +const std::string CONST_OK = "ok"; + +const int CONST_MAP_STATE_ALARM = 2; + +int check_func(int x) +{ + return x*x; +} \ No newline at end of file diff --git a/common/misc.h b/common/misc.h new file mode 100644 index 0000000..4f12a3c --- /dev/null +++ b/common/misc.h @@ -0,0 +1,19 @@ +#ifndef MISC_H_INCLUDED +#define MISC_H_INCLUDED + +#include "UserInfo.h" + + +extern const float CONST_90_DEG; + +extern const int CONST_SIGNAL_MESSAGE; + +extern const std::string CONST_OK; + +extern const int CONST_MAP_STATE_ALARM; + +int check_func(int x); + + + +#endif \ No newline at end of file diff --git a/k_observer_client/Debug/k_observer_client.exe b/k_observer_client/Debug/k_observer_client.exe new file mode 100644 index 0000000..bf64a51 Binary files /dev/null and b/k_observer_client/Debug/k_observer_client.exe differ diff --git a/k_observer_client/k_observer_client.sln b/k_observer_client/k_observer_client.sln new file mode 100644 index 0000000..6202beb --- /dev/null +++ b/k_observer_client/k_observer_client.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C++ Express 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "k_observer_client", "k_observer_client\k_observer_client.vcxproj", "{D5128D35-C07B-40B1-BB51-884A79072B57}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D5128D35-C07B-40B1-BB51-884A79072B57}.Debug|Win32.ActiveCfg = Debug|Win32 + {D5128D35-C07B-40B1-BB51-884A79072B57}.Debug|Win32.Build.0 = Debug|Win32 + {D5128D35-C07B-40B1-BB51-884A79072B57}.Release|Win32.ActiveCfg = Release|Win32 + {D5128D35-C07B-40B1-BB51-884A79072B57}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/k_observer_client/k_observer_client/k_observer_client.vcxproj b/k_observer_client/k_observer_client/k_observer_client.vcxproj new file mode 100644 index 0000000..789d103 --- /dev/null +++ b/k_observer_client/k_observer_client/k_observer_client.vcxproj @@ -0,0 +1,87 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {D5128D35-C07B-40B1-BB51-884A79072B57} + k_observer_client + + + + Application + true + NotSet + + + Application + false + true + NotSet + + + + + + + + + + + + + + + Level3 + Disabled + $(LibsPath)\boost_1_47_0;../../common + _WIN32_WINNT=0x0501 + + + true + $(LibsPath)\boost_1_47_0\boost_windows\libs_engine\debug + + + + + Level3 + MaxSpeed + true + true + $(LibsPath)\boost_1_47_0;../../common + _WIN32_WINNT=0x0501 + + + true + true + true + $(LibsPath)\boost_1_47_0\boost_windows\libs_engine\release + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/k_observer_client/k_observer_client/main.cpp b/k_observer_client/k_observer_client/main.cpp new file mode 100644 index 0000000..c4076f0 --- /dev/null +++ b/k_observer_client/k_observer_client/main.cpp @@ -0,0 +1,100 @@ +#include "main.h" + +TUserInfo CustomUserInfo; + +void OnAutorizationSend(boost::shared_ptr c) +{/* + c->UserInfo.PosX = 37.443195f; + c->UserInfo.PosY = 55.888869f; + c->UserInfo.LastName = std::string("Bot"); + c->UserInfo.FirstName = std::string("Mobile"); + c->UserInfo.MiddleName = std::string("Idle"); + c->UserInfo.PhoneNumber = std::string("+75551234567"); + c->UserInfo.Uik = 1; + c->UserInfo.MapState = 0; + c->UserInfo.Status = 1; + */ + c->SendUserinfoUpdateThreaded(); +} + + + +int main(int argc, char *argv[]) +{ + +#ifndef _WIN32 + daemonize(); +#endif + + srand(static_cast(time(0))); + + + try + { + std::string fileName; + + if (argc < 2) + { + fileName = "botdata.txt"; + } + else + { + fileName = std::string(argv[1]); + + if (fileName == "") + { + fileName = "botdata.txt"; + } + } + + std::cout<<"File name is - '"<>CustomUserInfo.LastName; + f>>CustomUserInfo.FirstName; + f>>CustomUserInfo.MiddleName; + f>>CustomUserInfo.PhoneNumber; + f>>CustomUserInfo.PosX; + f>>CustomUserInfo.PosY; + f>>CustomUserInfo.MapState; + f>>CustomUserInfo.Uik; + f>>CustomUserInfo.Status; + + f.close(); + + } + else + { + std::cout<<"File not found, loading default data :("< c(new TClientSocket(io_service)); + + c->UserInfo = CustomUserInfo; + + c->Open("k-observer.org", "1984"); + + boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service)); + + c->ReceiveAutorizationSentSignal.connect(boost::bind(&OnAutorizationSend, c)); + + t.join(); + } + catch (std::exception& e) + { + std::cerr << "Exception: " << e.what() << "\n"; + } + + return 0; +} \ No newline at end of file diff --git a/k_observer_client/k_observer_client/main.h b/k_observer_client/k_observer_client/main.h new file mode 100644 index 0000000..ed8651d --- /dev/null +++ b/k_observer_client/k_observer_client/main.h @@ -0,0 +1,18 @@ +#include + +#include "boost/asio.hpp" +#include "boost/bind.hpp" +#include "boost/shared_ptr.hpp" +#include "boost/shared_array.hpp" +#include "boost/array.hpp" +#include "boost/enable_shared_from_this.hpp" +#include "boost/thread.hpp" + +#include +#include +#include +#include + +#include "ClientSocket.h" + +#include "linux_stuff.h" \ No newline at end of file diff --git a/k_observer_client/linux/makefile b/k_observer_client/linux/makefile new file mode 100644 index 0000000..4704f35 --- /dev/null +++ b/k_observer_client/linux/makefile @@ -0,0 +1,54 @@ +CC=g++ +CFLAGS=-Wall -O3 -I../../../boost_1_47_0 +LDFLAGS= -lpthread + +#thread +LOCAL_SRC_FILES := ../../../boost_1_47_0/libs/thread/src/pthread/thread.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/thread/src/pthread/once.cpp + +#signals +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/connection.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/named_slot_map.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/signal_base.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/slot.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/trackable.cpp + +#system +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/system/src/error_code.cpp + +#regex +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/c_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/cpp_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/cregex.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/fileiter.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/icu.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/instances.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/posix_api.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex_debug.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex_raw_buffer.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex_traits_defaults.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/static_mutex.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/usinstances.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/w32_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/wc_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/wide_posix_api.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/winstances.cpp + +#date_time +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/date_time/src/gregorian/greg_month.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/date_time/src/gregorian/greg_weekday.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/date_time/src/gregorian/date_generators.cpp + + +CFLAGS += -I../../common +CFLAGS += -I../k_observer_client +LOCAL_SRC_FILES += ../k_observer_client/main.cpp +LOCAL_SRC_FILES += ../../common/ClientSocket.cpp +LOCAL_SRC_FILES += ../../common/MessageSender.cpp +LOCAL_SRC_FILES += ../../common/misc.cpp +LOCAL_SRC_FILES += ../../common/UserInfo.cpp +LOCAL_SRC_FILES += ../../common/linux_stuff.cpp + +all: + $(CC) $(LOCAL_SRC_FILES) $(CFLAGS) $(LDFLAGS) -o k_observer_client_bot \ No newline at end of file diff --git a/k_observer_client/serverdata.txt b/k_observer_client/serverdata.txt new file mode 100644 index 0000000..341f0d2 --- /dev/null +++ b/k_observer_client/serverdata.txt @@ -0,0 +1,8 @@ + - . : k-observer.org 1996 + - . : +http://itunes.apple.com/us/app/k-vybory/id558631995?l=ru + Android: +https://play.google.com/store/apps/details?id=fishrungames.kobserver + + : +http://fishrungames.com/?page_id=48 \ No newline at end of file diff --git a/k_observer_iphone/k-observer-iphone/assets/alarm_text.png b/k_observer_iphone/k-observer-iphone/assets/alarm_text.png new file mode 100644 index 0000000..993fdc9 Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/assets/alarm_text.png differ diff --git a/k_observer_iphone/k-observer-iphone/assets/button.png b/k_observer_iphone/k-observer-iphone/assets/button.png new file mode 100644 index 0000000..94d2157 Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/assets/button.png differ diff --git a/k_observer_iphone/k-observer-iphone/assets/button_alarm.png b/k_observer_iphone/k-observer-iphone/assets/button_alarm.png new file mode 100644 index 0000000..b3f24a3 Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/assets/button_alarm.png differ diff --git a/k_observer_iphone/k-observer-iphone/assets/messages_text.png b/k_observer_iphone/k-observer-iphone/assets/messages_text.png new file mode 100644 index 0000000..d6ab56b Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/assets/messages_text.png differ diff --git a/k_observer_iphone/k-observer-iphone/assets/script.html b/k_observer_iphone/k-observer-iphone/assets/script.html new file mode 100644 index 0000000..c61a5a1 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/assets/script.html @@ -0,0 +1,132 @@ + +OpenLayers Simplest Example +
+ + \ No newline at end of file diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone.xcodeproj/project.pbxproj b/k_observer_iphone/k-observer-iphone/k-observer-iphone.xcodeproj/project.pbxproj new file mode 100644 index 0000000..de1adea --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone.xcodeproj/project.pbxproj @@ -0,0 +1,548 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 4C02E9D915E9F4AA0051A095 /* MainMenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C02E9D715E9F4AA0051A095 /* MainMenuViewController.m */; }; + 4C02E9DA15E9F4AA0051A095 /* MainMenuViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C02E9D815E9F4AA0051A095 /* MainMenuViewController.xib */; }; + 4C02E9E615E9FCF70051A095 /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C02E9E415E9FCF70051A095 /* ProfileViewController.m */; }; + 4C02E9E715E9FCF70051A095 /* ProfileViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C02E9E515E9FCF70051A095 /* ProfileViewController.xib */; }; + 4C02E9F415EA18FB0051A095 /* script.html in Resources */ = {isa = PBXBuildFile; fileRef = 4C02E9F315EA18FB0051A095 /* script.html */; }; + 4C02E9FC15EA1E3C0051A095 /* AlarmViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C02E9F715EA1E3B0051A095 /* AlarmViewController.m */; }; + 4C02E9FD15EA1E3C0051A095 /* AlarmViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C02E9F815EA1E3B0051A095 /* AlarmViewController.xib */; }; + 4C02E9FE15EA1E3C0051A095 /* MapViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C02E9FA15EA1E3C0051A095 /* MapViewController.mm */; }; + 4C02E9FF15EA1E3C0051A095 /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C02E9FB15EA1E3C0051A095 /* MapViewController.xib */; }; + 4C02EA0315EA1E740051A095 /* MessagesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C02EA0115EA1E740051A095 /* MessagesViewController.m */; }; + 4C02EA0415EA1E740051A095 /* MessagesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C02EA0215EA1E740051A095 /* MessagesViewController.xib */; }; + 4C7732CE15ED663F003C49DB /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C7732CD15ED663F003C49DB /* CoreLocation.framework */; }; + 4C79C35C15EBEBC300FE6C7B /* NavigationControllerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C79C35B15EBEBC300FE6C7B /* NavigationControllerDelegate.m */; }; + 4C79C36015EC008F00FE6C7B /* ObserverClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C79C35F15EC008E00FE6C7B /* ObserverClient.mm */; }; + 4C7BE98B15F391E100E87726 /* alarm_text.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7BE98A15F391E100E87726 /* alarm_text.png */; }; + 4C7BE98D15F3954200E87726 /* messages_text.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7BE98C15F3954200E87726 /* messages_text.png */; }; + 4C7BE99415F39E0D00E87726 /* button_alarm.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7BE99215F39E0D00E87726 /* button_alarm.png */; }; + 4C7BE99515F39E0D00E87726 /* button.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7BE99315F39E0D00E87726 /* button.png */; }; + 4C7D07C415F54AB6001DCB2A /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7D07BF15F54AB6001DCB2A /* Icon@2x.png */; }; + 4C7D07C515F54AB6001DCB2A /* Icon-72@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7D07C015F54AB6001DCB2A /* Icon-72@2x.png */; }; + 4C7D07C615F54AB6001DCB2A /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7D07C115F54AB6001DCB2A /* Icon.png */; }; + 4C7D07C715F54AB6001DCB2A /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7D07C215F54AB6001DCB2A /* Icon-72.png */; }; + 4C7D07C815F54AB6001DCB2A /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = 4C7D07C315F54AB6001DCB2A /* iTunesArtwork */; }; + 4C7D07CB15F55E8F001DCB2A /* Splash-portrait.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7D07CA15F55E8F001DCB2A /* Splash-portrait.png */; }; + 4C82990115F9315500E85091 /* ObserverClientCpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C82990015F9315500E85091 /* ObserverClientCpp.cpp */; }; + 4CA1EE5215F005A400469619 /* SendMessageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA1EE5015F005A400469619 /* SendMessageViewController.m */; }; + 4CA1EE5315F005A400469619 /* SendMessageViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CA1EE5115F005A400469619 /* SendMessageViewController.xib */; }; + 4CF8F4BC15E96AB8002E9A61 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CF8F4BB15E96AB8002E9A61 /* UIKit.framework */; }; + 4CF8F4BE15E96AB8002E9A61 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CF8F4BD15E96AB8002E9A61 /* Foundation.framework */; }; + 4CF8F4C015E96AB8002E9A61 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CF8F4BF15E96AB8002E9A61 /* CoreGraphics.framework */; }; + 4CF8F4C615E96AB8002E9A61 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4CF8F4C415E96AB8002E9A61 /* InfoPlist.strings */; }; + 4CF8F4C815E96AB8002E9A61 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8F4C715E96AB8002E9A61 /* main.m */; }; + 4CF8F4CC15E96AB8002E9A61 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8F4CB15E96AB8002E9A61 /* AppDelegate.m */; }; + 4CF8F4CF15E96AB8002E9A61 /* ConnectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8F4CE15E96AB8002E9A61 /* ConnectViewController.m */; }; + 4CF8F4D215E96AB9002E9A61 /* ConnectViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CF8F4D015E96AB9002E9A61 /* ConnectViewController.xib */; }; + 4CF8F4D915E96C0A002E9A61 /* libboost.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CF8F4D815E96C0A002E9A61 /* libboost.a */; }; + 4CF8F4E315E96C4F002E9A61 /* ClientSocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8F4DB15E96C4F002E9A61 /* ClientSocket.cpp */; }; + 4CF8F4E415E96C4F002E9A61 /* MessageSender.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8F4DD15E96C4F002E9A61 /* MessageSender.cpp */; }; + 4CF8F4E515E96C4F002E9A61 /* misc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8F4DF15E96C4F002E9A61 /* misc.cpp */; }; + 4CF8F4E615E96C4F002E9A61 /* UserInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8F4E115E96C4F002E9A61 /* UserInfo.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 4C02E9D615E9F4AA0051A095 /* MainMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainMenuViewController.h; sourceTree = ""; }; + 4C02E9D715E9F4AA0051A095 /* MainMenuViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainMenuViewController.m; sourceTree = ""; }; + 4C02E9D815E9F4AA0051A095 /* MainMenuViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenuViewController.xib; sourceTree = ""; }; + 4C02E9E315E9FCF70051A095 /* ProfileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProfileViewController.h; sourceTree = ""; }; + 4C02E9E415E9FCF70051A095 /* ProfileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProfileViewController.m; sourceTree = ""; }; + 4C02E9E515E9FCF70051A095 /* ProfileViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ProfileViewController.xib; sourceTree = ""; }; + 4C02E9F315EA18FB0051A095 /* script.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = script.html; path = assets/script.html; sourceTree = ""; }; + 4C02E9F615EA1E3B0051A095 /* AlarmViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlarmViewController.h; sourceTree = ""; }; + 4C02E9F715EA1E3B0051A095 /* AlarmViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AlarmViewController.m; sourceTree = ""; }; + 4C02E9F815EA1E3B0051A095 /* AlarmViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AlarmViewController.xib; sourceTree = ""; }; + 4C02E9F915EA1E3C0051A095 /* MapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewController.h; sourceTree = ""; }; + 4C02E9FA15EA1E3C0051A095 /* MapViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MapViewController.mm; sourceTree = ""; }; + 4C02E9FB15EA1E3C0051A095 /* MapViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; + 4C02EA0015EA1E740051A095 /* MessagesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagesViewController.h; sourceTree = ""; }; + 4C02EA0115EA1E740051A095 /* MessagesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessagesViewController.m; sourceTree = ""; }; + 4C02EA0215EA1E740051A095 /* MessagesViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MessagesViewController.xib; sourceTree = ""; }; + 4C7732CD15ED663F003C49DB /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; + 4C79C35A15EBEBC300FE6C7B /* NavigationControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationControllerDelegate.h; sourceTree = ""; }; + 4C79C35B15EBEBC300FE6C7B /* NavigationControllerDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationControllerDelegate.m; sourceTree = ""; }; + 4C79C35E15EC008E00FE6C7B /* ObserverClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObserverClient.h; sourceTree = ""; }; + 4C79C35F15EC008E00FE6C7B /* ObserverClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ObserverClient.mm; sourceTree = ""; }; + 4C7BE98A15F391E100E87726 /* alarm_text.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = alarm_text.png; path = assets/alarm_text.png; sourceTree = ""; }; + 4C7BE98C15F3954200E87726 /* messages_text.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = messages_text.png; path = assets/messages_text.png; sourceTree = ""; }; + 4C7BE99215F39E0D00E87726 /* button_alarm.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = button_alarm.png; path = assets/button_alarm.png; sourceTree = ""; }; + 4C7BE99315F39E0D00E87726 /* button.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = button.png; path = assets/button.png; sourceTree = ""; }; + 4C7D07BF15F54AB6001DCB2A /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@2x.png"; sourceTree = ""; }; + 4C7D07C015F54AB6001DCB2A /* Icon-72@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72@2x.png"; sourceTree = ""; }; + 4C7D07C115F54AB6001DCB2A /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = ""; }; + 4C7D07C215F54AB6001DCB2A /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72.png"; sourceTree = ""; }; + 4C7D07C315F54AB6001DCB2A /* iTunesArtwork */ = {isa = PBXFileReference; lastKnownFileType = file; path = iTunesArtwork; sourceTree = ""; }; + 4C7D07CA15F55E8F001DCB2A /* Splash-portrait.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Splash-portrait.png"; path = "icons/Splash-portrait.png"; sourceTree = ""; }; + 4C8298FE15F9312A00E85091 /* ObserverClientCpp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ObserverClientCpp.h; sourceTree = ""; }; + 4C82990015F9315500E85091 /* ObserverClientCpp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObserverClientCpp.cpp; sourceTree = ""; }; + 4CA1EE4F15F005A400469619 /* SendMessageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SendMessageViewController.h; sourceTree = ""; }; + 4CA1EE5015F005A400469619 /* SendMessageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SendMessageViewController.m; sourceTree = ""; }; + 4CA1EE5115F005A400469619 /* SendMessageViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SendMessageViewController.xib; sourceTree = ""; }; + 4CF8F4B715E96AB8002E9A61 /* k-observer-iphone.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "k-observer-iphone.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4CF8F4BB15E96AB8002E9A61 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 4CF8F4BD15E96AB8002E9A61 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 4CF8F4BF15E96AB8002E9A61 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + 4CF8F4C315E96AB8002E9A61 /* k-observer-iphone-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "k-observer-iphone-Info.plist"; sourceTree = ""; }; + 4CF8F4C515E96AB8002E9A61 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 4CF8F4C715E96AB8002E9A61 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 4CF8F4C915E96AB8002E9A61 /* k-observer-iphone-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "k-observer-iphone-Prefix.pch"; sourceTree = ""; }; + 4CF8F4CA15E96AB8002E9A61 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 4CF8F4CB15E96AB8002E9A61 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 4CF8F4CD15E96AB8002E9A61 /* ConnectViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConnectViewController.h; sourceTree = ""; }; + 4CF8F4CE15E96AB8002E9A61 /* ConnectViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConnectViewController.m; sourceTree = ""; }; + 4CF8F4D115E96AB9002E9A61 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ConnectViewController.xib; sourceTree = ""; }; + 4CF8F4D815E96C0A002E9A61 /* libboost.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libboost.a; path = "../../../../libs/boost_1_47_0/build-ios/ios-device/libboost.a"; sourceTree = ""; }; + 4CF8F4DB15E96C4F002E9A61 /* ClientSocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClientSocket.cpp; path = ../../../common/ClientSocket.cpp; sourceTree = ""; }; + 4CF8F4DC15E96C4F002E9A61 /* ClientSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClientSocket.h; path = ../../../common/ClientSocket.h; sourceTree = ""; }; + 4CF8F4DD15E96C4F002E9A61 /* MessageSender.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MessageSender.cpp; path = ../../../common/MessageSender.cpp; sourceTree = ""; }; + 4CF8F4DE15E96C4F002E9A61 /* MessageSender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MessageSender.h; path = ../../../common/MessageSender.h; sourceTree = ""; }; + 4CF8F4DF15E96C4F002E9A61 /* misc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = misc.cpp; path = ../../../common/misc.cpp; sourceTree = ""; }; + 4CF8F4E015E96C4F002E9A61 /* misc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = misc.h; path = ../../../common/misc.h; sourceTree = ""; }; + 4CF8F4E115E96C4F002E9A61 /* UserInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UserInfo.cpp; path = ../../../common/UserInfo.cpp; sourceTree = ""; }; + 4CF8F4E215E96C4F002E9A61 /* UserInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserInfo.h; path = ../../../common/UserInfo.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4CF8F4B415E96AB8002E9A61 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4C7732CE15ED663F003C49DB /* CoreLocation.framework in Frameworks */, + 4CF8F4D915E96C0A002E9A61 /* libboost.a in Frameworks */, + 4CF8F4BC15E96AB8002E9A61 /* UIKit.framework in Frameworks */, + 4CF8F4BE15E96AB8002E9A61 /* Foundation.framework in Frameworks */, + 4CF8F4C015E96AB8002E9A61 /* CoreGraphics.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4C02E9F515EA19040051A095 /* assets */ = { + isa = PBXGroup; + children = ( + 4C7BE99215F39E0D00E87726 /* button_alarm.png */, + 4C7BE99315F39E0D00E87726 /* button.png */, + 4C7BE98C15F3954200E87726 /* messages_text.png */, + 4C7BE98A15F391E100E87726 /* alarm_text.png */, + 4C02E9F315EA18FB0051A095 /* script.html */, + ); + name = assets; + sourceTree = ""; + }; + 4C7D07BE15F54AB6001DCB2A /* Icons */ = { + isa = PBXGroup; + children = ( + 4C7D07BF15F54AB6001DCB2A /* Icon@2x.png */, + 4C7D07C015F54AB6001DCB2A /* Icon-72@2x.png */, + 4C7D07C115F54AB6001DCB2A /* Icon.png */, + 4C7D07C215F54AB6001DCB2A /* Icon-72.png */, + 4C7D07C315F54AB6001DCB2A /* iTunesArtwork */, + ); + name = Icons; + path = "k-observer-iphone/icons"; + sourceTree = ""; + }; + 4C8298F615F9307900E85091 /* SendMessage */ = { + isa = PBXGroup; + children = ( + 4CA1EE4F15F005A400469619 /* SendMessageViewController.h */, + 4CA1EE5015F005A400469619 /* SendMessageViewController.m */, + 4CA1EE5115F005A400469619 /* SendMessageViewController.xib */, + ); + name = SendMessage; + sourceTree = ""; + }; + 4C8298F715F9309200E85091 /* Alarm */ = { + isa = PBXGroup; + children = ( + 4C02E9F615EA1E3B0051A095 /* AlarmViewController.h */, + 4C02E9F715EA1E3B0051A095 /* AlarmViewController.m */, + 4C02E9F815EA1E3B0051A095 /* AlarmViewController.xib */, + ); + name = Alarm; + sourceTree = ""; + }; + 4C8298F815F930A800E85091 /* Map */ = { + isa = PBXGroup; + children = ( + 4C02E9F915EA1E3C0051A095 /* MapViewController.h */, + 4C02E9FA15EA1E3C0051A095 /* MapViewController.mm */, + 4C02E9FB15EA1E3C0051A095 /* MapViewController.xib */, + ); + name = Map; + sourceTree = ""; + }; + 4C8298F915F930B700E85091 /* Classes */ = { + isa = PBXGroup; + children = ( + 4CF8F4CA15E96AB8002E9A61 /* AppDelegate.h */, + 4CF8F4CB15E96AB8002E9A61 /* AppDelegate.m */, + 4C79C35A15EBEBC300FE6C7B /* NavigationControllerDelegate.h */, + 4C79C35B15EBEBC300FE6C7B /* NavigationControllerDelegate.m */, + 4C79C35E15EC008E00FE6C7B /* ObserverClient.h */, + 4C79C35F15EC008E00FE6C7B /* ObserverClient.mm */, + 4C8298FD15F930E400E85091 /* Messages */, + 4C8298FC15F930DB00E85091 /* Profile */, + 4C8298FB15F930D100E85091 /* MainMenu */, + 4C8298FA15F930C400E85091 /* Connect */, + 4C8298F815F930A800E85091 /* Map */, + 4C8298F715F9309200E85091 /* Alarm */, + 4C8298F615F9307900E85091 /* SendMessage */, + ); + name = Classes; + sourceTree = ""; + }; + 4C8298FA15F930C400E85091 /* Connect */ = { + isa = PBXGroup; + children = ( + 4CF8F4CD15E96AB8002E9A61 /* ConnectViewController.h */, + 4CF8F4CE15E96AB8002E9A61 /* ConnectViewController.m */, + 4CF8F4D015E96AB9002E9A61 /* ConnectViewController.xib */, + ); + name = Connect; + sourceTree = ""; + }; + 4C8298FB15F930D100E85091 /* MainMenu */ = { + isa = PBXGroup; + children = ( + 4C02E9D615E9F4AA0051A095 /* MainMenuViewController.h */, + 4C02E9D715E9F4AA0051A095 /* MainMenuViewController.m */, + 4C02E9D815E9F4AA0051A095 /* MainMenuViewController.xib */, + ); + name = MainMenu; + sourceTree = ""; + }; + 4C8298FC15F930DB00E85091 /* Profile */ = { + isa = PBXGroup; + children = ( + 4C02E9E315E9FCF70051A095 /* ProfileViewController.h */, + 4C02E9E415E9FCF70051A095 /* ProfileViewController.m */, + 4C02E9E515E9FCF70051A095 /* ProfileViewController.xib */, + ); + name = Profile; + sourceTree = ""; + }; + 4C8298FD15F930E400E85091 /* Messages */ = { + isa = PBXGroup; + children = ( + 4C02EA0015EA1E740051A095 /* MessagesViewController.h */, + 4C02EA0115EA1E740051A095 /* MessagesViewController.m */, + 4C02EA0215EA1E740051A095 /* MessagesViewController.xib */, + ); + name = Messages; + sourceTree = ""; + }; + 4CF8F4AC15E96AB7002E9A61 = { + isa = PBXGroup; + children = ( + 4C7D07BE15F54AB6001DCB2A /* Icons */, + 4C7732CD15ED663F003C49DB /* CoreLocation.framework */, + 4C02E9F515EA19040051A095 /* assets */, + 4CF8F4D815E96C0A002E9A61 /* libboost.a */, + 4CF8F4C115E96AB8002E9A61 /* k-observer-iphone */, + 4CF8F4BA15E96AB8002E9A61 /* Frameworks */, + 4CF8F4B815E96AB8002E9A61 /* Products */, + ); + sourceTree = ""; + }; + 4CF8F4B815E96AB8002E9A61 /* Products */ = { + isa = PBXGroup; + children = ( + 4CF8F4B715E96AB8002E9A61 /* k-observer-iphone.app */, + ); + name = Products; + sourceTree = ""; + }; + 4CF8F4BA15E96AB8002E9A61 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 4CF8F4BB15E96AB8002E9A61 /* UIKit.framework */, + 4CF8F4BD15E96AB8002E9A61 /* Foundation.framework */, + 4CF8F4BF15E96AB8002E9A61 /* CoreGraphics.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 4CF8F4C115E96AB8002E9A61 /* k-observer-iphone */ = { + isa = PBXGroup; + children = ( + 4C8298F915F930B700E85091 /* Classes */, + 4CF8F4C215E96AB8002E9A61 /* Supporting Files */, + 4CF8F4DA15E96C21002E9A61 /* common */, + 4C8298FE15F9312A00E85091 /* ObserverClientCpp.h */, + 4C82990015F9315500E85091 /* ObserverClientCpp.cpp */, + ); + path = "k-observer-iphone"; + sourceTree = ""; + }; + 4CF8F4C215E96AB8002E9A61 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 4C7D07CA15F55E8F001DCB2A /* Splash-portrait.png */, + 4CF8F4C315E96AB8002E9A61 /* k-observer-iphone-Info.plist */, + 4CF8F4C415E96AB8002E9A61 /* InfoPlist.strings */, + 4CF8F4C715E96AB8002E9A61 /* main.m */, + 4CF8F4C915E96AB8002E9A61 /* k-observer-iphone-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 4CF8F4DA15E96C21002E9A61 /* common */ = { + isa = PBXGroup; + children = ( + 4CF8F4DB15E96C4F002E9A61 /* ClientSocket.cpp */, + 4CF8F4DC15E96C4F002E9A61 /* ClientSocket.h */, + 4CF8F4DD15E96C4F002E9A61 /* MessageSender.cpp */, + 4CF8F4DE15E96C4F002E9A61 /* MessageSender.h */, + 4CF8F4DF15E96C4F002E9A61 /* misc.cpp */, + 4CF8F4E015E96C4F002E9A61 /* misc.h */, + 4CF8F4E115E96C4F002E9A61 /* UserInfo.cpp */, + 4CF8F4E215E96C4F002E9A61 /* UserInfo.h */, + ); + name = common; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4CF8F4B615E96AB8002E9A61 /* k-observer-iphone */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4CF8F4D515E96AB9002E9A61 /* Build configuration list for PBXNativeTarget "k-observer-iphone" */; + buildPhases = ( + 4CF8F4B315E96AB8002E9A61 /* Sources */, + 4CF8F4B415E96AB8002E9A61 /* Frameworks */, + 4CF8F4B515E96AB8002E9A61 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "k-observer-iphone"; + productName = "k-observer-iphone"; + productReference = 4CF8F4B715E96AB8002E9A61 /* k-observer-iphone.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4CF8F4AE15E96AB7002E9A61 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0430; + }; + buildConfigurationList = 4CF8F4B115E96AB7002E9A61 /* Build configuration list for PBXProject "k-observer-iphone" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 4CF8F4AC15E96AB7002E9A61; + productRefGroup = 4CF8F4B815E96AB8002E9A61 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4CF8F4B615E96AB8002E9A61 /* k-observer-iphone */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4CF8F4B515E96AB8002E9A61 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4CF8F4C615E96AB8002E9A61 /* InfoPlist.strings in Resources */, + 4CF8F4D215E96AB9002E9A61 /* ConnectViewController.xib in Resources */, + 4C02E9DA15E9F4AA0051A095 /* MainMenuViewController.xib in Resources */, + 4C02E9E715E9FCF70051A095 /* ProfileViewController.xib in Resources */, + 4C02E9F415EA18FB0051A095 /* script.html in Resources */, + 4C02E9FD15EA1E3C0051A095 /* AlarmViewController.xib in Resources */, + 4C02E9FF15EA1E3C0051A095 /* MapViewController.xib in Resources */, + 4C02EA0415EA1E740051A095 /* MessagesViewController.xib in Resources */, + 4CA1EE5315F005A400469619 /* SendMessageViewController.xib in Resources */, + 4C7BE98B15F391E100E87726 /* alarm_text.png in Resources */, + 4C7BE98D15F3954200E87726 /* messages_text.png in Resources */, + 4C7BE99415F39E0D00E87726 /* button_alarm.png in Resources */, + 4C7BE99515F39E0D00E87726 /* button.png in Resources */, + 4C7D07C415F54AB6001DCB2A /* Icon@2x.png in Resources */, + 4C7D07C515F54AB6001DCB2A /* Icon-72@2x.png in Resources */, + 4C7D07C615F54AB6001DCB2A /* Icon.png in Resources */, + 4C7D07C715F54AB6001DCB2A /* Icon-72.png in Resources */, + 4C7D07C815F54AB6001DCB2A /* iTunesArtwork in Resources */, + 4C7D07CB15F55E8F001DCB2A /* Splash-portrait.png in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4CF8F4B315E96AB8002E9A61 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4CF8F4C815E96AB8002E9A61 /* main.m in Sources */, + 4CF8F4CC15E96AB8002E9A61 /* AppDelegate.m in Sources */, + 4CF8F4CF15E96AB8002E9A61 /* ConnectViewController.m in Sources */, + 4CF8F4E315E96C4F002E9A61 /* ClientSocket.cpp in Sources */, + 4CF8F4E415E96C4F002E9A61 /* MessageSender.cpp in Sources */, + 4CF8F4E515E96C4F002E9A61 /* misc.cpp in Sources */, + 4CF8F4E615E96C4F002E9A61 /* UserInfo.cpp in Sources */, + 4C02E9D915E9F4AA0051A095 /* MainMenuViewController.m in Sources */, + 4C02E9E615E9FCF70051A095 /* ProfileViewController.m in Sources */, + 4C02E9FC15EA1E3C0051A095 /* AlarmViewController.m in Sources */, + 4C02E9FE15EA1E3C0051A095 /* MapViewController.mm in Sources */, + 4C02EA0315EA1E740051A095 /* MessagesViewController.m in Sources */, + 4C79C35C15EBEBC300FE6C7B /* NavigationControllerDelegate.m in Sources */, + 4C79C36015EC008F00FE6C7B /* ObserverClient.mm in Sources */, + 4CA1EE5215F005A400469619 /* SendMessageViewController.m in Sources */, + 4C82990115F9315500E85091 /* ObserverClientCpp.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 4CF8F4C415E96AB8002E9A61 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 4CF8F4C515E96AB8002E9A61 /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 4CF8F4D015E96AB9002E9A61 /* ConnectViewController.xib */ = { + isa = PBXVariantGroup; + children = ( + 4CF8F4D115E96AB9002E9A61 /* en */, + ); + name = ConnectViewController.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 4CF8F4D315E96AB9002E9A61 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 4CF8F4D415E96AB9002E9A61 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4CF8F4D615E96AB9002E9A61 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "k-observer-iphone/k-observer-iphone-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1"; + GCC_VERSION = ""; + HEADER_SEARCH_PATHS = "$(LibsPath)/boost_1_47_0"; + INFOPLIST_FILE = "k-observer-iphone/k-observer-iphone-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 4.3; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = "$(LibsPath)/boost_1_47_0/build-ios/ios-device"; + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(LibsPath)/boost_1_47_0/build-ios/ios-simulator"; + OTHER_CFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = 1; + USER_HEADER_SEARCH_PATHS = ""; + VALID_ARCHS = armv7; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + 4CF8F4D715E96AB9002E9A61 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "k-observer-iphone/k-observer-iphone-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ""; + GCC_VERSION = ""; + HEADER_SEARCH_PATHS = "$(LibsPath)/boost_1_47_0"; + INFOPLIST_FILE = "k-observer-iphone/k-observer-iphone-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 4.3; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = "$(LibsPath)/boost_1_47_0/build-ios/ios-device"; + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(LibsPath)/boost_1_47_0/build-ios/ios-simulator"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = 1; + USER_HEADER_SEARCH_PATHS = ""; + VALID_ARCHS = armv7; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4CF8F4B115E96AB7002E9A61 /* Build configuration list for PBXProject "k-observer-iphone" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4CF8F4D315E96AB9002E9A61 /* Debug */, + 4CF8F4D415E96AB9002E9A61 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4CF8F4D515E96AB9002E9A61 /* Build configuration list for PBXNativeTarget "k-observer-iphone" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4CF8F4D615E96AB9002E9A61 /* Debug */, + 4CF8F4D715E96AB9002E9A61 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 4CF8F4AE15E96AB7002E9A61 /* Project object */; +} diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.h new file mode 100644 index 0000000..b4cd3d0 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.h @@ -0,0 +1,23 @@ +// +// AlarmViewController.h +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface AlarmViewController : UIViewController + +- (void)textViewDidBeginEditing:(UITextView *)textView; + +- (void)finishEditingMessage; +- (IBAction)OnRejectPressed; +- (IBAction)OnThrowPressed; +- (IBAction)OnCarouselPressed; +- (IBAction)OnAssaultPressed; +- (IBAction)OnOtherPressed; +- (IBAction)OnSendAdditionalMessage; + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.m new file mode 100644 index 0000000..fb7d88f --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.m @@ -0,0 +1,132 @@ +// +// AlarmViewController.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "AlarmViewController.h" +#import "AppDelegate.h" +#import "ProfileViewController.h" + +AppDelegate* appDelegate; + +@interface AlarmViewController () + +@end + +@implementation AlarmViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) + { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. + + UIScrollView *tempScrollView=(UIScrollView *)self.view; + + tempScrollView.contentSize=CGSizeMake(320, 700); + +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +-(void)viewDidAppear:(BOOL)animated +{ + if ([appDelegate.observerClient GetMapState] >= 1) + { + [appDelegate.profileViewController SwitchAlarmSelector:YES]; + } + + if ([appDelegate.observerClient GetMapState] == 1) + { + [appDelegate.observerClient SetMapState:2]; + [appDelegate.observerClient SendMessage:@"ТРЕВОГА (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)"]; + } + +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +- (void)finishEditingMessage +{ + [self.view endEditing:YES]; + self.navigationItem.rightBarButtonItem = nil; +} + +- (IBAction)OnRejectPressed +{ + [appDelegate.observerClient SetMapState:3]; + [appDelegate.observerClient SendMessage:@"ТРЕВОГА: УДАЛЕНИЕ С УИК (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)"]; + [appDelegate.profileViewController SwitchAlarmSelector:YES]; +} + +- (IBAction)OnThrowPressed +{ + [appDelegate.observerClient SetMapState:4]; + [appDelegate.profileViewController SwitchAlarmSelector:YES]; + [appDelegate.observerClient SendMessage:@"ТРЕВОГА: ВБРОС (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)"]; +} + +- (IBAction)OnCarouselPressed +{ + [appDelegate.observerClient SetMapState:5]; + [appDelegate.profileViewController SwitchAlarmSelector:YES]; + [appDelegate.observerClient SendMessage:@"ТРЕВОГА: КАРУСЕЛЬ (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)"]; +} + +- (IBAction)OnAssaultPressed +{ + [appDelegate.observerClient SetMapState:6]; + [appDelegate.profileViewController SwitchAlarmSelector:YES]; + [appDelegate.observerClient SendMessage:@"ТРЕВОГА: НАПАДЕНИЕ (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)"]; +} + +- (IBAction)OnOtherPressed +{ + [appDelegate.observerClient SetMapState:2]; + [appDelegate.profileViewController SwitchAlarmSelector:YES]; + [appDelegate.observerClient SendMessage:@"ТРЕВОГА: ДРУГОЕ (АВТОМАТИЧЕСКОЕ СООБЩЕНИЕ)"]; +} + +- (IBAction)OnSendAdditionalMessage +{ + UITextView* textView = (UITextView*)[self.view viewWithTag:2]; + + NSString* msg = textView.text; + + if (![msg isEqualToString:@""]) + { + + [textView setText:@""]; + [appDelegate.observerClient SendMessage:msg]; + } +} + +- (void)textViewDidBeginEditing:(UITextView *)textView +{ + UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Готово" style:UIBarButtonItemStylePlain target:self action:@selector(finishEditingMessage)]; + + self.navigationItem.rightBarButtonItem = anotherButton; +} + + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.xib b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.xib new file mode 100644 index 0000000..be4631b --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AlarmViewController.xib @@ -0,0 +1,572 @@ + + + + 1296 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1181 + + + IBUITextView + IBUIButton + IBUIImageView + IBUIView + IBUILabel + IBProxyObject + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 292 + {{40, 67}, {240, 36}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Удаление с участка + + 3 + MQA + + + 1 + MC4zMTUyMTczOTEzIDAuMDA3NDMwODQ2NTgyIDAAA + + + 3 + MC41AA + + + NSImage + button_alarm.png + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + + + + 292 + {{40, 131}, {240, 36}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Вброс + + + 1 + MC4zMTUyMTczOTEzIDAuMDA3NDMwODQ2NTgyIDAAA + + + + + + + + + 292 + {{26, 1}, {268, 58}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Включен режим тревоги. Что случилось? + + 1 + MCAwIDAAA + + + 0 + 10 + 2 + + 1 + 17 + + + Helvetica + 17 + 16 + + + + + 292 + {{40, 197}, {240, 36}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Карусель + + + 1 + MC4zMTUyMTczOTEzIDAuMDA3NDMwODQ2NTgyIDAAA + + + + + + + + + 292 + {{40, 267}, {240, 36}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Нападение + + + 1 + MC4zMTUyMTczOTEzIDAuMDA3NDMwODQ2NTgyIDAAA + + + + + + + + + 292 + {{40, 334}, {240, 36}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Другое + + + 1 + MC4zMTUyMTczOTEzIDAuMDA3NDMwODQ2NTgyIDAAA + + + + + + + + + 292 + {{43, 402}, {234, 21}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Дополнительное сообщение: + + + 0 + 10 + + + + + + 292 + {{20, 431}, {280, 80}} + + + + _NS:9 + NO + IBCocoaTouchFramework + + NSImage + alarm_text.png + + + + + 292 + {{20, 431}, {280, 80}} + + + + _NS:9 + + 1 + MC45MjM5MTMwNDM1IDAuOTIzOTEzMDQzNSAwLjkyMzkxMzA0MzUgMAA + + YES + YES + 2 + IBCocoaTouchFramework + + + 2 + 1 + 9 + IBCocoaTouchFramework + + + 1 + 14 + + + Helvetica + 14 + 16 + + + + + 292 + {{40, 519}, {240, 36}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Отправить + + + 1 + MC4zMTUyMTczOTEzIDAuMDA3NDMwODQ2NTgyIDAAA + + + + + + + + {{0, 20}, {320, 582}} + + + + + 1 + MSAwLjkwMzYyNDMzNTUgMC44NTU0OTc1MzIAA + + + + IBUISimulatedFreeformSizeMetricsSentinel + Freeform + + IBCocoaTouchFramework + + + + + + + view + + + + 3 + + + + delegate + + + + 18 + + + + OnRejectPressed + + + 7 + + 21 + + + + OnThrowPressed + + + 7 + + 22 + + + + OnCarouselPressed + + + 7 + + 23 + + + + OnAssaultPressed + + + 7 + + 24 + + + + OnOtherPressed + + + 7 + + 25 + + + + delegate + + + + 20 + + + + OnSendAdditionalMessage + + + 7 + + 26 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 1 + + + + + + + + + + + + + + + + + 13 + + + + + 12 + + + + + 11 + + + + + 9 + + + + + 8 + + + + + 7 + + + + + 5 + + + + + 6 + + + + + 4 + + + + + 27 + + + + + + + AlarmViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIScrollView + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 27 + + + + + AlarmViewController + UIViewController + + id + id + id + id + id + id + + + + OnAssaultPressed + id + + + OnCarouselPressed + id + + + OnOtherPressed + id + + + OnRejectPressed + id + + + OnSendAdditionalMessage + id + + + OnThrowPressed + id + + + + IBProjectSource + ./Classes/AlarmViewController.h + + + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + + {280, 80} + {240, 36} + + 1181 + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/AppDelegate.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AppDelegate.h new file mode 100644 index 0000000..1a8c931 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AppDelegate.h @@ -0,0 +1,61 @@ +// +// AppDelegate.h +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import +#import + + +#import "NavigationControllerDelegate.h" +#import "ObserverClient.h" + +@class ConnectViewController; +@class MainMenuViewController; +@class ProfileViewController; +@class AlarmViewController; +@class MapViewController; +@class MessagesViewController; +@class SendMessageViewController; + +@interface AppDelegate : UIResponder +{ +} + +@property (strong, nonatomic) UIWindow *window; + +@property (strong, nonatomic) UINavigationController *navController; + +@property (strong, nonatomic) ConnectViewController *connectViewController; + +@property (strong, nonatomic) MainMenuViewController *mainMenuViewController; + +@property (strong, nonatomic) ProfileViewController *profileViewController; + +@property (strong, nonatomic) AlarmViewController *alarmViewController; + +@property (strong, nonatomic) MapViewController *mapViewController; + +@property (strong, nonatomic) MessagesViewController *messagesViewController; + +@property (strong, nonatomic) SendMessageViewController *sendMessageViewController; + +@property (strong, nonatomic) NavigationControllerDelegate *navigationControllerDelegate; + +@property (strong, nonatomic) ObserverClient* observerClient; + +@property (strong, nonatomic) CLLocationManager *locationManager; + +@property (strong, nonatomic) UIActivityIndicatorView* spinner; + +-(void)gotoMainMenu; +-(void)gotoMainMenuImmediate; + +- (void)locationManager:(CLLocationManager *)manager + didUpdateToLocation:(CLLocation *)newLocation + fromLocation:(CLLocation *)oldLocation; + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/AppDelegate.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AppDelegate.m new file mode 100644 index 0000000..696521a --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/AppDelegate.m @@ -0,0 +1,166 @@ +// +// AppDelegate.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "AppDelegate.h" + +#import "ConnectViewController.h" +#import "MainMenuViewController.h" +#import "ProfileViewController.h" +#import "AlarmViewController.h" +#import "MapViewController.h" +#import "MessagesViewController.h" +#import "SendMessageViewController.h" + +AppDelegate* appDelegate; + +@implementation AppDelegate + +@synthesize window = _window; +@synthesize navController = _navController; +@synthesize connectViewController = _connectViewController; +@synthesize mainMenuViewController = _mainMenuViewController; +@synthesize profileViewController = _profileViewController; +@synthesize alarmViewController = _alarmViewController; +@synthesize mapViewController = _mapViewController; +@synthesize messagesViewController = _messagesViewController; +@synthesize sendMessageViewController = _sendMessageViewController; + +@synthesize navigationControllerDelegate = _navigationControllerDelegate; + +@synthesize spinner = _spinner; + +@synthesize observerClient = _observerClient; +@synthesize locationManager = _locationManager; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + // Override point for customization after application launch. + + + self.connectViewController = [[ConnectViewController alloc] initWithNibName:@"ConnectViewController" bundle:nil]; + + self.connectViewController.title = @"Вход"; + + self.mainMenuViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil]; + + self.mainMenuViewController.title = @"Главное меню"; + + self.profileViewController = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil]; + + self.profileViewController.title = @"Профиль"; + + self.profileViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + + self.alarmViewController = [[AlarmViewController alloc] initWithNibName:@"AlarmViewController" bundle:nil]; + + self.alarmViewController.title = @"Тревога"; + + self.alarmViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + + self.mapViewController = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil]; + + self.mapViewController.title = @"Карта"; + + + self.messagesViewController = [[MessagesViewController alloc] initWithNibName:@"MessagesViewController" bundle:nil]; + + self.messagesViewController.title = @"Сообщения"; + + self.sendMessageViewController = [[SendMessageViewController alloc] initWithNibName:@"SendMessageViewController" bundle:nil]; + + self.navigationControllerDelegate = [[NavigationControllerDelegate alloc] init]; + + self.navController = [[UINavigationController alloc] initWithRootViewController:self.connectViewController]; + + self.navController.delegate = self.navigationControllerDelegate; + + self.window.rootViewController = self.navController; + [self.window makeKeyAndVisible]; + + self.observerClient = [[ObserverClient alloc] init]; + + self.locationManager = [[CLLocationManager alloc] init]; + self.locationManager.delegate = self; + self.locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move + self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; + [self.locationManager startUpdatingLocation]; + + //Force lazy load + //[self.mapViewController view]; //NO + [self.alarmViewController view]; + [self.profileViewController view]; + [self.sendMessageViewController view]; + [self.messagesViewController view]; + + appDelegate = self; + + CGPoint p = self.connectViewController.view.center; + + self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; + [self.spinner setCenter:p]; // I do this because I'm in landscape mode + [self.connectViewController.view addSubview:self.spinner]; // spinner is not visible until started + + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +-(void)gotoMainMenu +{ + @autoreleasepool + { + [self performSelectorOnMainThread:@selector(gotoMainMenuImmediate) withObject:nil waitUntilDone:NO]; + } +} + +-(void)gotoMainMenuImmediate +{ + @autoreleasepool + { + [self.spinner stopAnimating]; + [self.navController pushViewController:self.mainMenuViewController animated:YES]; + } +} + +- (void)locationManager:(CLLocationManager *)manager + didUpdateToLocation:(CLLocation *)newLocation + fromLocation:(CLLocation *)oldLocation +{ + float lon = newLocation.coordinate.longitude; + float lat = newLocation.coordinate.latitude; + + [appDelegate.observerClient UpdateLon:lon Lat:lat]; +} + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ConnectViewController.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ConnectViewController.h new file mode 100644 index 0000000..8ae1302 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ConnectViewController.h @@ -0,0 +1,26 @@ +// +// ViewController.h +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface ConnectViewController : UIViewController + +- (IBAction)OnConnectPressed; + +- (BOOL)textFieldShouldReturn:(UITextField *)textField; + +-(void)UnlockConnectButton; + +-(void)OnConnectionClosed; + +-(void)OnConnectionClosedImmediate; + +-(void)OnReceiveQuit; + +-(void)OnReceiveQuitImmediate; +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ConnectViewController.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ConnectViewController.m new file mode 100644 index 0000000..6d0ab39 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ConnectViewController.m @@ -0,0 +1,109 @@ +// +// ViewController.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "ConnectViewController.h" +#import "MainMenuViewController.h" +#import "AppDelegate.h" + +extern AppDelegate* appDelegate; + +@interface ConnectViewController () + +@end + +@implementation ConnectViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + + +- (IBAction)OnConnectPressed +{ + [appDelegate.spinner startAnimating]; + + UITextField* address_tf = (UITextField*)[self.view viewWithTag:1]; + + UITextField* port_tf = (UITextField*)[self.view viewWithTag:2]; + + UIButton* btn_connect = (UIButton*)[self.view viewWithTag:3]; + + [appDelegate.observerClient ConnectTo:address_tf.text onPort:port_tf.text]; + + [btn_connect setUserInteractionEnabled:NO]; + +} + + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + [self.view endEditing:YES]; + return YES; +} + +-(void)UnlockConnectButton +{ + UIButton* btn_connect = (UIButton*)[self.view viewWithTag:3]; + [btn_connect setUserInteractionEnabled:YES]; + +} + +-(void)OnConnectionClosed +{ + [self performSelectorOnMainThread:@selector(OnConnectionClosedImmediate) withObject:nil waitUntilDone:NO]; +} + +-(void)OnReceiveQuit +{ + [self performSelectorOnMainThread:@selector(OnReceiveQuitImmediate) withObject:nil waitUntilDone:NO]; +} + + +-(void)OnReceiveQuitImmediate +{ + @autoreleasepool { + + + UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Сервер недоступен" + message:@"Сервер недоступен" + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil]; + [message show]; + + [appDelegate.spinner stopAnimating]; + [appDelegate.connectViewController UnlockConnectButton]; + [appDelegate.navController popToRootViewControllerAnimated:YES]; + + } +} + +-(void)OnConnectionClosedImmediate +{ + + [appDelegate.spinner stopAnimating]; + [appDelegate.connectViewController UnlockConnectButton]; +} + + + + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.h new file mode 100644 index 0000000..0501f84 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.h @@ -0,0 +1,19 @@ +// +// MainMenuViewController.h +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface MainMenuViewController : UIViewController +- (IBAction)OnMapButtonPressed; +- (IBAction)OnProfileButtonPressed; +- (IBAction)OnAlarmButtonPressed; +- (IBAction)OnMessagesButtonPressed; + +-(void)viewDidAppear:(BOOL)animated; + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.m new file mode 100644 index 0000000..974f3df --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.m @@ -0,0 +1,78 @@ +// +// MainMenuViewController.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "MainMenuViewController.h" +#import "ProfileViewController.h" +#import "AlarmViewController.h" +#import "MapViewController.h" +#import "MessagesViewController.h" +#import "AppDelegate.h" + +extern AppDelegate* appDelegate; + +@interface MainMenuViewController () + +@end + +@implementation MainMenuViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +-(void)viewDidAppear:(BOOL)animated +{ +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +- (IBAction)OnMapButtonPressed +{ + //[self.view addSubview:appDelegate.mapViewController.view]; + [appDelegate.navController pushViewController:appDelegate.mapViewController animated:YES]; +} + +- (IBAction)OnProfileButtonPressed +{ + //[self.view addSubview:appDelegate.profileViewController.view]; + [appDelegate.navController pushViewController:appDelegate.profileViewController animated:YES]; +} + +- (IBAction)OnAlarmButtonPressed +{ + //[self.view addSubview:appDelegate.alarmViewController.view]; + [appDelegate.navController pushViewController:appDelegate.alarmViewController animated:YES]; +} + +- (IBAction)OnMessagesButtonPressed +{ + //[self.view addSubview:appDelegate.messagesViewController.view]; + [appDelegate.navController pushViewController:appDelegate.messagesViewController animated:YES]; +} +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.xib b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.xib new file mode 100644 index 0000000..acf2984 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MainMenuViewController.xib @@ -0,0 +1,329 @@ + + + + 1296 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1181 + + + IBUIButton + IBUIView + IBUILabel + IBProxyObject + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 292 + {{40, 75}, {240, 36}} + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Открыть карту + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + NSImage + button.png + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + + + + 292 + {{40, 141}, {240, 36}} + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Изменить профиль + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + + + + + + + 292 + {{40, 207}, {240, 36}} + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Подать сигнал тревоги + + + 1 + MC4zMTUyMTczOTEzIDAuMDA3NDMwODQ2NTgyIDAAA + + + + NSImage + button_alarm.png + + + + + + + 292 + {{40, 273}, {240, 36}} + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Посмотреть сообщения + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + + + + + + + 292 + {{40, 28}, {245, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Панель управления К-Выборы + + 1 + MCAwIDAAA + + + 0 + 10 + + 1 + 17 + + + Helvetica + 17 + 16 + + + + {{0, 20}, {320, 460}} + + + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + + IBCocoaTouchFramework + + + + + + + view + + + + 3 + + + + OnMapButtonPressed + + + 7 + + 10 + + + + OnProfileButtonPressed + + + 7 + + 8 + + + + OnAlarmButtonPressed + + + 7 + + 9 + + + + OnMessagesButtonPressed + + + 7 + + 11 + + + + + + 0 + + + + + + 1 + + + + + + + + + + + + -1 + + + File's Owner + + + -2 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 12 + + + + + + + MainMenuViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 12 + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + + {480, 72} + {480, 72} + + 1181 + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.h new file mode 100644 index 0000000..867aad8 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.h @@ -0,0 +1,30 @@ +// +// MapViewController.h +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import +//#import + +@interface MapViewController : UIViewController + + +@property (nonatomic, retain) NSTimer *MapRefreshTimer; + +@property (strong, nonatomic) UIActivityIndicatorView* spinner; + +- (void)viewDidAppear:(BOOL)animated; +- (void)viewDidDisappear:(BOOL)animated; + +-(void)refreshMap; + +- (void) onAlarmSelectorChanged; +- (void)webViewDidFinishLoad:(UIWebView *)webView; + +@end + + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.mm b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.mm new file mode 100644 index 0000000..db5ce02 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.mm @@ -0,0 +1,234 @@ +// +// MapViewController.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "MapViewController.h" +#import "AppDelegate.h" + +#include "ObserverClientCpp.h" + +//extern boost::mutex UpdatingMapMutex; + +//extern std::vector UserInfoArr; +//extern std::vector AlarmUserInfoArr; +/* +void SwitchMapToAlarm(); +void SwitchMapToCommon(); + +bool IsAlarmMap();*/ + +extern TObserverClient ObserverClientClass; + +extern AppDelegate* appDelegate; + +@interface MapViewController () + +@end + +@implementation MapViewController + +@synthesize MapRefreshTimer = _MapRefreshTimer; +@synthesize spinner = _spinner; + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. + + UISegmentedControl* segmentedControl = (UISegmentedControl*)[self.view viewWithTag:3]; + [segmentedControl addTarget:self action:@selector(onAlarmSelectorChanged) forControlEvents:UIControlEventValueChanged]; + + UIWebView* webView = (UIWebView*)[self.view viewWithTag:2]; + + + NSString* filePath = [[NSBundle mainBundle] pathForResource:@"script" ofType:@"html"]; + + NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; + + NSString* lon_str = [NSString stringWithFormat:@"%f", [appDelegate.observerClient GetBaseLon]]; + NSString* lat_str = [NSString stringWithFormat:@"%f", [appDelegate.observerClient GetBaseLat]]; + NSString* zoom_str = [NSString stringWithFormat:@"%d", [appDelegate.observerClient GetBaseZoom]]; + + + htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<<>>" withString:lon_str]; + htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<<>>" withString:lat_str]; + htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<<>>" withString:zoom_str]; + + [webView loadHTMLString:htmlString baseURL:nil]; + + [webView setDelegate:self]; + + CGPoint p = webView.center; + + + self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; + + [self.spinner setCenter:p]; // I do this because I'm in landscape mode + [webView addSubview:self.spinner]; // spinner is not visible until started + + [self.spinner startAnimating]; + + +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +- (void)viewDidAppear:(BOOL)animated +{ + [appDelegate.observerClient StartMapHeartbeatTimer]; + + self.MapRefreshTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(refreshMap) userInfo:nil repeats:YES]; +} + + +- (void)viewDidDisappear:(BOOL)animated +{ + [appDelegate.observerClient StopMapHeartbeatTimer]; + + self.MapRefreshTimer = nil; + +} + +-(void)refreshMap +{ + ObserverClientClass.UpdatingMapMutex.lock(); + + UIWebView* webView = (UIWebView*)[self.view viewWithTag:2]; + + [webView stringByEvaluatingJavaScriptFromString:@"Clear();"]; + + + if ([appDelegate.observerClient IsAlarmMap]) + { + + for (std::vector::iterator i = ObserverClientClass.AlarmUserInfoArr.begin(); i != ObserverClientClass.AlarmUserInfoArr.end(); ++i) + { + NSString* posX = [NSString stringWithFormat:@"%f", i->PosX]; + NSString* posY = [NSString stringWithFormat:@"%f", i->PosY]; + NSString* mapState = [NSString stringWithFormat:@"%d", i->MapState]; + + + NSString* State; + + + if (i->MapState == 0) + { + State = @"Мобильная группа"; + } + else if (i->MapState == 1) + { + State = @"Наблюдатель"; + } + else if (i->MapState == 2) + { + State = @"Тревога"; + } + else if (i->MapState == 3) + { + State = @"Тревога - Удаление с УИК"; + } + else if (i->MapState == 4) + { + State = @"Тревога - Вброс"; + } + else if (i->MapState == 5) + { + State = @"Тревога - Карусель"; + } + else if (i->MapState == 6) + { + State = @"Тревога - Нападение"; + } + else + { + State = @"Тревога"; + } + + NSString* text = [NSString stringWithFormat:@"УИК № %d \\n %@ \\n %@ \\n %@ \\n %@ \\n Состояние: %@", + i->Uik, + [NSString stringWithCString:i->LastName.c_str() encoding:NSUTF8StringEncoding], + [NSString stringWithCString:i->FirstName.c_str() encoding:NSUTF8StringEncoding], + [NSString stringWithCString:i->MiddleName.c_str() encoding:NSUTF8StringEncoding], + [NSString stringWithCString:i->PhoneNumber.c_str() encoding:NSUTF8StringEncoding], + State]; + + if (i->PosX != 0.f && i->PosY != 0.f) + { + NSString* javaScriptCode = [NSString stringWithFormat:@"AddMarkerWithPopup(%@, %@, %@, \"%@\");", posX, posY, mapState, text]; + + [webView stringByEvaluatingJavaScriptFromString:javaScriptCode]; + } + } + + } + else + { + for (std::vector::iterator i = ObserverClientClass.UserInfoArr.begin(); i != ObserverClientClass.UserInfoArr.end(); ++i) + { + NSString* posX = [NSString stringWithFormat:@"%f", i->PosX]; + NSString* posY = [NSString stringWithFormat:@"%f", i->PosY]; + NSString* mapState = [NSString stringWithFormat:@"%d", i->MapState]; + + if (i->PosX != 0.f && i->PosY != 0.f) + { + NSString* javaScriptCode = [NSString stringWithFormat:@"AddMarker(%@, %@, %@);", posX, posY, mapState]; + + [webView stringByEvaluatingJavaScriptFromString:javaScriptCode]; + } + } + } + + + ObserverClientClass.UpdatingMapMutex.unlock(); +} + + +- (void) onAlarmSelectorChanged +{ + UISegmentedControl* segmentedControl = (UISegmentedControl*)[self.view viewWithTag:3]; + + UIWebView* webView = (UIWebView*)[self.view viewWithTag:2]; + + if (segmentedControl.selectedSegmentIndex == 0) + { + [appDelegate.observerClient SwitchMapToCommon]; + + [webView stringByEvaluatingJavaScriptFromString:@"DeactivateSelectControl();"]; + } + else + { + [appDelegate.observerClient SwitchMapToAlarm]; + [webView stringByEvaluatingJavaScriptFromString:@"ActivateSelectControl();"]; + } +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + [self.spinner stopAnimating]; +} + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.xib b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.xib new file mode 100644 index 0000000..ec571dc --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MapViewController.xib @@ -0,0 +1,176 @@ + + + + 1296 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1181 + + + IBUIWebView + IBUISegmentedControl + IBUIView + IBProxyObject + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 274 + {320, 460} + + + _NS:9 + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + 2 + IBCocoaTouchFramework + 1 + YES + + + + 292 + {{57, 360}, {207, 44}} + + _NS:9 + NO + 3 + IBCocoaTouchFramework + 2 + 0 + + Все + Тревога + + + + + + + + + + + {0, 0} + {0, 0} + + + + + + + + {{0, 20}, {320, 460}} + + + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + + IBCocoaTouchFramework + + + + + + + view + + + + 3 + + + + + + 0 + + + + + + 1 + + + + + + + + + -1 + + + File's Owner + + + -2 + + + + + 4 + + + + + 6 + + + + + + + MapViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 6 + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + 1181 + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.h new file mode 100644 index 0000000..aba1273 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.h @@ -0,0 +1,28 @@ +// +// MessagesViewController.h +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface MessagesViewController : UIViewController +{ + NSMutableArray* messageHeadersArray; + NSMutableArray* messageArray; + +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; + +-(void)addMessage:(NSString*)message withHeader:(NSString*)header; + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.m new file mode 100644 index 0000000..a73cbef --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.m @@ -0,0 +1,137 @@ +// +// MessagesViewController.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "MessagesViewController.h" +#import "AppDelegate.h" + +extern AppDelegate* appDelegate; + +@interface MessagesViewController () + +@end + +@implementation MessagesViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + messageHeadersArray = [[NSMutableArray alloc] init]; + messageArray = [[NSMutableArray alloc] init]; + + [messageHeadersArray addObject:@"Подключение установлено"]; + [messageArray addObject:@"Подключение к серверу успешно установлено"]; + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. + + NSArray* iparr = [NSArray arrayWithObjects:[NSIndexPath indexPathWithIndex:0], [NSIndexPath indexPathWithIndex:1], nil]; + + UITableView* tableView = (UITableView*)[self.view viewWithTag:4]; + + [tableView insertRowsAtIndexPaths:iparr withRowAnimation:UITableViewRowAnimationAutomatic]; +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +-(void)viewDidAppear:(BOOL)animated +{ + UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Отправить" style:UIBarButtonItemStylePlain target:self action:@selector(goToSendMessageView)]; + + + self.navigationItem.rightBarButtonItem = anotherButton; +} + +-(void)viewDidDisappear:(BOOL)animated +{ + + self.navigationItem.rightBarButtonItem = nil; +} + +-(void)goToSendMessageView +{ + + self.navigationItem.rightBarButtonItem = nil; + [appDelegate.navController pushViewController:(UIViewController*)appDelegate.sendMessageViewController animated:YES]; +} + + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [messageHeadersArray count]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *CellIdentifier = @"Cell"; + + //Поиск ячейки + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + + //Если ячейка не найдена + if (cell == nil) { + //Создание ячейки + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + } + + ; + + cell.textLabel.text = [messageHeadersArray objectAtIndex:messageHeadersArray.count-indexPath.row-1]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITextView* textView = (UITextView*)[[self.view viewWithTag:1] viewWithTag:2]; + + [textView setText:[messageArray objectAtIndex:messageHeadersArray.count-indexPath.row-1]]; + + +} + + +-(void)addMessage:(NSString*)message withHeader:(NSString*)header +{ + + UITableView* tableView = (UITableView*)[self.view viewWithTag:4]; + + [messageHeadersArray addObject:header]; + [messageArray addObject:message]; + + [tableView reloadData]; + + [tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; + + +} + + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.xib b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.xib new file mode 100644 index 0000000..4c2fd69 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/MessagesViewController.xib @@ -0,0 +1,300 @@ + + + + 1296 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1181 + + + IBProxyObject + IBUIImageView + IBUILabel + IBUITextView + IBUITableView + IBUIScrollView + IBUIView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 268 + + + + 292 + {320, 186} + + + + _NS:9 + NO + IBCocoaTouchFramework + + NSImage + messages_text.png + + + + + 274 + {320, 186} + + + + _NS:9 + YES + 2 + IBCocoaTouchFramework + NO + + + 2 + IBCocoaTouchFramework + + + 1 + 14 + + + Helvetica + 14 + 16 + + + + {{0, 84}, {320, 186}} + + + + _NS:9 + YES + YES + 1 + IBCocoaTouchFramework + + + + 274 + {{0, 229}, {320, 231}} + + + _NS:9 + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + YES + 4 + IBCocoaTouchFramework + YES + 1 + + 1 + MC43ODgwNDM0NzgzIDAuNzg4MDQzNDc4MyAwLjc4ODA0MzQ3ODMAA + + 0 + YES + 44 + 22 + 22 + + + + 292 + {{20, 12}, {190, 21}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Выбранное сообщение: + + 1 + MCAwIDAAA + + + 0 + 10 + + 1 + 17 + + + Helvetica + 17 + 16 + + + + {{0, 20}, {320, 460}} + + + + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + + IBCocoaTouchFramework + + + + + + + view + + + + 3 + + + + dataSource + + + + 12 + + + + delegate + + + + 11 + + + + + + 0 + + + + + + 1 + + + + + + + + + + -1 + + + File's Owner + + + -2 + + + + + 7 + + + + + + + + + 10 + + + + + 13 + + + + + 6 + + + + + 14 + + + + + + + MessagesViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 14 + + + + + MessagesViewController + UIViewController + + IBProjectSource + ./Classes/MessagesViewController.h + + + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + + messages_text.png + {640, 372} + + 1181 + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/NavigationControllerDelegate.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/NavigationControllerDelegate.h new file mode 100644 index 0000000..4491724 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/NavigationControllerDelegate.h @@ -0,0 +1,17 @@ +// +// NavigationControllerDelegate.h +// k-observer-iphone +// +// Created by vvv ооо on 27.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import +#import + +@interface NavigationControllerDelegate : NSObject + + +- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated; + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/NavigationControllerDelegate.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/NavigationControllerDelegate.m new file mode 100644 index 0000000..02db77d --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/NavigationControllerDelegate.m @@ -0,0 +1,58 @@ +// +// NavigationControllerDelegate.m +// k-observer-iphone +// +// Created by vvv ооо on 27.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "NavigationControllerDelegate.h" + +#import "AppDelegate.h" + +#import "ConnectViewController.h" +#import "MainMenuViewController.h" +#import "ProfileViewController.h" +#import "AlarmViewController.h" +#import "MapViewController.h" +#import "MessagesViewController.h" + +extern AppDelegate* appDelegate; + +@implementation NavigationControllerDelegate + +- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated +{ + if (viewController == appDelegate.connectViewController) + { + [appDelegate.observerClient Close]; + } + + if (viewController == appDelegate.mainMenuViewController) + { + + } + + if (viewController == appDelegate.profileViewController) + { + + } + + if (viewController == appDelegate.alarmViewController) + { + + } + + if (viewController == appDelegate.mapViewController) + { + + } + + if (viewController == appDelegate.messagesViewController) + { + } + +} + + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClient.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClient.h new file mode 100644 index 0000000..94f6aaa --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClient.h @@ -0,0 +1,59 @@ +// +// ObserverClient.h +// k-observer-iphone +// +// Created by vvv ооо on 27.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface ObserverClient : NSObject +{ + BOOL Active; + float CurrentLon; + float CurrentLat; +} + +-(void)ConnectTo:(NSString*)address onPort:(NSString*)port; + +-(void)StopTryingConnect; + +-(void)Close; + +-(void)UpdateProfileWithLastName:(NSString*)lastName + FirstName:(NSString*)firstName + MiddleName:(NSString*)middleName + PhoneNumber:(NSString*)phoneNumber + UikNumber:(int)uikNumber + Status:(int)status; + +-(void)SetMapState:(int)mode; + +-(int)GetMapState; + +-(void)UpdateLon:(float)lon Lat:(float)lat; + +-(void)PassLonLatToClient; + +-(void)StartHeartbeatTimer; + +-(void)StopHeartbeatTimer; + +-(void)StartMapHeartbeatTimer; + +-(void)StopMapHeartbeatTimer; + +-(void)SendMessage:(NSString*)msg; + +-(float)GetBaseLon; +-(float)GetBaseLat; +-(int)GetBaseZoom; + +-(void)SwitchMapToAlarm; +-(void)SwitchMapToCommon; +-(bool)IsAlarmMap; + +@end + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClient.mm b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClient.mm new file mode 100644 index 0000000..0564949 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClient.mm @@ -0,0 +1,261 @@ +// +// ObserverClient.m +// k-observer-iphone +// +// Created by vvv ооо on 27.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "ObserverClient.h" +#import "AppDelegate.h" +#import "MessagesViewController.h" +#import "ConnectViewController.h" +#include "ObserverClientCpp.h" + +extern AppDelegate* appDelegate; + +TObserverClient ObserverClientClass; + + +@implementation ObserverClient + +-(id)init +{ + self = [super init]; + + if (self) + { + Active = NO; + CurrentLon = 0.f; + CurrentLat = 0.f; + } + + return self; +} + +-(void)ConnectTo:(NSString*)address onPort:(NSString*)port +{ + if (!Active) + { + const char* c_address = [address UTF8String]; + const char* c_port = [port UTF8String]; + + ObserverClientClass.CreateClientSocket(c_address, c_port); + + } +} + +-(void)StopTryingConnect +{ + ObserverClientClass.DestroyClientSocket(); + + [appDelegate.spinner stopAnimating]; + + UIButton* btn_connect = (UIButton*)[appDelegate.connectViewController.view viewWithTag:3]; + + UIButton* btn_cancel = (UIButton*)[appDelegate.connectViewController.view viewWithTag:4]; + + [btn_connect setUserInteractionEnabled:YES]; + + [btn_cancel setUserInteractionEnabled:NO]; +} + +-(void)ConnectAutorizationFinished +{ + if (!Active) + { + [self StartHeartbeatTimer]; + + [self PassLonLatToClient]; + + Active = YES; + } +} + +-(void)Close +{ + if (Active) + { + [self StopHeartbeatTimer]; + ObserverClientClass.ClientSocket->BlockForceCloseMessage = true; + + ObserverClientClass.DestroyClientSocket(); + Active = NO; + } +} + + +-(void)UpdateProfileWithLastName:(NSString*)lastName + FirstName:(NSString*)firstName + MiddleName:(NSString*)middleName + PhoneNumber:(NSString*)phoneNumber + UikNumber:(int)uikNumber + Status:(int)status +{ + const char* c_lastName = [lastName UTF8String]; + const char* c_firstName = [firstName UTF8String]; + const char* c_middleName = [middleName UTF8String]; + const char* c_phoneNumber = [phoneNumber UTF8String]; + + ObserverClientClass.UpdateUserInfo(c_lastName, c_firstName, c_middleName, c_phoneNumber, uikNumber, status); + +} + +-(void)SetMapState:(int)mode +{ + ObserverClientClass.ClientSocket->UserInfo.MapState = mode; +} + +-(int)GetMapState +{ + return ObserverClientClass.ClientSocket->UserInfo.MapState; +} + +-(void)UpdateLon:(float)lon Lat:(float)lat +{ + CurrentLon = lon; + CurrentLat = lat; + + if (Active) + { + [self PassLonLatToClient]; + } +} + +-(void)PassLonLatToClient +{ + ObserverClientClass.ClientSocket->UserInfo.PosX = CurrentLon; + ObserverClientClass.ClientSocket->UserInfo.PosY = CurrentLat; + +} + +-(void)StartHeartbeatTimer +{ + ObserverClientClass.RestartHeartbeatTimer(); +} + +-(void)StopHeartbeatTimer +{ + ObserverClientClass.HeartbeatTimer->cancel(); +} + +-(void)StartMapHeartbeatTimer +{ + ObserverClientClass.RestartMapHeartbeatTimer(); +} + +-(void)StopMapHeartbeatTimer +{ + ObserverClientClass.MapHeartbeatTimer->cancel(); +} + +-(void)SendMessage:(NSString*)msg +{ + const char* c_msg = [msg UTF8String]; + + ObserverClientClass.SendMessage(c_msg); +} + +-(float)GetBaseLon +{ + return ObserverClientClass.ClientSocket->BaseLon; +} + +-(float)GetBaseLat +{ + return ObserverClientClass.ClientSocket->BaseLat; +} + +-(int)GetBaseZoom +{ + return ObserverClientClass.ClientSocket->BaseZoom; +} + +-(void)SwitchMapToAlarm +{ + ObserverClientClass.SwitchMapToAlarm(); +} + +-(void)SwitchMapToCommon +{ + ObserverClientClass.SwitchMapToCommon(); +} + +-(bool)IsAlarmMap +{ + return ObserverClientClass.IsAlarmMap(); +} + + +@end + + +void AppDelegateSendOnConnectionClosed() +{ + [appDelegate.connectViewController OnConnectionClosed]; + +} + +void AppDelegateSendOnReceiveQuit() +{ + + [appDelegate.connectViewController OnReceiveQuit]; +} + + + + +void AppDelegateAddNewMessage(TUserInfo userInfo, std::string message) +{ + + @autoreleasepool { + NSString* str_msg = [NSString stringWithCString:message.c_str() encoding:NSUTF8StringEncoding]; + + NSString* str_header; + + if (userInfo.MapState != 0) + { + str_header = [NSString stringWithFormat:@"%d %@", userInfo.Uik, str_msg]; + } + else + { + str_header = [NSString stringWithFormat:@"(МГ) %@", str_msg]; + } + + NSString* lastName = [NSString stringWithCString:userInfo.LastName.c_str() encoding:NSUTF8StringEncoding]; + NSString* firstName = [NSString stringWithCString:userInfo.FirstName.c_str() encoding:NSUTF8StringEncoding]; + NSString* middleName = [NSString stringWithCString:userInfo.MiddleName.c_str() encoding:NSUTF8StringEncoding]; + NSString* phoneNumber = [NSString stringWithCString:userInfo.PhoneNumber.c_str() encoding:NSUTF8StringEncoding]; + + NSString* status; + + if (userInfo.MapState == 0) + { + status = @"Мобильная группа"; + } + else + { + status = @"Наблюдатель"; + } + if (userInfo.MapState != 0) + { + str_msg = [NSString stringWithFormat:@"УИК %d, %@ %@ %@ %@ %@: %@", userInfo.Uik, lastName, firstName, middleName, phoneNumber, status, str_msg]; + } + else + { + str_msg = [NSString stringWithFormat:@"(МГ), %@ %@ %@ %@ %@: %@", lastName, firstName, middleName, phoneNumber, status, str_msg]; + } + + [appDelegate.messagesViewController addMessage:str_msg withHeader:str_header]; + + } + +} + + +void AppDelegateOnAutorizationSend() +{ + [appDelegate gotoMainMenu]; + [appDelegate.observerClient ConnectAutorizationFinished]; +} + \ No newline at end of file diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClientCpp.cpp b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClientCpp.cpp new file mode 100644 index 0000000..67771a4 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClientCpp.cpp @@ -0,0 +1,198 @@ +// +// ObserverClientCpp.cpp +// k-observer-iphone +// +// Created by vvv ооо on 06.09.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#include +#include "ObserverClientCpp.h" + +TObserverClient::TObserverClient() + : MapType(0) +{ + +} + +void TObserverClient::DestroyClientSocket() +{ + ClientSocket->CloseImmediate(); +} + + +void TObserverClient::IoServiceRun() +{ + IoService.run(); + + ReceiveCloseSignal(); + ReceiveCloseSignal.disconnect_all_slots(); + +} + +void TObserverClient::CreateClientSocket(const char* address, const char* port) +{ + ClientSocket = boost::shared_ptr(new TClientSocket(IoService)); + + ClientSocket->ReceiveMapSignal.connect(boost::bind(&TObserverClient::OnReceiveMapUpdate, this, _1)); + + ClientSocket->ReceiveAlarmMapSignal.connect(boost::bind(&TObserverClient::OnReceiveAlarmMapUpdate, this, _1)); + + ClientSocket->ReceiveMessageSignal.connect(boost::bind(&TObserverClient::OnReceiveMessage, this, _1, _2)); + + ClientSocket->ReceiveAutorizationSentSignal.connect(boost::bind(&TObserverClient::OnAutorizationSend, this)); + + ReceiveCloseSignal.connect(boost::bind(&TObserverClient::OnCloseSocket, this)); + + ClientSocket->ReceiveForceCloseSignal.connect(boost::bind(&TObserverClient::OnReceiveQuit, this)); + + ClientSocket->Open(std::string(address), std::string(port)); + + IoServiceThread = boost::thread(boost::bind(&TObserverClient::IoServiceRun, this)); +} + + + +void TObserverClient::OnAutorizationSend() +{ + AppDelegateOnAutorizationSend(); +} + + +void TObserverClient::UpdateUserInfo(const char* lastName, + const char* firstName, + const char* middleName, + const char* phoneNumber, + int uik, + int status) +{ + + ClientSocket->UserInfo.LastName = std::string(lastName); + ClientSocket->UserInfo.FirstName = std::string(firstName); + ClientSocket->UserInfo.MiddleName = std::string(middleName); + ClientSocket->UserInfo.PhoneNumber = std::string(phoneNumber); + ClientSocket->UserInfo.Uik = uik; + ClientSocket->UserInfo.Status = status; + + if (status == 1) + { + ClientSocket->UserInfo.MapState = 0; + } + + ClientSocket->SendUserinfoUpdateThreaded(); + +} + + +void TObserverClient::RestartHeartbeatTimer() +{ + HeartbeatTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::milliseconds(500))); + + HeartbeatTimer->async_wait(boost::bind(&TObserverClient::OnHeartbeat, this, boost::asio::placeholders::error)); +} + +void TObserverClient::RestartMapHeartbeatTimer() +{ + MapHeartbeatTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::milliseconds(500))); + + MapHeartbeatTimer->async_wait(boost::bind(&TObserverClient::OnMapHeartbeat, this, boost::asio::placeholders::error)); +} + + +void TObserverClient::OnHeartbeat(const boost::system::error_code& e) +{ + if (e) + { + return; + } + + + ClientSocket->SendHeartbeatThreaded(); + + RestartHeartbeatTimer(); +} + +void TObserverClient::OnMapHeartbeat(const boost::system::error_code& e) +{ + if (e) + { + return; + } + + if (MapType == 0) + { + ClientSocket->SendMapQueryThreaded(); + } + else + { + ClientSocket->SendAlarmMapQueryThreaded(); + } + + RestartMapHeartbeatTimer(); +} + +void TObserverClient::OnReceiveMapUpdate(std::vector userInfoArr) +{ + + UpdatingMapMutex.lock(); + + UserInfoArr = userInfoArr; + + UpdatingMapMutex.unlock(); + +} + + +void TObserverClient::SwitchMapToAlarm() +{ + MapType = 1; +} + +void TObserverClient::SwitchMapToCommon() +{ + MapType = 0; +} + +bool TObserverClient::IsAlarmMap() +{ + return MapType == 1; +} + +void TObserverClient::OnReceiveAlarmMapUpdate(std::vector userInfoArr) +{ + UpdatingMapMutex.lock(); + + AlarmUserInfoArr = userInfoArr; + + UpdatingMapMutex.unlock(); +} + +void TObserverClient::OnReceiveMessage(TUserInfo userInfo, std::string message) +{ + + AppDelegateAddNewMessage(userInfo, message); + +} + +void TObserverClient::SendMessage(const char* msg) +{ + std::string message(msg); + + ClientSocket->SendMessageThreaded(message); +} + +void TObserverClient::OnCloseSocket() +{ + ClientSocket = boost::shared_ptr(); + + IoService.reset(); + + AppDelegateSendOnConnectionClosed(); + +} + +void TObserverClient::OnReceiveQuit() +{ + AppDelegateSendOnReceiveQuit(); + +} \ No newline at end of file diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClientCpp.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClientCpp.h new file mode 100644 index 0000000..cad91d7 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ObserverClientCpp.h @@ -0,0 +1,94 @@ +// +// ObserverClientCpp.h +// k-observer-iphone +// +// Created by vvv ооо on 06.09.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#ifndef OBSERVER_CLIENT_CPP_H_INCLUDED +#define OBSERVER_CLIENT_CPP_H_INCLUDED + +#include "ClientSocket.h" + + + + +void AppDelegateSendOnConnectionClosed(); + +void AppDelegateSendOnReceiveQuit(); + +void AppDelegateAddNewMessage(TUserInfo userInfo, std::string message); + +void AppDelegateOnAutorizationSend(); + + + + +class TObserverClient +{ +public: + boost::asio::io_service IoService; + + boost::thread IoServiceThread; + + boost::mutex UpdatingMapMutex; + + boost::shared_ptr ClientSocket; + + boost::shared_ptr HeartbeatTimer; + boost::shared_ptr MapHeartbeatTimer; + boost::signal ReceiveCloseSignal; + + std::vector UserInfoArr; + std::vector AlarmUserInfoArr; + + int MapType; + + TObserverClient(); + + void DestroyClientSocket(); + void IoServiceRun(); + void CreateClientSocket(const char* address, const char* port); + void OnAutorizationSend(); + void UpdateUserInfo(const char* lastName, + const char* firstName, + const char* middleName, + const char* phoneNumber, + int uik, + int status); + + + void RestartHeartbeatTimer(); + + void RestartMapHeartbeatTimer(); + + void OnCloseSocket(); + + void OnReceiveQuit(); + + void OnHeartbeat(const boost::system::error_code& e); + + void OnMapHeartbeat(const boost::system::error_code& e); + + + void OnReceiveMapUpdate(std::vector userInfoArr); + void OnReceiveAlarmMapUpdate(std::vector userInfoArr); + + void SwitchMapToAlarm(); + + void SwitchMapToCommon(); + + bool IsAlarmMap(); + + void OnReceiveMessage(TUserInfo userInfo, std::string message); + + void SendMessage(const char* msg); + + + + +}; + + +#endif diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.h new file mode 100644 index 0000000..bbd48c5 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.h @@ -0,0 +1,25 @@ +// +// ProfileViewControllerViewController.h +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface ProfileViewController : UIViewController +{ + int Status; +} + +-(void)finishEditing; +- (BOOL)textFieldShouldReturn:(UITextField *)textField; +- (IBAction)OnUpdateProfilePressed; +- (IBAction)OnObserverSelected; +- (IBAction)OnMobileSelected; + +-(void)SwitchAlarmSelector:(BOOL)alarm; +- (IBAction)EditingDidBegin; + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.m new file mode 100644 index 0000000..fbfa346 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.m @@ -0,0 +1,152 @@ +// +// ProfileViewControllerViewController.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "ProfileViewController.h" +#import "AppDelegate.h" + +extern AppDelegate* appDelegate; + + +@interface ProfileViewController () + +@end + +@implementation ProfileViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + + Status = 0; + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. + + + UIScrollView *tempScrollView=(UIScrollView *)self.view; + + tempScrollView.contentSize=CGSizeMake(320, 780); +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +-(void)finishEditing +{ + [self.view endEditing:YES]; + self.navigationItem.rightBarButtonItem = nil; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + [self finishEditing]; + return YES; +} + +- (IBAction)OnUpdateProfilePressed +{ + NSString* lastName = ((UITextField*)[self.view viewWithTag:1]).text; + NSString* firstName = ((UITextField*)[self.view viewWithTag:2]).text; + NSString* middleName = ((UITextField*)[self.view viewWithTag:3]).text; + NSString* phoneNumber = ((UITextField*)[self.view viewWithTag:4]).text; + + NSString* uikNumberStr = ((UITextField*)[self.view viewWithTag:5]).text; + + int uikNumber = [uikNumberStr intValue]; + + UISegmentedControl* alarlModeControl = (UISegmentedControl*)[self.view viewWithTag:8]; + + int status = self->Status; + + if (status == 0) + { + if ([alarlModeControl selectedSegmentIndex]) + { + int mapState = [appDelegate.observerClient GetMapState]; + + if (mapState < 2) + { + [appDelegate.observerClient SetMapState:2]; + } + } + else + { + [appDelegate.observerClient SetMapState:1]; + } + } + + [appDelegate.observerClient UpdateProfileWithLastName:lastName + FirstName:firstName MiddleName:middleName PhoneNumber:phoneNumber UikNumber:uikNumber Status:status]; + +} + +- (IBAction)OnObserverSelected +{ + self->Status = 0; + + UILabel* observer_label = (UILabel*)[self.view viewWithTag:6]; + UILabel* mobile_label = (UILabel*)[self.view viewWithTag:7]; + + observer_label.text = @"X"; + mobile_label.text = @""; +} + +- (IBAction)OnMobileSelected +{ + self->Status = 1; + + UILabel* observer_label = (UILabel*)[self.view viewWithTag:6]; + UILabel* mobile_label = (UILabel*)[self.view viewWithTag:7]; + + observer_label.text = @""; + mobile_label.text = @"X"; +} + + +-(void)SwitchAlarmSelector:(BOOL)alarm +{ + UISegmentedControl* alarmModeControl = (UISegmentedControl*)[self.view viewWithTag:8]; + + if (alarm) + { + [alarmModeControl setSelectedSegmentIndex:1]; + + } + else + { + [alarmModeControl setSelectedSegmentIndex:0]; + } + + +} + +- (IBAction)EditingDidBegin +{ + UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Готово" style:UIBarButtonItemStylePlain target:self action:@selector(finishEditing)]; + + + self.navigationItem.rightBarButtonItem = anotherButton; +} + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.xib b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.xib new file mode 100644 index 0000000..6e70384 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/ProfileViewController.xib @@ -0,0 +1,863 @@ + + + + 1296 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1181 + + + IBUILabel + IBUIButton + IBUISegmentedControl + IBUIView + IBUITextField + IBProxyObject + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 292 + + + + 292 + {{23, 280}, {273, 31}} + + + _NS:9 + NO + YES + 3 + IBCocoaTouchFramework + 0 + Anonymous + 3 + + 3 + MAA + + 2 + + + YES + 17 + + 9 + IBCocoaTouchFramework + + + 1 + 14 + + + Helvetica + 14 + 16 + + + + + 292 + {{16, 20}, {280, 80}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Указанная вами информация будет видна всем и поможет мобильной группе своевременно оказать вам помощь + + 1 + MCAwIDAAA + + + 0 + 10 + 4 + 1 + + 1 + 15 + + + Helvetica + 15 + 16 + + + + + 292 + {{24, 105}, {78, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Фамилия: + + + 0 + 10 + + 1 + 17 + + + Helvetica + 17 + 16 + + + + + 292 + {{20, 134}, {273, 31}} + + + _NS:9 + NO + YES + 1 + IBCocoaTouchFramework + 0 + Anonymous + 3 + + 3 + MAA + + + YES + 17 + + 9 + IBCocoaTouchFramework + + + + + + + 292 + {{27, 173}, {78, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Имя: + + + 0 + 10 + + + + + + 292 + {{24, 202}, {273, 31}} + + + _NS:9 + NO + YES + 2 + IBCocoaTouchFramework + 0 + Anonymous + 3 + + 3 + MAA + + + YES + 17 + + 9 + IBCocoaTouchFramework + + + + + + + 292 + {{24, 251}, {81, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Отчество: + + + 0 + 10 + + + + + + 292 + {{23, 329}, {178, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Контактный телефон: + + + 0 + 10 + + + + + + 292 + {{22, 354}, {273, 31}} + + + _NS:9 + NO + YES + 4 + IBCocoaTouchFramework + 0 + + 3 + + 3 + MAA + + + YES + 17 + + 6 + 9 + IBCocoaTouchFramework + + + + + + + 292 + {{23, 404}, {178, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Номер УИК: + + + 0 + 10 + + + + + + 292 + {{22, 429}, {273, 31}} + + + _NS:9 + NO + YES + 5 + IBCocoaTouchFramework + 0 + 0 + 3 + + 3 + MAA + + + YES + 17 + + 4 + 9 + IBCocoaTouchFramework + + + + + + + 292 + {{36, 520}, {240, 36}} + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Вы наблюдатель + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + NSImage + button.png + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + + + + 292 + {{36, 575}, {240, 36}} + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Вы мобильная группа + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + + + + + + + 292 + {{48, 491}, {128, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Выберите роль: + + + 0 + 10 + + + + + + 292 + {{284, 582}, {42, 21}} + + + _NS:9 + NO + YES + 7 + 7 + NO + IBCocoaTouchFramework + + + + 0 + 10 + + + + + + 292 + {{284, 527}, {42, 21}} + + + _NS:9 + NO + YES + 7 + 6 + NO + IBCocoaTouchFramework + X + + + 0 + 10 + + + + + + 292 + {{40, 715}, {240, 36}} + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Обновить + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + + + + + + + 292 + {{44, 649}, {233, 44}} + + + _NS:9 + NO + 8 + IBCocoaTouchFramework + 2 + 0 + + Выключен + Включен + + + + + + + + + + + {0, 0} + {0, 0} + + + + + + + + + 292 + {{53, 620}, {128, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Режим тревоги: + + + 0 + 10 + + + + + {320, 771} + + + _NS:9 + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + IBCocoaTouchFramework + + + + + + + view + + + + 48 + + + + delegate + + + + 53 + + + + EditingDidBegin + + + 17 + + 68 + + + + delegate + + + + 51 + + + + EditingDidBegin + + + 17 + + 66 + + + + delegate + + + + 52 + + + + EditingDidBegin + + + 17 + + 67 + + + + delegate + + + + 54 + + + + EditingDidBegin + + + 17 + + 65 + + + + delegate + + + + 49 + + + + OnObserverSelected + + + 7 + + 57 + + + + OnMobileSelected + + + 7 + + 58 + + + + OnUpdateProfilePressed + + + 7 + + 56 + + + + delegate + + + + 61 + + + + EditingDidBegin + + + 17 + + 69 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 21 + + + + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 14 + + + + + 15 + + + + + 39 + + + + + 40 + + + + + 41 + + + + + 42 + + + + + 43 + + + + + 55 + + + + + 59 + + + + + 60 + + + + + 63 + + + + + 64 + + + + + + + ProfileViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIScrollView + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 69 + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + + button.png + {480, 72} + + 1181 + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.h b/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.h new file mode 100644 index 0000000..cee58b2 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.h @@ -0,0 +1,13 @@ +// +// SendMessageViewController.h +// k-observer-iphone +// +// Created by vvv ооо on 31.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface SendMessageViewController : UIViewController + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.m new file mode 100644 index 0000000..07ff5bd --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.m @@ -0,0 +1,79 @@ +// +// SendMessageViewController.m +// k-observer-iphone +// +// Created by vvv ооо on 31.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "SendMessageViewController.h" +#import "AppDelegate.h" + + +extern AppDelegate* appDelegate; + +@interface SendMessageViewController () + +@end + +@implementation SendMessageViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +-(void)viewDidAppear:(BOOL)animated +{ + UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Отправить" style:UIBarButtonItemStylePlain target:self action:@selector(SendMessage)]; + + + self.navigationItem.rightBarButtonItem = anotherButton; +} + +-(void)viewDidDisappear:(BOOL)animated +{ + + self.navigationItem.rightBarButtonItem = nil; +} + +-(void)SendMessage +{ + + self.navigationItem.rightBarButtonItem = nil; + [appDelegate.navController popViewControllerAnimated:true]; + + NSString* ns_msg = ((UITextView*)[self.view viewWithTag:1]).text; + + if (![ns_msg isEqualToString:@""]) + { + + [appDelegate.observerClient SendMessage:ns_msg]; + + [((UITextView*)[self.view viewWithTag:1]) setText:@""]; + } +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +@end diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.xib b/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.xib new file mode 100644 index 0000000..1b04cc1 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/SendMessageViewController.xib @@ -0,0 +1,214 @@ + + + + 1296 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1181 + + + IBUITextView + IBUIImageView + IBUIView + IBUILabel + IBProxyObject + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 292 + {{0, 40}, {320, 186}} + + + _NS:9 + NO + IBCocoaTouchFramework + + NSImage + messages_text.png + + + + + 274 + {{0, 40}, {320, 186}} + + + _NS:9 + + 1 + MC44Njk1NjUyMTc0IDAuODY5NTY1MjE3NCAwLjg2OTU2NTIxNzQgMAA + + YES + YES + 1 + IBCocoaTouchFramework + + + 2 + IBCocoaTouchFramework + + + 1 + 14 + + + Helvetica + 14 + 16 + + + + + 292 + {{20, 12}, {280, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Введите сообщение для отправки: + + 1 + MCAwIDAAA + + + 0 + 10 + + 1 + 17 + + + Helvetica + 17 + 16 + + + + {{0, 20}, {320, 460}} + + + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + + IBCocoaTouchFramework + + + + + + + view + + + + 3 + + + + + + 0 + + + + + + 1 + + + + + + + + + + -1 + + + File's Owner + + + -2 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + + + SendMessageViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 6 + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + + messages_text.png + {640, 372} + + 1181 + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/en.lproj/ConnectViewController.xib b/k_observer_iphone/k-observer-iphone/k-observer-iphone/en.lproj/ConnectViewController.xib new file mode 100644 index 0000000..26666c2 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/en.lproj/ConnectViewController.xib @@ -0,0 +1,369 @@ + + + + 0 + 11E53 + 2182 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1181 + + + IBUITextField + IBUIButton + IBUIView + IBUILabel + IBProxyObject + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 292 + {{20, 123}, {207, 31}} + + + _NS:9 + NO + YES + 1 + IBCocoaTouchFramework + 0 + k-observer.org + 3 + + 3 + MAA + + 2 + + + YES + 17 + + 3 + IBCocoaTouchFramework + + + 1 + 14 + + + Helvetica + 14 + 16 + + + + + 292 + {{231, 123}, {69, 31}} + + + _NS:9 + NO + YES + 2 + IBCocoaTouchFramework + 0 + 1984 + 3 + + 3 + MAA + + + YES + 17 + + IBCocoaTouchFramework + + + + + + + 292 + {{27, 94}, {55, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Адрес: + + 1 + MCAwIDAAA + + + 0 + 10 + + 1 + 17 + + + Helvetica + 17 + 16 + + + + + 292 + {{231, 94}, {55, 21}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Порт: + + + 0 + 10 + + + + + + 292 + {{40, 184}, {240, 36}} + + + _NS:9 + NO + 3 + IBCocoaTouchFramework + 0 + 0 + 1 + Подключиться + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + NSImage + button.png + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + + + + 292 + {{36, 30}, {248, 56}} + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Введите адрес и порт сервера для подключения: + + + 0 + 10 + 2 + 1 + + + + + {{0, 20}, {320, 416}} + + + + 1 + MC44NDUzMDkwODU0IDAuOTI2MjM3MDMwNCAxAA + + NO + + IBCocoaTouchFramework + + + + + + + view + + + + 51 + + + + delegate + + + + 53 + + + + delegate + + + + 54 + + + + OnConnectPressed + + + 7 + + 52 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 44 + + + + + + + + + + + + + 49 + + + + + 48 + + + + + 47 + + + + + 46 + + + + + 45 + + + + + 58 + + + + + + + ConnectViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 58 + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + + button.png + {480, 72} + + 1181 + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/en.lproj/InfoPlist.strings b/k_observer_iphone/k-observer-iphone/k-observer-iphone/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..0f167df --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon-72.png b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon-72.png new file mode 100644 index 0000000..b101819 Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon-72.png differ diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon-72@2x.png b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon-72@2x.png new file mode 100644 index 0000000..d1a5534 Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon-72@2x.png differ diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon.png b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon.png new file mode 100644 index 0000000..be42d93 Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon.png differ diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon@2x.png b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon@2x.png new file mode 100644 index 0000000..bb26eb0 Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Icon@2x.png differ diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Splash-portrait.png b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Splash-portrait.png new file mode 100644 index 0000000..f473cae Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/Splash-portrait.png differ diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/iTunesArtwork b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/iTunesArtwork new file mode 100644 index 0000000..48b3eaf Binary files /dev/null and b/k_observer_iphone/k-observer-iphone/k-observer-iphone/icons/iTunesArtwork differ diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/k-observer-iphone-Info.plist b/k_observer_iphone/k-observer-iphone/k-observer-iphone/k-observer-iphone-Info.plist new file mode 100644 index 0000000..57c3dbe --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/k-observer-iphone-Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + ru + CFBundleDisplayName + К-Выборы + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFiles + + Icon.png + Icon@2x.png + Icon-72.png + Icon-72@2x.png + + CFBundleIdentifier + fishrungames.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UILaunchImageFile + Splash-portrait.png + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/k-observer-iphone-Prefix.pch b/k_observer_iphone/k-observer-iphone/k-observer-iphone/k-observer-iphone-Prefix.pch new file mode 100644 index 0000000..da3cc63 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/k-observer-iphone-Prefix.pch @@ -0,0 +1,14 @@ +// +// Prefix header for all source files of the 'k-observer-iphone' target in the 'k-observer-iphone' project +// + +#import + +#ifndef __IPHONE_4_0 +#warning "This project uses features only available in iOS SDK 4.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/k_observer_iphone/k-observer-iphone/k-observer-iphone/main.m b/k_observer_iphone/k-observer-iphone/k-observer-iphone/main.m new file mode 100644 index 0000000..35110e1 --- /dev/null +++ b/k_observer_iphone/k-observer-iphone/k-observer-iphone/main.m @@ -0,0 +1,18 @@ +// +// main.m +// k-observer-iphone +// +// Created by vvv ооо on 26.08.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +#import "AppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/k_observer_srv/Debug/k_observer_srv.exe b/k_observer_srv/Debug/k_observer_srv.exe new file mode 100644 index 0000000..5e13998 Binary files /dev/null and b/k_observer_srv/Debug/k_observer_srv.exe differ diff --git a/k_observer_srv/k_observer_srv.sln b/k_observer_srv/k_observer_srv.sln new file mode 100644 index 0000000..8ab9e3c --- /dev/null +++ b/k_observer_srv/k_observer_srv.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C++ Express 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "k_observer_srv", "k_observer_srv\k_observer_srv.vcxproj", "{086DBA7B-9D25-47EF-8371-0E4CE295FD3F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {086DBA7B-9D25-47EF-8371-0E4CE295FD3F}.Debug|Win32.ActiveCfg = Debug|Win32 + {086DBA7B-9D25-47EF-8371-0E4CE295FD3F}.Debug|Win32.Build.0 = Debug|Win32 + {086DBA7B-9D25-47EF-8371-0E4CE295FD3F}.Release|Win32.ActiveCfg = Release|Win32 + {086DBA7B-9D25-47EF-8371-0E4CE295FD3F}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/k_observer_srv/k_observer_srv/k_observer_srv.vcxproj b/k_observer_srv/k_observer_srv/k_observer_srv.vcxproj new file mode 100644 index 0000000..e7fc0bf --- /dev/null +++ b/k_observer_srv/k_observer_srv/k_observer_srv.vcxproj @@ -0,0 +1,85 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {086DBA7B-9D25-47EF-8371-0E4CE295FD3F} + k_observer_srv + + + + Application + true + NotSet + + + Application + false + true + NotSet + + + + + + + + + + + + + + + Level3 + Disabled + $(LibsPath)\boost_1_47_0;../../common + _WIN32_WINNT=0x0501 + + + true + $(LibsPath)\boost_1_47_0\boost_windows\libs_engine\debug + + + + + Level3 + MaxSpeed + true + true + $(LibsPath)\boost_1_47_0;../../common + _WIN32_WINNT=0x0501 + + + true + true + true + $(LibsPath)\boost_1_47_0\boost_windows\libs_engine\release + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/k_observer_srv/k_observer_srv/main.cpp b/k_observer_srv/k_observer_srv/main.cpp new file mode 100644 index 0000000..248658a --- /dev/null +++ b/k_observer_srv/k_observer_srv/main.cpp @@ -0,0 +1,315 @@ +#include "main.h" + + + +size_t TUser::NextId = 0; + + +//HIMKI +float BaseLon = 37.443195f; +float BaseLat = 55.888869f; +int BaseZoom = 12; + +/* +//SPB +float BaseLon = 30.2158f; +float BaseLat = 60.0052f; +int BaseZoom = 12; + +*/ + +TUser::TUser(TServer& server) + : Id(NextId++) + , Server(server) + , Socket(server.Service) +{ + +} + +void TUser::Delete() +{ + std::vector >::iterator i = std::find(Server.UserArr.begin(), Server.UserArr.end(), shared_from_this()); + + Server.UserArr.erase(i); +} + +void TUser::HandleReadUserLoginResponce(const boost::system::error_code& error) +{ + if (!error) + { + + if (check_func(LoginQuestion) == LoginQuestionResult) + { + //Autorization ok + + boost::asio::async_write(Socket, boost::asio::buffer(&CONST_OK[0], 2), boost::bind(&TUser::HandleCheckError, shared_from_this(), boost::asio::placeholders::error)); + + boost::asio::async_write(Socket, boost::asio::buffer(&CONST_OK[0], 2), boost::bind(&TUser::HandleCheckError, shared_from_this(), boost::asio::placeholders::error)); + boost::asio::async_write(Socket, boost::asio::buffer(&BaseLon, 4), boost::bind(&TUser::HandleCheckError, shared_from_this(), boost::asio::placeholders::error)); + boost::asio::async_write(Socket, boost::asio::buffer(&BaseLat, 4), boost::bind(&TUser::HandleCheckError, shared_from_this(), boost::asio::placeholders::error)); + boost::asio::async_write(Socket, boost::asio::buffer(&BaseZoom, 4), boost::bind(&TUser::HandleCheckError, shared_from_this(), boost::asio::placeholders::error)); + + + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TUser::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + + } + else + { + //Force close + + Socket.close(); + Delete(); + } + + } + else + { + Delete(); + } +} + +void TUser::HandleCheckError(const boost::system::error_code& error) +{ + if (error) + { + Delete(); + } +} + +void TUser::HandleReadSignal(const boost::system::error_code& error) +{ + if (!error) + { + if (LastSignal == 3 || LastSignal == 4 || LastSignal == 5) + { + boost::asio::async_read(Socket, boost::asio::buffer(&ReadDataLenLong, 4), boost::bind(&TUser::HandleReadDataLen, shared_from_this(), boost::asio::placeholders::error)); + } + if (LastSignal == 1) + { + std::vector mapData = Server.CreateMapData(); + + boost::shared_ptr(new TMessageSender(Socket, 1, mapData))->Send(); + + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TUser::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + } + if (LastSignal == 2) + { + std::vector mapData = Server.CreateAlarmMapData(); + + boost::shared_ptr(new TMessageSender(Socket, 2, mapData))->Send(); + + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TUser::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + + } + if (LastSignal == 100) + { + boost::asio::async_read(Socket, boost::asio::buffer(&ReadDataLenLong, 4), boost::bind(&TUser::HandleReadDataLen, shared_from_this(), boost::asio::placeholders::error)); + } + } + else + { + Delete(); + } +} + +void TUser::HandleReadDataLen(const boost::system::error_code& error) +{ + if (!error) + { + ReadData.resize(ReadDataLenLong); + if (ReadDataLenLong == 0) + { + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TUser::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + } + else + { + boost::asio::async_read(Socket, boost::asio::buffer(ReadData), boost::bind(&TUser::HandleReadData, shared_from_this(), boost::asio::placeholders::error)); + } + } + else + { + Delete(); + } +} + +void TUser::HandleReadData(const boost::system::error_code& error) +{ + if (!error) + { + if (LastSignal == 4) + { + std::string msg; + DecodeMessage(ReadData, UserInfo, msg); + Server.BroadcastMessage(CONST_SIGNAL_MESSAGE, ReadData); + } + if (LastSignal == 3) + { + DecodeProfileUpdateQuery(ReadData, UserInfo); + } + if (LastSignal == 5) + { + DecodeHeartBeatQuery(ReadData, UserInfo); + } + if (LastSignal == 100) + { + std::string lastName; + std::string firstName; + std::string middleName; + DecodeKickPlayerSignal(ReadData, lastName, firstName, middleName); + + if (IsAdmin()) + { + if (lastName != "" || firstName != "" || middleName != "") + { + int playerToDelete = -1; + for (int i=0; iUserInfo.LastName == lastName) && + (firstName == "" || Server.UserArr[i]->UserInfo.FirstName == firstName) && + (middleName == "" || Server.UserArr[i]->UserInfo.MiddleName == middleName)) + { + playerToDelete = i; + + + } + } + + if (playerToDelete != -1) + { + //Server.UserArr[playerToDelete]->ForceClose(); + + //If kick himself + if (Server.UserArr[playerToDelete] == shared_from_this()) + { + Server.UserArr.erase(Server.UserArr.begin()+playerToDelete); + return; + } + else + { + Server.UserArr.erase(Server.UserArr.begin()+playerToDelete); + } + } + } + } + + } + boost::asio::async_read(Socket, boost::asio::buffer(&LastSignal, 4), boost::bind(&TUser::HandleReadSignal, shared_from_this(), boost::asio::placeholders::error)); + } + else + { + Delete(); + } +} + + +bool TUser::IsAdmin() +{ + //Call-Center + if (UserInfo.LastName.size() <= 11) + { + return false; + } + + std::string lastName_part1 = std::string(UserInfo.LastName.begin(), UserInfo.LastName.begin()+11); + + std::string lastName_part2 = std::string(UserInfo.LastName.begin()+11, UserInfo.LastName.end()); + + if (lastName_part1 == "Call-Center") + { + if (lastName_part2 == UserInfo.FirstName) + { + return true; + } + } + + return false; +} + +void TUser::ForceClose() +{ + Socket.close(); + Delete(); +} + +void TServer::StartAccept() +{ + boost::shared_ptr newUser(new TUser(*this)); + + Acceptor.async_accept(newUser->Socket, boost::bind(&TServer::HandleAccept, this, newUser, boost::asio::placeholders::error)); +} + + +void TServer::HandleAccept(boost::shared_ptr user, const boost::system::error_code& error) +{ + if (!error) + { + UserArr.push_back(user); + + user->LoginQuestion = rand(); + + boost::asio::async_write(user->Socket, boost::asio::buffer(&(user->LoginQuestion), 4), boost::bind(&TUser::HandleCheckError, user, boost::asio::placeholders::error)); + + boost::asio::async_read(user->Socket, boost::asio::buffer(&(user->LoginQuestionResult), 4), boost::bind(&TUser::HandleReadUserLoginResponce, user, boost::asio::placeholders::error)); + + } + + StartAccept(); +} + +void TServer::BroadcastMessage(int messageType, std::vector messageData) +{ + for (std::vector >::iterator i = UserArr.begin(); i != UserArr.end(); ++i) + { + boost::shared_ptr(new TMessageSender((*i)->Socket, messageType, messageData))->Send(); + } +} + +std::vector TServer::CreateMapData() +{ + std::vector result; + + for (std::vector >::iterator i = UserArr.begin(); i != UserArr.end(); ++i) + { + std::vector beatQuery(CreateHeartBeatQuery((*i)->UserInfo)); + result.insert(result.end(), beatQuery.begin(), beatQuery.end()); + } + + return result; +} + +std::vector TServer::CreateAlarmMapData() +{ + std::vector result; + + for (std::vector >::iterator i = UserArr.begin(); i != UserArr.end(); ++i) + { + //if ((*i)->UserInfo.MapState >= CONST_MAP_STATE_ALARM) + { + std::vector beatQuery(CreateProfileUpdateQuery((*i)->UserInfo)); + result.insert(result.end(), beatQuery.begin(), beatQuery.end()); + } + } + + return result; +} + +int main() +{ + srand(static_cast(time(0))); + + std::cout<<"K-observer server started"< Server(new TServer(io_service, endpoint)); + + io_service.run(); + + return 0; +} \ No newline at end of file diff --git a/k_observer_srv/k_observer_srv/main.h b/k_observer_srv/k_observer_srv/main.h new file mode 100644 index 0000000..f4f8ab0 --- /dev/null +++ b/k_observer_srv/k_observer_srv/main.h @@ -0,0 +1,73 @@ +#include + +#include "UserInfo.h" +#include "MessageSender.h" +#include "misc.h" + +#include "linux_stuff.h" + +struct TServer; + +struct TUser + : public boost::enable_shared_from_this +{ + static size_t NextId; + + size_t Id; + + TServer& Server; + + TUserInfo UserInfo; + boost::asio::ip::tcp::socket Socket; + + int LoginQuestion; + int LoginQuestionResult; + + + int ReadDataLenLong; + std::vector ReadData; + int LastSignal; + + TUser(TServer& server); + void Delete(); + + void HandleReadUserLoginResponce(const boost::system::error_code& error); + + void HandleReadSignal(const boost::system::error_code& error); + + //ReadFullInfo + void HandleReadDataLen(const boost::system::error_code& error); + void HandleReadData(const boost::system::error_code& error); + + void HandleCheckError(const boost::system::error_code& error); + + bool IsAdmin(); + + void ForceClose(); + +}; + + + + +struct TServer +{ + TServer(boost::asio::io_service& service, const boost::asio::ip::tcp::endpoint& endpoint) + : Service(service) + , Acceptor(service, endpoint) + { + StartAccept(); + } + + void StartAccept(); + void HandleAccept(boost::shared_ptr user, const boost::system::error_code& error); + + void BroadcastMessage(int messageType, std::vector messageData); + + std::vector CreateMapData(); + std::vector CreateAlarmMapData(); + + boost::asio::io_service& Service; + boost::asio::ip::tcp::acceptor Acceptor; + std::vector > UserArr; +}; \ No newline at end of file diff --git a/k_observer_srv/linux/makefile b/k_observer_srv/linux/makefile new file mode 100644 index 0000000..d7da7db --- /dev/null +++ b/k_observer_srv/linux/makefile @@ -0,0 +1,54 @@ +CC=g++ +CFLAGS=-Wall -O3 -I../../../boost_1_47_0 +LDFLAGS= -lpthread + +#thread +LOCAL_SRC_FILES := ../../../boost_1_47_0/libs/thread/src/pthread/thread.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/thread/src/pthread/once.cpp + +#signals +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/connection.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/named_slot_map.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/signal_base.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/slot.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/signals/src/trackable.cpp + +#system +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/system/src/error_code.cpp + +#regex +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/c_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/cpp_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/cregex.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/fileiter.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/icu.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/instances.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/posix_api.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex_debug.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex_raw_buffer.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/regex_traits_defaults.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/static_mutex.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/usinstances.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/w32_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/wc_regex_traits.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/wide_posix_api.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/regex/src/winstances.cpp + +#date_time +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/date_time/src/gregorian/greg_month.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/date_time/src/gregorian/greg_weekday.cpp +LOCAL_SRC_FILES += ../../../boost_1_47_0/libs/date_time/src/gregorian/date_generators.cpp + + +CFLAGS += -I../../common +CFLAGS += -I../k_observer_srv +LOCAL_SRC_FILES += ../k_observer_srv/main.cpp +LOCAL_SRC_FILES += ../../common/ClientSocket.cpp +LOCAL_SRC_FILES += ../../common/MessageSender.cpp +LOCAL_SRC_FILES += ../../common/misc.cpp +LOCAL_SRC_FILES += ../../common/UserInfo.cpp +LOCAL_SRC_FILES += ../../common/linux_stuff.cpp + +all: + $(CC) $(LOCAL_SRC_FILES) $(CFLAGS) $(LDFLAGS) -o k_observer_srv \ No newline at end of file