/** Animation Log Server 1.0 anm_log_server.c v1.0 by Fumi.Iseki (C)2012 */ #include "network.h" #include "matrix.h" #include "anm_server.h" #include "anm_log_server.h" #include "anm_data.h" #define NI_SHM_JOINT_NUM 34 #define NI_JTXT_FILE_ID "NI_JOINTS_TEXT_FILE" Buffer NiJointName[NI_SHM_JOINT_NUM]; tList* File_List = NULL; void anm_log_server(int usock, char* gname) { int datasz; udp_header* dat = NULL; struct sockaddr_in rcv_addr; struct sigaction sa; vector posVect[NI_SHM_JOINT_NUM]; quaternion rotQuat[NI_SHM_JOINT_NUM]; double jntAngl[NI_SHM_JOINT_NUM]; int rcvData[NI_SHM_JOINT_NUM]; // DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Log Server start.\n", CrntPID); // シグナルハンドリング sa.sa_handler = anm_log_server_term; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask, SIGCHLD); sigaction(SIGINT, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGTERM, &sa, NULL); DEBUG_MODE set_sigseg_handler(NULL); // Segmentation Falt check File_List = add_tList_node_bystr(NULL, 0, 0, TLIST_ANCHOR, NULL, NULL, 0); Buffer path = make_Buffer(LNAME); // full path of log file Buffer srch = make_Buffer(LNAME); // search name Buffer name = make_Buffer(LNAME); // user name Buffer clip = make_Buffer(LEN_IPADDR); // IP address of Client (Viewer) Buffer buf = make_Buffer(LFRAME); Buffer ldir = make_Buffer_bystr(Data_Log_Dir); // directory of log file // cat_s2Buffer("/", &ldir); cat_s2Buffer(gname, &ldir); cat_s2Buffer("/", &ldir); mkdir((const char*)ldir.buf, 0750); init_joint_name(); // Loop { FILE* fp = NULL; int errflag = FALSE; //////////////////////////////////////////////////////////////////////////////////////////////////////// // Data受信 if (recv_wait(usock, ANM_UDP_TIMEOUT)) { int cc = udp_recv_Buffer_sockaddr_in(usock, &buf, &rcv_addr); if (cc<(int)sizeof(udp_header)) { DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Received Data size = [%d]\n", CrntPID, cc); continue; } dat = (udp_header*)buf.buf; char* ipaddr = get_ipaddr_ipv4(rcv_addr.sin_addr); datasz = 4; // sizeof(float) //DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Received Data from [%s] key = %s\n", CrntPID, ipaddr, dat->key); // if (strcmp(ipaddr, LOCAL_IPADDR)) { DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: WARNING: udp data from unknown node!! [%s]\n", CrntPID, ipaddr); freeNull(ipaddr); continue; } freeNull(ipaddr); } else continue; // //////////////////////////////////////////////////////////////////////////////////////////////////////// // コマンド処理 if (dat->com[0]==ANM_COM_REQ_LOG || dat->com[0]==ANM_COM_REQ_TRANSFER_LOG) { //DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Recieved LOG Data\n", CrntPID); //DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Recieved LOG Data %s %s\n", CrntPID, Data_Log_Dir, dat->key); int len = sizeof(udp_header); char* ptr = (char*)dat + len; unsigned short* mode = NULL; // get name and IP address while (lenldat.ptr; } if (fp==NULL) continue; // len = sizeof(udp_header); ptr = (char*)dat + len; unsigned long int laptime; // memset(posVect, 0, NI_SHM_JOINT_NUM*sizeof(vector)); memset(rotQuat, 0, NI_SHM_JOINT_NUM*sizeof(quaternion)); memset(jntAngl, 0, NI_SHM_JOINT_NUM*sizeof(double)); memset(rcvData, 0, NI_SHM_JOINT_NUM*sizeof(int)); // while (lencom[0]==ANM_COM_REQ_LOG_START) { DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Recieved LOG START\n", CrntPID); int len = sizeof(udp_header); char* ptr = (char*)dat + len; unsigned short* mode = NULL; // while (lenldat.id++; // DEBUG_MODE { fprintf(stderr, "++++++++++++++++++++++++++++++++++++++++++++++\n"); print_tList(stderr, File_List); fprintf(stderr, "++++++++++++++++++++++++++++++++++++++++++++++\n"); } // fprintf(fp, "%s\n", NI_JTXT_FILE_ID); fprintf(fp, "%s, %s\n", name.buf, clip.buf); } // else if (dat->com[0]==ANM_COM_REQ_LOG_STOP) { DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Recieved LOG STOP\n", CrntPID); int len = sizeof(udp_header); char* ptr = (char*)dat + len; unsigned short* mode = (unsigned short*)ptr; // while (lenldat.ptr; if (fp!=NULL) fclose(fp); del_tList_node(&user); File_List->ldat.id--; // DEBUG_MODE { fprintf(stderr, "++++++++++++++++++++++++++++++++++++++++++++++\n"); print_tList(stderr, File_List); fprintf(stderr, "++++++++++++++++++++++++++++++++++++++++++++++\n"); } } else { } } // else { DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: Recieved Unknown Data (%02x)\n", CrntPID, dat->com[0]); } } ///////////////////////////////////////////////////////////////////////// // if (File_List!=NULL) del_all_tList(&File_List); DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER: down!!\n", CrntPID); return; } ////////////////////////////////////////////////////////////////////////////////////////////////////////// // Termination of Program // void anm_log_server_term(int signal) { DEBUG_MODE print_message("[%5d] ANM_LOG_SERVER_TERM: going down!!\n", CrntPID); if (File_List!=NULL) del_all_tList(&File_List); clear_joint_name(); exit(signal); } ////////////////////////////////////////////////////////////////////////////////////////////////////////// // Joint Name // /* 共有メモリ名 mPelvis(0), mTorso(1), mChest(2), mNeck(3), mHead(4), mSkull(5), mEyeLeft(6), mEyeRight(7), mBustLeft(8), mBustRight(9), mCollarLeft (10), mShoulderLeft (11), mElbowLeft (12), mWristLeft (13), mFingertipLeft (14), mCollarRight(15), mShoulderRight(16), mElbowRight(17), mWristRight(18), mFingertipRight(19), mHipLeft (20), mKneeLeft (21), mAnkleLeft (22), mFootLeft (23), mToeLeft (24), mHipRight(25), mKneeRight(26), mAnkleRight(27), mFootRight(28), mToeRight(29), L_Hand(30), R_Hand(31), Expression(32), Avatar(33) */ void init_joint_name(void) { NiJointName[ 0] = make_Buffer_bystr("PELVIS"); NiJointName[ 1] = make_Buffer_bystr("TORSO"); NiJointName[ 2] = make_Buffer_bystr("CHEST"); NiJointName[ 3] = make_Buffer_bystr("NECK"); NiJointName[ 4] = make_Buffer_bystr("HEAD"); NiJointName[ 5] = make_Buffer_bystr("SKULL"); NiJointName[ 6] = make_Buffer_bystr("L_EYE"); NiJointName[ 7] = make_Buffer_bystr("R_EYE"); NiJointName[ 8] = make_Buffer_bystr("L_BUST"); NiJointName[ 9] = make_Buffer_bystr("R_BUST"); NiJointName[10] = make_Buffer_bystr("L_COLLAR"); NiJointName[11] = make_Buffer_bystr("L_SHLDR"); NiJointName[12] = make_Buffer_bystr("L_ELBOW"); NiJointName[13] = make_Buffer_bystr("L_WRIST"); NiJointName[14] = make_Buffer_bystr("L_FNGRTIP"); NiJointName[15] = make_Buffer_bystr("R_COLLAR"); NiJointName[16] = make_Buffer_bystr("R_SHLDR"); NiJointName[17] = make_Buffer_bystr("R_ELBOW"); NiJointName[18] = make_Buffer_bystr("R_WRIST"); NiJointName[19] = make_Buffer_bystr("R_FNGRTIP"); NiJointName[20] = make_Buffer_bystr("L_HIP"); NiJointName[21] = make_Buffer_bystr("L_KNEE"); NiJointName[22] = make_Buffer_bystr("L_ANKLE"); NiJointName[23] = make_Buffer_bystr("L_FOOT"); NiJointName[24] = make_Buffer_bystr("L_TOE"); NiJointName[25] = make_Buffer_bystr("R_HIP"); NiJointName[26] = make_Buffer_bystr("R_KNEE"); NiJointName[27] = make_Buffer_bystr("R_ANKLE"); NiJointName[28] = make_Buffer_bystr("R_FOOT"); NiJointName[29] = make_Buffer_bystr("R_TOE"); NiJointName[30] = make_Buffer_bystr("L_HAND"); NiJointName[31] = make_Buffer_bystr("R_HAND"); NiJointName[32] = make_Buffer_bystr("FACE"); NiJointName[33] = make_Buffer_bystr("AVATAR"); } void clear_joint_name(void) { int j; for (j=0; j